Skip to content

Commit b88a9ce

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 <benpeart@microsoft.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 610bacb commit b88a9ce

File tree

6 files changed

+68
-7
lines changed

6 files changed

+68
-7
lines changed

builtin/gc.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "dir.h"
2020
#include "environment.h"
2121
#include "hex.h"
22+
#include "gvfs.h"
2223
#include "config.h"
2324
#include "tempfile.h"
2425
#include "lockfile.h"
@@ -843,7 +844,7 @@ static int gc_foreground_tasks(struct maintenance_run_opts *opts,
843844
int cmd_gc(int argc,
844845
const char **argv,
845846
const char *prefix,
846-
struct repository *repo UNUSED)
847+
struct repository *repo)
847848
{
848849
int aggressive = 0;
849850
int force = 0;
@@ -925,6 +926,10 @@ int cmd_gc(int argc,
925926
if (opts.quiet)
926927
strvec_push(&repack_args, "-q");
927928

929+
if ((!opts.auto_flag || (opts.auto_flag && cfg.gc_auto_threshold > 0)) &&
930+
gvfs_config_is_set(repo, GVFS_BLOCK_COMMANDS))
931+
die(_("'git gc' is not supported on a GVFS repo"));
932+
928933
if (opts.auto_flag) {
929934
if (cfg.detach_auto && opts.detach < 0)
930935
opts.detach = 1;

builtin/update-index.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define DISABLE_SIGN_COMPARE_WARNINGS
99

1010
#include "builtin.h"
11+
#include "gvfs.h"
1112
#include "config.h"
1213
#include "environment.h"
1314
#include "gettext.h"
@@ -914,7 +915,7 @@ static enum parse_opt_result reupdate_callback(
914915
int cmd_update_index(int argc,
915916
const char **argv,
916917
const char *prefix,
917-
struct repository *repo UNUSED)
918+
struct repository *repo)
918919
{
919920
int newfd, entries, has_errors = 0, nul_term_line = 0;
920921
enum uc_mode untracked_cache = UC_UNSPECIFIED;
@@ -1178,7 +1179,13 @@ int cmd_update_index(int argc,
11781179
argc = parse_options_end(&ctx);
11791180

11801181
getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf;
1182+
if (mark_skip_worktree_only && gvfs_config_is_set(repo, GVFS_BLOCK_COMMANDS))
1183+
die(_("modifying the skip worktree bit is not supported on a GVFS repo"));
1184+
11811185
if (preferred_index_format) {
1186+
if (preferred_index_format != 4 && gvfs_config_is_set(repo, GVFS_BLOCK_COMMANDS))
1187+
die(_("changing the index version is not supported on a GVFS repo"));
1188+
11821189
if (preferred_index_format < 0) {
11831190
printf(_("%d\n"), the_repository->index->version);
11841191
} else if (preferred_index_format < INDEX_FORMAT_LB ||
@@ -1224,6 +1231,9 @@ int cmd_update_index(int argc,
12241231
odb_transaction_commit(transaction);
12251232

12261233
if (split_index > 0) {
1234+
if (gvfs_config_is_set(repo, GVFS_BLOCK_COMMANDS))
1235+
die(_("split index is not supported on a GVFS repo"));
1236+
12271237
if (repo_config_get_split_index(the_repository) == 0)
12281238
warning(_("core.splitIndex is set to false; "
12291239
"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,6 +1,7 @@
11
#define USE_THE_REPOSITORY_VARIABLE
22

33
#include "builtin.h"
4+
#include "gvfs.h"
45
#include "config.h"
56
#include "environment.h"
67
#include "exec-cmd.h"
@@ -31,6 +32,7 @@
3132
#define DELAY_PAGER_CONFIG (1<<4)
3233
#define NO_PARSEOPT (1<<5) /* parse-options is not used */
3334
#define DEPRECATED (1<<6)
35+
#define BLOCK_ON_GVFS_REPO (1<<7) /* command not allowed in GVFS repos */
3436

3537
struct cmd_struct {
3638
const char *cmd;
@@ -563,6 +565,9 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv, struct
563565
if (!help && p->option & NEED_WORK_TREE)
564566
setup_work_tree();
565567

568+
if (!help && p->option & BLOCK_ON_GVFS_REPO && gvfs_config_is_set(repo, GVFS_BLOCK_COMMANDS))
569+
die("'git %s' is not supported on a GVFS repo", p->cmd);
570+
566571
if (run_pre_command_hook(the_repository, argv))
567572
die("pre-command hook aborted command");
568573

@@ -647,7 +652,7 @@ static struct cmd_struct commands[] = {
647652
{ "for-each-ref", cmd_for_each_ref, RUN_SETUP },
648653
{ "for-each-repo", cmd_for_each_repo, RUN_SETUP_GENTLY },
649654
{ "format-patch", cmd_format_patch, RUN_SETUP },
650-
{ "fsck", cmd_fsck, RUN_SETUP },
655+
{ "fsck", cmd_fsck, RUN_SETUP | BLOCK_ON_GVFS_REPO},
651656
{ "fsck-objects", cmd_fsck, RUN_SETUP },
652657
{ "fsmonitor--daemon", cmd_fsmonitor__daemon, RUN_SETUP },
653658
{ "gc", cmd_gc, RUN_SETUP },
@@ -691,7 +696,7 @@ static struct cmd_struct commands[] = {
691696
{ "pack-refs", cmd_pack_refs, RUN_SETUP },
692697
{ "patch-id", cmd_patch_id, RUN_SETUP_GENTLY | NO_PARSEOPT },
693698
{ "pickaxe", cmd_blame, RUN_SETUP },
694-
{ "prune", cmd_prune, RUN_SETUP },
699+
{ "prune", cmd_prune, RUN_SETUP | BLOCK_ON_GVFS_REPO},
695700
{ "prune-packed", cmd_prune_packed, RUN_SETUP },
696701
{ "pull", cmd_pull, RUN_SETUP | NEED_WORK_TREE },
697702
{ "push", cmd_push, RUN_SETUP },
@@ -704,7 +709,7 @@ static struct cmd_struct commands[] = {
704709
{ "remote", cmd_remote, RUN_SETUP },
705710
{ "remote-ext", cmd_remote_ext, NO_PARSEOPT },
706711
{ "remote-fd", cmd_remote_fd, NO_PARSEOPT },
707-
{ "repack", cmd_repack, RUN_SETUP },
712+
{ "repack", cmd_repack, RUN_SETUP | BLOCK_ON_GVFS_REPO },
708713
{ "replace", cmd_replace, RUN_SETUP },
709714
{ "replay", cmd_replay, RUN_SETUP },
710715
{ "repo", cmd_repo, RUN_SETUP },
@@ -726,7 +731,7 @@ static struct cmd_struct commands[] = {
726731
{ "stash", cmd_stash, RUN_SETUP | NEED_WORK_TREE },
727732
{ "status", cmd_status, RUN_SETUP | NEED_WORK_TREE },
728733
{ "stripspace", cmd_stripspace },
729-
{ "submodule--helper", cmd_submodule__helper, RUN_SETUP },
734+
{ "submodule--helper", cmd_submodule__helper, RUN_SETUP | BLOCK_ON_GVFS_REPO },
730735
{ "survey", cmd_survey, RUN_SETUP },
731736
{ "switch", cmd_switch, RUN_SETUP | NEED_WORK_TREE },
732737
{ "symbolic-ref", cmd_symbolic_ref, RUN_SETUP },
@@ -747,7 +752,7 @@ static struct cmd_struct commands[] = {
747752
#ifndef WITH_BREAKING_CHANGES
748753
{ "whatchanged", cmd_whatchanged, RUN_SETUP | DEPRECATED },
749754
#endif
750-
{ "worktree", cmd_worktree, RUN_SETUP },
755+
{ "worktree", cmd_worktree, RUN_SETUP | BLOCK_ON_GVFS_REPO },
751756
{ "write-tree", cmd_write_tree, RUN_SETUP },
752757
};
753758

gvfs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ struct repository;
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

1718
/*

t/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ integration_tests = [
138138
't0303-credential-external.sh',
139139
't0400-pre-command-hook.sh',
140140
't0401-post-command-hook.sh',
141+
't0402-block-command-on-gvfs.sh',
141142
't0410-partial-clone.sh',
142143
't0411-clone-from-partial.sh',
143144
't0450-txt-doc-vs-help.sh',

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)