Skip to content

Commit 116dbce

Browse files
benpeartdscho
authored andcommitted
gvfs: block unsupported commands when running in a GVFS repo
The following commands and options are not currently supported when working in a GVFS repo. Add code to detect and block these commands from executing. 1) fsck 2) gc 4) prune 5) repack 6) submodule 8) update-index --split-index 9) update-index --index-version (other than 4) 10) update-index --[no-]skip-worktree 11) worktree Signed-off-by: Ben Peart <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 0ed17f0 commit 116dbce

File tree

5 files changed

+64
-5
lines changed

5 files changed

+64
-5
lines changed

builtin/gc.c

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "environment.h"
1717
#include "hex.h"
1818
#include "repository.h"
19+
#include "gvfs.h"
1920
#include "config.h"
2021
#include "tempfile.h"
2122
#include "lockfile.h"
@@ -676,6 +677,9 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
676677
if (quiet)
677678
strvec_push(&repack, "-q");
678679

680+
if ((!opts.auto_flag || (opts.auto_flag && gc_auto_threshold > 0)) && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
681+
die(_("'git gc' is not supported on a GVFS repo"));
682+
679683
if (opts.auto_flag) {
680684
/*
681685
* Auto-gc should be least intrusive as possible.

builtin/update-index.c

+10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
#define USE_THE_INDEX_VARIABLE
77
#include "builtin.h"
8+
#include "gvfs.h"
89
#include "bulk-checkin.h"
910
#include "config.h"
1011
#include "environment.h"
@@ -1109,7 +1110,13 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
11091110
argc = parse_options_end(&ctx);
11101111

11111112
getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf;
1113+
if (mark_skip_worktree_only && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
1114+
die(_("modifying the skip worktree bit is not supported on a GVFS repo"));
1115+
11121116
if (preferred_index_format) {
1117+
if (preferred_index_format != 4 && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
1118+
die(_("changing the index version is not supported on a GVFS repo"));
1119+
11131120
if (preferred_index_format < 0) {
11141121
printf(_("%d\n"), the_index.version);
11151122
} else if (preferred_index_format < INDEX_FORMAT_LB ||
@@ -1155,6 +1162,9 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
11551162
end_odb_transaction();
11561163

11571164
if (split_index > 0) {
1165+
if (gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
1166+
die(_("split index is not supported on a GVFS repo"));
1167+
11581168
if (git_config_get_split_index() == 0)
11591169
warning(_("core.splitIndex is set to false; "
11601170
"remove or change it, if you really want to "

git.c

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "builtin.h"
2+
#include "gvfs.h"
23
#include "config.h"
34
#include "environment.h"
45
#include "exec-cmd.h"
@@ -28,6 +29,7 @@
2829
#define NEED_WORK_TREE (1<<3)
2930
#define DELAY_PAGER_CONFIG (1<<4)
3031
#define NO_PARSEOPT (1<<5) /* parse-options is not used */
32+
#define BLOCK_ON_GVFS_REPO (1<<6) /* command not allowed in GVFS repos */
3133

3234
struct cmd_struct {
3335
const char *cmd;
@@ -526,6 +528,9 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
526528
if (!help && p->option & NEED_WORK_TREE)
527529
setup_work_tree();
528530

531+
if (!help && p->option & BLOCK_ON_GVFS_REPO && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
532+
die("'git %s' is not supported on a GVFS repo", p->cmd);
533+
529534
if (run_pre_command_hook(argv))
530535
die("pre-command hook aborted command");
531536

@@ -608,7 +613,7 @@ static struct cmd_struct commands[] = {
608613
{ "for-each-ref", cmd_for_each_ref, RUN_SETUP },
609614
{ "for-each-repo", cmd_for_each_repo, RUN_SETUP_GENTLY },
610615
{ "format-patch", cmd_format_patch, RUN_SETUP },
611-
{ "fsck", cmd_fsck, RUN_SETUP },
616+
{ "fsck", cmd_fsck, RUN_SETUP | BLOCK_ON_GVFS_REPO},
612617
{ "fsck-objects", cmd_fsck, RUN_SETUP },
613618
{ "fsmonitor--daemon", cmd_fsmonitor__daemon, RUN_SETUP },
614619
{ "gc", cmd_gc, RUN_SETUP },
@@ -649,7 +654,7 @@ static struct cmd_struct commands[] = {
649654
{ "pack-refs", cmd_pack_refs, RUN_SETUP },
650655
{ "patch-id", cmd_patch_id, RUN_SETUP_GENTLY | NO_PARSEOPT },
651656
{ "pickaxe", cmd_blame, RUN_SETUP },
652-
{ "prune", cmd_prune, RUN_SETUP },
657+
{ "prune", cmd_prune, RUN_SETUP | BLOCK_ON_GVFS_REPO},
653658
{ "prune-packed", cmd_prune_packed, RUN_SETUP },
654659
{ "pull", cmd_pull, RUN_SETUP | NEED_WORK_TREE },
655660
{ "push", cmd_push, RUN_SETUP },
@@ -661,7 +666,7 @@ static struct cmd_struct commands[] = {
661666
{ "remote", cmd_remote, RUN_SETUP },
662667
{ "remote-ext", cmd_remote_ext, NO_PARSEOPT },
663668
{ "remote-fd", cmd_remote_fd, NO_PARSEOPT },
664-
{ "repack", cmd_repack, RUN_SETUP },
669+
{ "repack", cmd_repack, RUN_SETUP | BLOCK_ON_GVFS_REPO },
665670
{ "replace", cmd_replace, RUN_SETUP },
666671
{ "replay", cmd_replay, RUN_SETUP },
667672
{ "rerere", cmd_rerere, RUN_SETUP },
@@ -682,7 +687,7 @@ static struct cmd_struct commands[] = {
682687
{ "stash", cmd_stash, RUN_SETUP | NEED_WORK_TREE },
683688
{ "status", cmd_status, RUN_SETUP | NEED_WORK_TREE },
684689
{ "stripspace", cmd_stripspace },
685-
{ "submodule--helper", cmd_submodule__helper, RUN_SETUP },
690+
{ "submodule--helper", cmd_submodule__helper, RUN_SETUP | BLOCK_ON_GVFS_REPO },
686691
{ "survey", cmd_survey, RUN_SETUP },
687692
{ "switch", cmd_switch, RUN_SETUP | NEED_WORK_TREE },
688693
{ "symbolic-ref", cmd_symbolic_ref, RUN_SETUP },
@@ -701,7 +706,7 @@ static struct cmd_struct commands[] = {
701706
{ "verify-tag", cmd_verify_tag, RUN_SETUP },
702707
{ "version", cmd_version },
703708
{ "whatchanged", cmd_whatchanged, RUN_SETUP },
704-
{ "worktree", cmd_worktree, RUN_SETUP },
709+
{ "worktree", cmd_worktree, RUN_SETUP | BLOCK_ON_GVFS_REPO },
705710
{ "write-tree", cmd_write_tree, RUN_SETUP },
706711
};
707712

gvfs.h

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* The list of bits in the core_gvfs setting
1313
*/
1414
#define GVFS_SKIP_SHA_ON_INDEX (1 << 0)
15+
#define GVFS_BLOCK_COMMANDS (1 << 1)
1516
#define GVFS_MISSING_OK (1 << 2)
1617
#define GVFS_NO_DELETE_OUTSIDE_SPARSECHECKOUT (1 << 3)
1718
#define GVFS_FETCH_SKIP_REACHABILITY_AND_UPLOADPACK (1 << 4)

t/t0402-block-command-on-gvfs.sh

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/sh
2+
3+
test_description='block commands in GVFS repo'
4+
5+
. ./test-lib.sh
6+
7+
not_with_gvfs () {
8+
command=$1 &&
9+
shift &&
10+
test_expect_success "test $command $*" "
11+
test_config alias.g4rbled $command &&
12+
test_config core.gvfs true &&
13+
test_must_fail git $command $* &&
14+
test_must_fail git g4rbled $* &&
15+
test_unconfig core.gvfs &&
16+
test_must_fail git -c core.gvfs=true $command $* &&
17+
test_must_fail git -c core.gvfs=true g4rbled $*
18+
"
19+
}
20+
21+
not_with_gvfs fsck
22+
not_with_gvfs gc
23+
not_with_gvfs gc --auto
24+
not_with_gvfs prune
25+
not_with_gvfs repack
26+
not_with_gvfs submodule status
27+
not_with_gvfs update-index --index-version 2
28+
not_with_gvfs update-index --skip-worktree
29+
not_with_gvfs update-index --no-skip-worktree
30+
not_with_gvfs update-index --split-index
31+
not_with_gvfs worktree list
32+
33+
test_expect_success 'test gc --auto succeeds when disabled via config' '
34+
test_config core.gvfs true &&
35+
test_config gc.auto 0 &&
36+
git gc --auto
37+
'
38+
39+
test_done

0 commit comments

Comments
 (0)