Skip to content

Commit 50b45b6

Browse files
derrickstoleedscho
authored andcommitted
worktree: allow in Scalar repositories
The 'git worktree' command was marked as BLOCK_ON_GVFS_REPO because it does not interact well with the virtual filesystem of VFS for Git. When a Scalar clone uses the GVFS protocol, it enables the GVFS_BLOCK_COMMANDS flag, since commands like 'git gc' do not work well with the GVFS protocol. However, 'git worktree' works just fine with the GVFS protocol since it isn't doing anything special. It copies the sparse-checkout from the current worktree, so it does not have performance issues. This is a highly requested option. The solution is to stop using the BLOCK_ON_GVFS_REPO option and instead add a special-case check in cmd_worktree() specifically for a particular bit of the 'core_gvfs' global variable (loaded by very early config reading) that corresponds to the virtual filesystem. The bit that most closely resembled this behavior was non-obviously named, but does provide a signal that we are in a Scalar clone and not a VFS for Git clone. The error message is copied from git.c, so it will have the same output as before if a user runs this in a VFS for Git clone. Signed-off-by: Derrick Stolee <[email protected]>
1 parent ebba63f commit 50b45b6

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

builtin/worktree.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "builtin.h"
55
#include "abspath.h"
66
#include "advice.h"
7+
#include "gvfs.h"
78
#include "checkout.h"
89
#include "config.h"
910
#include "copy.h"
@@ -1429,6 +1430,13 @@ int cmd_worktree(int ac,
14291430

14301431
git_config(git_worktree_config, NULL);
14311432

1433+
/*
1434+
* git-worktree is special-cased to work in Scalar repositories
1435+
* even when they use the GVFS Protocol.
1436+
*/
1437+
if (core_gvfs & GVFS_USE_VIRTUAL_FILESYSTEM)
1438+
die("'git %s' is not supported on a GVFS repo", "worktree");
1439+
14321440
if (!prefix)
14331441
prefix = "";
14341442

git.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ static struct cmd_struct commands[] = {
719719
{ "verify-tag", cmd_verify_tag, RUN_SETUP },
720720
{ "version", cmd_version },
721721
{ "whatchanged", cmd_whatchanged, RUN_SETUP },
722-
{ "worktree", cmd_worktree, RUN_SETUP | BLOCK_ON_GVFS_REPO },
722+
{ "worktree", cmd_worktree, RUN_SETUP },
723723
{ "write-tree", cmd_write_tree, RUN_SETUP },
724724
};
725725

gvfs.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,18 @@
1414
#define GVFS_SKIP_SHA_ON_INDEX (1 << 0)
1515
#define GVFS_BLOCK_COMMANDS (1 << 1)
1616
#define GVFS_MISSING_OK (1 << 2)
17+
18+
/*
19+
* This behavior of not deleting outside of the sparse-checkout
20+
* is specific to the virtual filesystem support. It is only
21+
* enabled by VFS for Git, and so can be used as an indicator
22+
* that we are in a virtualized filesystem environment and not
23+
* in a Scalar environment. This bit has two names to reflect
24+
* that.
25+
*/
1726
#define GVFS_NO_DELETE_OUTSIDE_SPARSECHECKOUT (1 << 3)
27+
#define GVFS_USE_VIRTUAL_FILESYSTEM (1 << 3)
28+
1829
#define GVFS_FETCH_SKIP_REACHABILITY_AND_UPLOADPACK (1 << 4)
1930
#define GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS (1 << 6)
2031

0 commit comments

Comments
 (0)