Skip to content

Commit 4920f57

Browse files
benpeartdscho
authored andcommitted
Merge pull request #85 from benpeart/block-commands
gvfs: block unsupported commands when running in a GVFS repo
2 parents 478d082 + b61fc1c commit 4920f57

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
@@ -1115,7 +1116,13 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
11151116
argc = parse_options_end(&ctx);
11161117

11171118
getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf;
1119+
if (mark_skip_worktree_only && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
1120+
die(_("modifying the skip worktree bit is not supported on a GVFS repo"));
1121+
11181122
if (preferred_index_format) {
1123+
if (preferred_index_format != 4 && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
1124+
die(_("changing the index version is not supported on a GVFS repo"));
1125+
11191126
if (preferred_index_format < INDEX_FORMAT_LB ||
11201127
INDEX_FORMAT_UB < preferred_index_format)
11211128
die("index-version %d not in range: %d..%d",
@@ -1151,6 +1158,9 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
11511158
}
11521159

11531160
if (split_index > 0) {
1161+
if (gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
1162+
die(_("split index is not supported on a GVFS repo"));
1163+
11541164
if (git_config_get_split_index() == 0)
11551165
warning(_("core.splitIndex is set to false; "
11561166
"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;
@@ -487,6 +489,9 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
487489
if (!help && p->option & NEED_WORK_TREE)
488490
setup_work_tree();
489491

492+
if (!help && p->option & BLOCK_ON_GVFS_REPO && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
493+
die("'git %s' is not supported on a GVFS repo", p->cmd);
494+
490495
if (run_pre_command_hook(argv))
491496
die("pre-command hook aborted command");
492497

@@ -561,9 +566,9 @@ static struct cmd_struct commands[] = {
561566
{ "fmt-merge-msg", cmd_fmt_merge_msg, RUN_SETUP },
562567
{ "for-each-ref", cmd_for_each_ref, RUN_SETUP },
563568
{ "format-patch", cmd_format_patch, RUN_SETUP },
564-
{ "fsck", cmd_fsck, RUN_SETUP },
569+
{ "fsck", cmd_fsck, RUN_SETUP | BLOCK_ON_GVFS_REPO},
565570
{ "fsck-objects", cmd_fsck, RUN_SETUP },
566-
{ "gc", cmd_gc, RUN_SETUP },
571+
{ "gc", cmd_gc, RUN_SETUP | BLOCK_ON_GVFS_REPO},
567572
{ "get-tar-commit-id", cmd_get_tar_commit_id, NO_PARSEOPT },
568573
{ "grep", cmd_grep, RUN_SETUP_GENTLY },
569574
{ "hash-object", cmd_hash_object },
@@ -599,7 +604,7 @@ static struct cmd_struct commands[] = {
599604
{ "pack-refs", cmd_pack_refs, RUN_SETUP },
600605
{ "patch-id", cmd_patch_id, RUN_SETUP_GENTLY | NO_PARSEOPT },
601606
{ "pickaxe", cmd_blame, RUN_SETUP },
602-
{ "prune", cmd_prune, RUN_SETUP },
607+
{ "prune", cmd_prune, RUN_SETUP | BLOCK_ON_GVFS_REPO},
603608
{ "prune-packed", cmd_prune_packed, RUN_SETUP },
604609
{ "pull", cmd_pull, RUN_SETUP | NEED_WORK_TREE },
605610
{ "push", cmd_push, RUN_SETUP },
@@ -617,7 +622,7 @@ static struct cmd_struct commands[] = {
617622
{ "remote", cmd_remote, RUN_SETUP },
618623
{ "remote-ext", cmd_remote_ext, NO_PARSEOPT },
619624
{ "remote-fd", cmd_remote_fd, NO_PARSEOPT },
620-
{ "repack", cmd_repack, RUN_SETUP },
625+
{ "repack", cmd_repack, RUN_SETUP | BLOCK_ON_GVFS_REPO },
621626
{ "replace", cmd_replace, RUN_SETUP },
622627
{ "rerere", cmd_rerere, RUN_SETUP },
623628
{ "reset", cmd_reset, RUN_SETUP },
@@ -641,7 +646,7 @@ static struct cmd_struct commands[] = {
641646
{ "stash", cmd_stash },
642647
{ "status", cmd_status, RUN_SETUP | NEED_WORK_TREE },
643648
{ "stripspace", cmd_stripspace },
644-
{ "submodule--helper", cmd_submodule__helper, RUN_SETUP | SUPPORT_SUPER_PREFIX | NO_PARSEOPT },
649+
{ "submodule--helper", cmd_submodule__helper, RUN_SETUP | SUPPORT_SUPER_PREFIX | NO_PARSEOPT | BLOCK_ON_GVFS_REPO },
645650
{ "symbolic-ref", cmd_symbolic_ref, RUN_SETUP },
646651
{ "tag", cmd_tag, RUN_SETUP | DELAY_PAGER_CONFIG },
647652
{ "unpack-file", cmd_unpack_file, RUN_SETUP | NO_PARSEOPT },
@@ -658,7 +663,7 @@ static struct cmd_struct commands[] = {
658663
{ "verify-tag", cmd_verify_tag, RUN_SETUP },
659664
{ "version", cmd_version },
660665
{ "whatchanged", cmd_whatchanged, RUN_SETUP },
661-
{ "worktree", cmd_worktree, RUN_SETUP | NO_PARSEOPT },
666+
{ "worktree", cmd_worktree, RUN_SETUP | NO_PARSEOPT | BLOCK_ON_GVFS_REPO },
662667
{ "write-tree", cmd_write_tree, RUN_SETUP },
663668
};
664669

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)