Skip to content

Commit 9d1374d

Browse files
authored
Merge pull request #85 from benpeart/block-commands
gvfs: block unsupported commands when running in a GVFS repo
2 parents 5dd0fb7 + cfe88be commit 9d1374d

File tree

4 files changed

+54
-6
lines changed

4 files changed

+54
-6
lines changed

builtin/update-index.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "dir.h"
1818
#include "split-index.h"
1919
#include "fsmonitor.h"
20+
#include "gvfs.h"
2021

2122
/*
2223
* Default to not allowing changes to the list of files. The
@@ -1098,7 +1099,13 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
10981099
argc = parse_options_end(&ctx);
10991100

11001101
getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf;
1102+
if (mark_skip_worktree_only && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
1103+
die(_("modifying the skip worktree bit is not supported on a GVFS repo"));
1104+
11011105
if (preferred_index_format) {
1106+
if (preferred_index_format != 4 && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
1107+
die(_("changing the index version is not supported on a GVFS repo"));
1108+
11021109
if (preferred_index_format < INDEX_FORMAT_LB ||
11031110
INDEX_FORMAT_UB < preferred_index_format)
11041111
die("index-version %d not in range: %d..%d",
@@ -1134,6 +1141,9 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
11341141
}
11351142

11361143
if (split_index > 0) {
1144+
if (gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
1145+
die(_("split index is not supported on a GVFS repo"));
1146+
11371147
if (git_config_get_split_index() == 0)
11381148
warning(_("core.splitIndex is set to false; "
11391149
"remove or change it, if you really want to "

git.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "run-command.h"
66
#include "alias.h"
77
#include "dir.h"
8+
#include "gvfs.h"
89

910
#define RUN_SETUP (1<<0)
1011
#define RUN_SETUP_GENTLY (1<<1)
@@ -17,6 +18,7 @@
1718
#define SUPPORT_SUPER_PREFIX (1<<4)
1819
#define DELAY_PAGER_CONFIG (1<<5)
1920
#define NO_PARSEOPT (1<<6) /* parse-options is not used */
21+
#define BLOCK_ON_GVFS_REPO (1<<7) /* command not allowed in GVFS repos */
2022

2123
struct cmd_struct {
2224
const char *cmd;
@@ -484,6 +486,9 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
484486
if (!help && p->option & NEED_WORK_TREE)
485487
setup_work_tree();
486488

489+
if (!help && p->option & BLOCK_ON_GVFS_REPO && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
490+
die("'git %s' is not supported on a GVFS repo", p->cmd);
491+
487492
if (run_pre_command_hook(argv))
488493
die("pre-command hook aborted command");
489494

@@ -558,9 +563,9 @@ static struct cmd_struct commands[] = {
558563
{ "fmt-merge-msg", cmd_fmt_merge_msg, RUN_SETUP },
559564
{ "for-each-ref", cmd_for_each_ref, RUN_SETUP },
560565
{ "format-patch", cmd_format_patch, RUN_SETUP },
561-
{ "fsck", cmd_fsck, RUN_SETUP },
566+
{ "fsck", cmd_fsck, RUN_SETUP | BLOCK_ON_GVFS_REPO},
562567
{ "fsck-objects", cmd_fsck, RUN_SETUP },
563-
{ "gc", cmd_gc, RUN_SETUP },
568+
{ "gc", cmd_gc, RUN_SETUP | BLOCK_ON_GVFS_REPO},
564569
{ "get-tar-commit-id", cmd_get_tar_commit_id, NO_PARSEOPT },
565570
{ "grep", cmd_grep, RUN_SETUP_GENTLY },
566571
{ "hash-object", cmd_hash_object },
@@ -596,7 +601,7 @@ static struct cmd_struct commands[] = {
596601
{ "pack-refs", cmd_pack_refs, RUN_SETUP },
597602
{ "patch-id", cmd_patch_id, RUN_SETUP_GENTLY | NO_PARSEOPT },
598603
{ "pickaxe", cmd_blame, RUN_SETUP },
599-
{ "prune", cmd_prune, RUN_SETUP },
604+
{ "prune", cmd_prune, RUN_SETUP | BLOCK_ON_GVFS_REPO},
600605
{ "prune-packed", cmd_prune_packed, RUN_SETUP },
601606
{ "pull", cmd_pull, RUN_SETUP | NEED_WORK_TREE },
602607
{ "push", cmd_push, RUN_SETUP },
@@ -614,7 +619,7 @@ static struct cmd_struct commands[] = {
614619
{ "remote", cmd_remote, RUN_SETUP },
615620
{ "remote-ext", cmd_remote_ext, NO_PARSEOPT },
616621
{ "remote-fd", cmd_remote_fd, NO_PARSEOPT },
617-
{ "repack", cmd_repack, RUN_SETUP },
622+
{ "repack", cmd_repack, RUN_SETUP | BLOCK_ON_GVFS_REPO },
618623
{ "replace", cmd_replace, RUN_SETUP },
619624
{ "rerere", cmd_rerere, RUN_SETUP },
620625
{ "reset", cmd_reset, RUN_SETUP },
@@ -638,7 +643,7 @@ static struct cmd_struct commands[] = {
638643
{ "stash", cmd_stash },
639644
{ "status", cmd_status, RUN_SETUP | NEED_WORK_TREE },
640645
{ "stripspace", cmd_stripspace },
641-
{ "submodule--helper", cmd_submodule__helper, RUN_SETUP | SUPPORT_SUPER_PREFIX | NO_PARSEOPT },
646+
{ "submodule--helper", cmd_submodule__helper, RUN_SETUP | SUPPORT_SUPER_PREFIX | NO_PARSEOPT | BLOCK_ON_GVFS_REPO },
642647
{ "symbolic-ref", cmd_symbolic_ref, RUN_SETUP },
643648
{ "tag", cmd_tag, RUN_SETUP | DELAY_PAGER_CONFIG },
644649
{ "unpack-file", cmd_unpack_file, RUN_SETUP | NO_PARSEOPT },
@@ -655,7 +660,7 @@ static struct cmd_struct commands[] = {
655660
{ "verify-tag", cmd_verify_tag, RUN_SETUP },
656661
{ "version", cmd_version },
657662
{ "whatchanged", cmd_whatchanged, RUN_SETUP },
658-
{ "worktree", cmd_worktree, RUN_SETUP | NO_PARSEOPT },
663+
{ "worktree", cmd_worktree, RUN_SETUP | NO_PARSEOPT | BLOCK_ON_GVFS_REPO },
659664
{ "write-tree", cmd_write_tree, RUN_SETUP },
660665
};
661666

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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 prune
24+
not_with_gvfs repack
25+
not_with_gvfs submodule status
26+
not_with_gvfs update-index --index-version 2
27+
not_with_gvfs update-index --skip-worktree
28+
not_with_gvfs update-index --no-skip-worktree
29+
not_with_gvfs update-index --split-index
30+
not_with_gvfs worktree list
31+
32+
test_done

0 commit comments

Comments
 (0)