Skip to content

Commit 4fa3036

Browse files
committed
add/rm: allow adding sparse entries when virtual
Upstream, a20f704 (add: warn when asked to update SKIP_WORKTREE entries, 2021-04-08) modified how 'git add <pathspec>' works with cache entries marked with the SKIP_WORKTREE bit. The intention is to prevent a user from accidentally adding a path that is outside their sparse-checkout definition but somehow matches an existing index entry. A similar change for 'git rm' happened in d5f4b82 (rm: honor sparse checkout patterns, 2021-04-08). This breaks when using the virtual filesystem in VFS for Git. It is rare, but we could be in a scenario where the user has staged a change and then the file is projected away. If the user re-adds the file, then this warning causes the command to fail with the advise message. Disable this logic when core_virtualfilesystem is enabled. Signed-off-by: Derrick Stolee <[email protected]>
1 parent 403bcde commit 4fa3036

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

builtin/add.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,11 @@ static int refresh(int verbose, const struct pathspec *pathspec)
208208
}
209209
}
210210

211-
if (only_match_skip_worktree.nr) {
211+
/*
212+
* When using a virtual filesystem, we might re-add a path
213+
* that is currently virtual and we want that to succeed.
214+
*/
215+
if (only_match_skip_worktree.nr && !core_virtualfilesystem) {
212216
advise_on_updating_sparse_paths(&only_match_skip_worktree);
213217
ret = 1;
214218
}
@@ -652,8 +656,11 @@ int cmd_add(int argc, const char **argv, const char *prefix)
652656
}
653657
}
654658

655-
656-
if (only_match_skip_worktree.nr) {
659+
/*
660+
* When using a virtual filesystem, we might re-add a path
661+
* that is currently virtual and we want that to succeed.
662+
*/
663+
if (only_match_skip_worktree.nr && !core_virtualfilesystem) {
657664
advise_on_updating_sparse_paths(&only_match_skip_worktree);
658665
exit_status = 1;
659666
}

builtin/rm.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,11 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
332332
*original ? original : ".");
333333
}
334334

335-
if (only_match_skip_worktree.nr) {
335+
/*
336+
* When using a virtual filesystem, we might re-add a path
337+
* that is currently virtual and we want that to succeed.
338+
*/
339+
if (only_match_skip_worktree.nr && !core_virtualfilesystem) {
336340
advise_on_updating_sparse_paths(&only_match_skip_worktree);
337341
ret = 1;
338342
}

0 commit comments

Comments
 (0)