Skip to content

Commit 2f54b0c

Browse files
benpeartdscho
authored andcommitted
Merge pull request #91 from benpeart/block-commands
gvfs: block unsupported commands when running in a GVFS repo
2 parents 01b3ca9 + e7652b9 commit 2f54b0c

File tree

5 files changed

+64
-5
lines changed

5 files changed

+64
-5
lines changed

builtin/gc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "pack-objects.h"
2828
#include "blob.h"
2929
#include "tree.h"
30+
#include "gvfs.h"
3031

3132
#define FAILED_RUN "failed to run %s"
3233

@@ -586,6 +587,9 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
586587
if (quiet)
587588
argv_array_push(&repack, "-q");
588589

590+
if ((!auto_gc || (auto_gc && gc_auto_threshold > 0)) && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
591+
die(_("'git gc' is not supported on a GVFS repo"));
592+
589593
if (auto_gc) {
590594
/*
591595
* 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
@@ -18,6 +18,7 @@
1818
#include "dir.h"
1919
#include "split-index.h"
2020
#include "fsmonitor.h"
21+
#include "gvfs.h"
2122

2223
/*
2324
* Default to not allowing changes to the list of files. The
@@ -1128,7 +1129,13 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
11281129
argc = parse_options_end(&ctx);
11291130

11301131
getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf;
1132+
if (mark_skip_worktree_only && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
1133+
die(_("modifying the skip worktree bit is not supported on a GVFS repo"));
1134+
11311135
if (preferred_index_format) {
1136+
if (preferred_index_format != 4 && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
1137+
die(_("changing the index version is not supported on a GVFS repo"));
1138+
11321139
if (preferred_index_format < INDEX_FORMAT_LB ||
11331140
INDEX_FORMAT_UB < preferred_index_format)
11341141
die("index-version %d not in range: %d..%d",
@@ -1164,6 +1171,9 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
11641171
}
11651172

11661173
if (split_index > 0) {
1174+
if (gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
1175+
die(_("split index is not supported on a GVFS repo"));
1176+
11671177
if (git_config_get_split_index() == 0)
11681178
warning(_("core.splitIndex is set to false; "
11691179
"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
@@ -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;
@@ -495,6 +497,9 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
495497
if (!help && p->option & NEED_WORK_TREE)
496498
setup_work_tree();
497499

500+
if (!help && p->option & BLOCK_ON_GVFS_REPO && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
501+
die("'git %s' is not supported on a GVFS repo", p->cmd);
502+
498503
if (run_pre_command_hook(argv))
499504
die("pre-command hook aborted command");
500505

@@ -569,7 +574,7 @@ static struct cmd_struct commands[] = {
569574
{ "fmt-merge-msg", cmd_fmt_merge_msg, RUN_SETUP },
570575
{ "for-each-ref", cmd_for_each_ref, RUN_SETUP },
571576
{ "format-patch", cmd_format_patch, RUN_SETUP },
572-
{ "fsck", cmd_fsck, RUN_SETUP },
577+
{ "fsck", cmd_fsck, RUN_SETUP | BLOCK_ON_GVFS_REPO},
573578
{ "fsck-objects", cmd_fsck, RUN_SETUP },
574579
{ "gc", cmd_gc, RUN_SETUP },
575580
{ "get-tar-commit-id", cmd_get_tar_commit_id, NO_PARSEOPT },
@@ -607,7 +612,7 @@ static struct cmd_struct commands[] = {
607612
{ "pack-refs", cmd_pack_refs, RUN_SETUP },
608613
{ "patch-id", cmd_patch_id, RUN_SETUP_GENTLY | NO_PARSEOPT },
609614
{ "pickaxe", cmd_blame, RUN_SETUP },
610-
{ "prune", cmd_prune, RUN_SETUP },
615+
{ "prune", cmd_prune, RUN_SETUP | BLOCK_ON_GVFS_REPO},
611616
{ "prune-packed", cmd_prune_packed, RUN_SETUP },
612617
{ "pull", cmd_pull, RUN_SETUP | NEED_WORK_TREE },
613618
{ "push", cmd_push, RUN_SETUP },
@@ -625,7 +630,7 @@ static struct cmd_struct commands[] = {
625630
{ "remote", cmd_remote, RUN_SETUP },
626631
{ "remote-ext", cmd_remote_ext, NO_PARSEOPT },
627632
{ "remote-fd", cmd_remote_fd, NO_PARSEOPT },
628-
{ "repack", cmd_repack, RUN_SETUP },
633+
{ "repack", cmd_repack, RUN_SETUP | BLOCK_ON_GVFS_REPO },
629634
{ "replace", cmd_replace, RUN_SETUP },
630635
{ "rerere", cmd_rerere, RUN_SETUP },
631636
{ "reset", cmd_reset, RUN_SETUP },
@@ -648,7 +653,7 @@ static struct cmd_struct commands[] = {
648653
{ "stash", cmd_stash },
649654
{ "status", cmd_status, RUN_SETUP | NEED_WORK_TREE },
650655
{ "stripspace", cmd_stripspace },
651-
{ "submodule--helper", cmd_submodule__helper, RUN_SETUP | SUPPORT_SUPER_PREFIX | NO_PARSEOPT },
656+
{ "submodule--helper", cmd_submodule__helper, RUN_SETUP | SUPPORT_SUPER_PREFIX | NO_PARSEOPT | BLOCK_ON_GVFS_REPO },
652657
{ "symbolic-ref", cmd_symbolic_ref, RUN_SETUP },
653658
{ "tag", cmd_tag, RUN_SETUP | DELAY_PAGER_CONFIG },
654659
{ "unpack-file", cmd_unpack_file, RUN_SETUP | NO_PARSEOPT },
@@ -665,7 +670,7 @@ static struct cmd_struct commands[] = {
665670
{ "verify-tag", cmd_verify_tag, RUN_SETUP },
666671
{ "version", cmd_version },
667672
{ "whatchanged", cmd_whatchanged, RUN_SETUP },
668-
{ "worktree", cmd_worktree, RUN_SETUP | NO_PARSEOPT },
673+
{ "worktree", cmd_worktree, RUN_SETUP | NO_PARSEOPT | BLOCK_ON_GVFS_REPO },
669674
{ "write-tree", cmd_write_tree, RUN_SETUP },
670675
};
671676

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)