Skip to content

Commit 4c89091

Browse files
committed
Merge pull request #392: add: allow adding sparse entries when virtual
Upstream, a20f704 (add: warn when asked to update SKIP_WORKTREE entries, 04-08-2021) 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. 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. This should allow the VFS for Git functional tests to pass (at least the ones in the default run). I'll create a `-pr` installer build to check before merging this.
2 parents 81961f2 + 8dae5de commit 4c89091

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

builtin/add.c

Lines changed: 11 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 (!core_virtualfilesystem && only_match_skip_worktree.nr) {
212216
advise_on_updating_sparse_paths(&only_match_skip_worktree);
213217
ret = 1;
214218
}
@@ -628,7 +632,12 @@ int cmd_add(int argc, const char **argv, const char *prefix)
628632
if (seen[i])
629633
continue;
630634

631-
if (matches_skip_worktree(&pathspec, i, &skip_worktree_seen)) {
635+
/*
636+
* When using a virtual filesystem, we might re-add a path
637+
* that is currently virtual and we want that to succeed.
638+
*/
639+
if (!core_virtualfilesystem &&
640+
matches_skip_worktree(&pathspec, i, &skip_worktree_seen)) {
632641
string_list_append(&only_match_skip_worktree,
633642
pathspec.items[i].original);
634643
continue;
@@ -651,7 +660,6 @@ int cmd_add(int argc, const char **argv, const char *prefix)
651660
}
652661
}
653662

654-
655663
if (only_match_skip_worktree.nr) {
656664
advise_on_updating_sparse_paths(&only_match_skip_worktree);
657665
exit_status = 1;

builtin/rm.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
298298
ensure_full_index(&the_index);
299299
for (i = 0; i < active_nr; i++) {
300300
const struct cache_entry *ce = active_cache[i];
301-
if (ce_skip_worktree(ce))
301+
if (!core_virtualfilesystem && ce_skip_worktree(ce))
302302
continue;
303303
if (!ce_path_match(&the_index, ce, &pathspec, seen))
304304
continue;
@@ -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 (!core_virtualfilesystem && only_match_skip_worktree.nr) {
336340
advise_on_updating_sparse_paths(&only_match_skip_worktree);
337341
ret = 1;
338342
}

0 commit comments

Comments
 (0)