Skip to content

Commit 819b108

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 cb94c4f commit 819b108

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
@@ -2,6 +2,7 @@
22
#include "builtin.h"
33
#include "abspath.h"
44
#include "advice.h"
5+
#include "gvfs.h"
56
#include "checkout.h"
67
#include "config.h"
78
#include "copy.h"
@@ -1427,6 +1428,13 @@ int cmd_worktree(int ac,
14271428

14281429
git_config(git_worktree_config, NULL);
14291430

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

git.c

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

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)