Skip to content

Commit babf5e7

Browse files
benpeartderrickstolee
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 <benpeart@microsoft.com>
1 parent c315007 commit babf5e7

5 files changed

Lines changed: 64 additions & 5 deletions

File tree

builtin/gc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "builtin.h"
1414
#include "repository.h"
15+
#include "gvfs.h"
1516
#include "config.h"
1617
#include "tempfile.h"
1718
#include "lockfile.h"
@@ -596,6 +597,9 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
596597
if (quiet)
597598
strvec_push(&repack, "-q");
598599

600+
if ((!auto_gc || (auto_gc && gc_auto_threshold > 0)) && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
601+
die(_("'git gc' is not supported on a GVFS repo"));
602+
599603
if (auto_gc) {
600604
/*
601605
* Auto-gc should be least intrusive as possible.

builtin/update-index.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
#define USE_THE_INDEX_COMPATIBILITY_MACROS
77
#include "cache.h"
8+
#include "gvfs.h"
89
#include "config.h"
910
#include "lockfile.h"
1011
#include "quote.h"
@@ -1135,7 +1136,13 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
11351136
argc = parse_options_end(&ctx);
11361137

11371138
getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf;
1139+
if (mark_skip_worktree_only && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
1140+
die(_("modifying the skip worktree bit is not supported on a GVFS repo"));
1141+
11381142
if (preferred_index_format) {
1143+
if (preferred_index_format != 4 && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
1144+
die(_("changing the index version is not supported on a GVFS repo"));
1145+
11391146
if (preferred_index_format < INDEX_FORMAT_LB ||
11401147
INDEX_FORMAT_UB < preferred_index_format)
11411148
die("index-version %d not in range: %d..%d",
@@ -1171,6 +1178,9 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
11711178
}
11721179

11731180
if (split_index > 0) {
1181+
if (gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
1182+
die(_("split index is not supported on a GVFS repo"));
1183+
11741184
if (git_config_get_split_index() == 0)
11751185
warning(_("core.splitIndex is set to false; "
11761186
"remove or change it, if you really want to "

git.c

Lines changed: 10 additions & 5 deletions
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 "exec-cmd.h"
45
#include "help.h"
@@ -18,6 +19,7 @@
1819
#define SUPPORT_SUPER_PREFIX (1<<4)
1920
#define DELAY_PAGER_CONFIG (1<<5)
2021
#define NO_PARSEOPT (1<<6) /* parse-options is not used */
22+
#define BLOCK_ON_GVFS_REPO (1<<7) /* command not allowed in GVFS repos */
2123

2224
struct cmd_struct {
2325
const char *cmd;
@@ -511,6 +513,9 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
511513
if (!help && p->option & NEED_WORK_TREE)
512514
setup_work_tree();
513515

516+
if (!help && p->option & BLOCK_ON_GVFS_REPO && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
517+
die("'git %s' is not supported on a GVFS repo", p->cmd);
518+
514519
if (run_pre_command_hook(argv))
515520
die("pre-command hook aborted command");
516521

@@ -595,7 +600,7 @@ static struct cmd_struct commands[] = {
595600
{ "for-each-ref", cmd_for_each_ref, RUN_SETUP },
596601
{ "for-each-repo", cmd_for_each_repo, RUN_SETUP_GENTLY },
597602
{ "format-patch", cmd_format_patch, RUN_SETUP },
598-
{ "fsck", cmd_fsck, RUN_SETUP },
603+
{ "fsck", cmd_fsck, RUN_SETUP | BLOCK_ON_GVFS_REPO},
599604
{ "fsck-objects", cmd_fsck, RUN_SETUP },
600605
{ "fsmonitor--daemon", cmd_fsmonitor__daemon, RUN_SETUP },
601606
{ "gc", cmd_gc, RUN_SETUP },
@@ -635,7 +640,7 @@ static struct cmd_struct commands[] = {
635640
{ "pack-refs", cmd_pack_refs, RUN_SETUP },
636641
{ "patch-id", cmd_patch_id, RUN_SETUP_GENTLY | NO_PARSEOPT },
637642
{ "pickaxe", cmd_blame, RUN_SETUP },
638-
{ "prune", cmd_prune, RUN_SETUP },
643+
{ "prune", cmd_prune, RUN_SETUP | BLOCK_ON_GVFS_REPO},
639644
{ "prune-packed", cmd_prune_packed, RUN_SETUP },
640645
{ "pull", cmd_pull, RUN_SETUP | NEED_WORK_TREE },
641646
{ "push", cmd_push, RUN_SETUP },
@@ -648,7 +653,7 @@ static struct cmd_struct commands[] = {
648653
{ "remote", cmd_remote, RUN_SETUP },
649654
{ "remote-ext", cmd_remote_ext, NO_PARSEOPT },
650655
{ "remote-fd", cmd_remote_fd, NO_PARSEOPT },
651-
{ "repack", cmd_repack, RUN_SETUP },
656+
{ "repack", cmd_repack, RUN_SETUP | BLOCK_ON_GVFS_REPO },
652657
{ "replace", cmd_replace, RUN_SETUP },
653658
{ "rerere", cmd_rerere, RUN_SETUP },
654659
{ "reset", cmd_reset, RUN_SETUP },
@@ -668,7 +673,7 @@ static struct cmd_struct commands[] = {
668673
{ "stash", cmd_stash, RUN_SETUP | NEED_WORK_TREE },
669674
{ "status", cmd_status, RUN_SETUP | NEED_WORK_TREE },
670675
{ "stripspace", cmd_stripspace },
671-
{ "submodule--helper", cmd_submodule__helper, RUN_SETUP | SUPPORT_SUPER_PREFIX | NO_PARSEOPT },
676+
{ "submodule--helper", cmd_submodule__helper, RUN_SETUP | SUPPORT_SUPER_PREFIX | NO_PARSEOPT | BLOCK_ON_GVFS_REPO },
672677
{ "switch", cmd_switch, RUN_SETUP | NEED_WORK_TREE },
673678
{ "symbolic-ref", cmd_symbolic_ref, RUN_SETUP },
674679
{ "tag", cmd_tag, RUN_SETUP | DELAY_PAGER_CONFIG },
@@ -686,7 +691,7 @@ static struct cmd_struct commands[] = {
686691
{ "verify-tag", cmd_verify_tag, RUN_SETUP },
687692
{ "version", cmd_version },
688693
{ "whatchanged", cmd_whatchanged, RUN_SETUP },
689-
{ "worktree", cmd_worktree, RUN_SETUP | NO_PARSEOPT },
694+
{ "worktree", cmd_worktree, RUN_SETUP | NO_PARSEOPT | BLOCK_ON_GVFS_REPO },
690695
{ "write-tree", cmd_write_tree, RUN_SETUP },
691696
};
692697

gvfs.h

Lines changed: 1 addition & 0 deletions
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

Lines changed: 39 additions & 0 deletions
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)