Skip to content

Commit 2337249

Browse files
Tyrie VellaCopilot
andcommitted
worktree: address PR feedback
Move the VFS worktree block from the generic BLOCK_ON_VFS_ENABLED check in run_builtin() to an explicit check in cmd_worktree(). This keeps the worktree entry in the commands table clean (RUN_SETUP only) and makes the VFS guard self-contained in builtin/worktree.c. Guard the skip-clean-check marker behind core_virtualfilesystem so it only takes effect when VFS is active. Consolidate the worktree tests into a single test case that covers add (with --no-checkout verification), list, and remove. Use core.gvfs=true instead of the magic number 351. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent dedaa37 commit 2337249

3 files changed

Lines changed: 25 additions & 39 deletions

File tree

builtin/worktree.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1420,7 +1420,7 @@ static int remove_worktree(int ac, const char **av, const char *prefix,
14201420
strbuf_release(&errmsg);
14211421

14221422
if (file_exists(wt->path)) {
1423-
if (!force && !should_skip_clean_check(wt))
1423+
if (!force && !(core_virtualfilesystem && should_skip_clean_check(wt)))
14241424
check_clean_worktree(wt, av[0]);
14251425

14261426
ret |= delete_git_work_tree(wt);
@@ -1492,6 +1492,14 @@ int cmd_worktree(int ac,
14921492

14931493
ac = parse_options(ac, av, prefix, options, git_worktree_usage, 0);
14941494

1495+
/*
1496+
* Block worktree commands when VFS is active unless the VFS layer
1497+
* has signaled worktree support via GVFS_SUPPORTS_WORKTREES.
1498+
*/
1499+
if (gvfs_config_is_set(the_repository, GVFS_USE_VIRTUAL_FILESYSTEM) &&
1500+
!gvfs_config_is_set(the_repository, GVFS_SUPPORTS_WORKTREES))
1501+
die("'git worktree' is not supported when using the virtual file system");
1502+
14951503
prepare_repo_settings(the_repository);
14961504
the_repository->settings.command_requires_full_index = 0;
14971505

git.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv, struct
574574
die("'git %s' is not supported on a GVFS repo", p->cmd);
575575

576576
if (!help && p->option & BLOCK_ON_VFS_ENABLED && gvfs_config_is_set(repo, GVFS_USE_VIRTUAL_FILESYSTEM))
577-
if (strcmp(p->cmd, "worktree") != 0 || !gvfs_config_is_set(repo, GVFS_SUPPORTS_WORKTREES))
578-
die("'git %s' is not supported when using the virtual file system", p->cmd);
577+
die("'git %s' is not supported when using the virtual file system", p->cmd);
579578

580579
if (run_pre_command_hook(the_repository, argv))
581580
die("pre-command hook aborted command");
@@ -762,7 +761,7 @@ static struct cmd_struct commands[] = {
762761
#ifndef WITH_BREAKING_CHANGES
763762
{ "whatchanged", cmd_whatchanged, RUN_SETUP | DEPRECATED },
764763
#endif
765-
{ "worktree", cmd_worktree, RUN_SETUP | BLOCK_ON_VFS_ENABLED },
764+
{ "worktree", cmd_worktree, RUN_SETUP },
766765
{ "write-tree", cmd_write_tree, RUN_SETUP },
767766
};
768767

t/t0402-block-command-on-gvfs.sh

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -29,52 +29,31 @@ not_with_gvfs update-index --no-skip-worktree
2929
not_with_gvfs update-index --split-index
3030

3131
# worktree is conditionally allowed: blocked when VFS enabled without
32-
# GVFS_SUPPORTS_WORKTREES, but core.gvfs=true sets all bits including
33-
# SUPPORTS_WORKTREES, so we test the blocked case with a specific bitmask.
32+
# GVFS_SUPPORTS_WORKTREES.
3433
test_expect_success 'worktree blocked with VFS but without SUPPORTS_WORKTREES' '
3534
test_config core.gvfs 95 &&
3635
test_must_fail git worktree list 2>err &&
3736
test_grep "not supported when using the virtual file system" err
3837
'
3938

40-
# core.gvfs bitmask values:
41-
# GVFS_USE_VIRTUAL_FILESYSTEM = (1 << 3) = 8
42-
# GVFS_SUPPORTS_WORKTREES = (1 << 8) = 256
43-
# A typical VFS-enabled repo has core.gvfs=95 (bits 0-4,6).
44-
# Adding SUPPORTS_WORKTREES: 95 + 256 = 351.
39+
test_expect_success 'worktree operations work when SUPPORTS_WORKTREES is set' '
40+
test_commit initial &&
4541
46-
test_expect_success 'setup for worktree tests' '
47-
test_commit initial
48-
'
49-
50-
test_expect_success 'worktree allowed when SUPPORTS_WORKTREES bit is set' '
51-
test_when_finished "git worktree remove --force ../allowed-wt 2>/dev/null; true" &&
52-
test_config core.gvfs 351 &&
53-
git worktree add ../allowed-wt &&
54-
test_path_exists ../allowed-wt/.git
55-
'
42+
# Use core.gvfs=true which sets all bits including SUPPORTS_WORKTREES.
43+
test_config core.gvfs true &&
5644
57-
test_expect_success 'worktree add forces --no-checkout when VFS active' '
58-
test_when_finished "git worktree remove --force ../nocheckout-wt 2>/dev/null; true" &&
59-
test_config core.gvfs 351 &&
60-
git worktree add ../nocheckout-wt &&
61-
test_path_exists ../nocheckout-wt/.git &&
62-
! test_path_exists ../nocheckout-wt/initial.t
63-
'
45+
# add: succeeds, forces --no-checkout (no initial.t on disk)
46+
git worktree add ../vfs-wt &&
47+
test_path_exists ../vfs-wt/.git &&
48+
! test_path_exists ../vfs-wt/initial.t &&
6449
65-
test_expect_success 'worktree list works with SUPPORTS_WORKTREES' '
66-
test_when_finished "git worktree remove --force ../list-wt 2>/dev/null; true" &&
67-
test_config core.gvfs 351 &&
68-
git worktree add ../list-wt &&
50+
# list: shows the worktree
6951
git worktree list >out &&
70-
grep "list-wt" out
71-
'
52+
grep "vfs-wt" out &&
7253
73-
test_expect_success 'worktree remove works with SUPPORTS_WORKTREES' '
74-
test_config core.gvfs 351 &&
75-
git worktree add ../remove-wt &&
76-
git worktree remove --force ../remove-wt &&
77-
! test_path_exists ../remove-wt
54+
# remove: cleans up
55+
git worktree remove --force ../vfs-wt &&
56+
! test_path_exists ../vfs-wt
7857
'
7958

8059
test_expect_success 'test gc --auto succeeds when disabled via config' '

0 commit comments

Comments
 (0)