Skip to content

Commit a7408cf

Browse files
derrickstoleedscho
authored andcommitted
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 <dstolee@microsoft.com>
1 parent 46727f3 commit a7408cf

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

builtin/add.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only)
4747
int err;
4848

4949
if (!include_sparse &&
50+
!core_virtualfilesystem &&
5051
(ce_skip_worktree(ce) ||
5152
!path_in_sparse_checkout(ce->name, &the_index)))
5253
continue;
@@ -97,7 +98,8 @@ static void update_callback(struct diff_queue_struct *q,
9798
struct diff_filepair *p = q->queue[i];
9899
const char *path = p->one->path;
99100

100-
if (!include_sparse && !path_in_sparse_checkout(path, &the_index))
101+
if (!include_sparse && !core_virtualfilesystem &&
102+
!path_in_sparse_checkout(path, &the_index))
101103
continue;
102104

103105
switch (fix_unmerged_status(p, data)) {
@@ -215,8 +217,9 @@ static int refresh(int verbose, const struct pathspec *pathspec)
215217
if (!seen[i]) {
216218
const char *path = pathspec->items[i].original;
217219

218-
if (matches_skip_worktree(pathspec, i, &skip_worktree_seen) ||
219-
!path_in_sparse_checkout(path, &the_index)) {
220+
if (!core_virtualfilesystem &&
221+
(matches_skip_worktree(pathspec, i, &skip_worktree_seen) ||
222+
!path_in_sparse_checkout(path, &the_index))) {
220223
string_list_append(&only_match_skip_worktree,
221224
pathspec->items[i].original);
222225
} else {
@@ -226,7 +229,11 @@ static int refresh(int verbose, const struct pathspec *pathspec)
226229
}
227230
}
228231

229-
if (only_match_skip_worktree.nr) {
232+
/*
233+
* When using a virtual filesystem, we might re-add a path
234+
* that is currently virtual and we want that to succeed.
235+
*/
236+
if (!core_virtualfilesystem && only_match_skip_worktree.nr) {
230237
advise_on_updating_sparse_paths(&only_match_skip_worktree);
231238
ret = 1;
232239
}
@@ -644,7 +651,11 @@ int cmd_add(int argc, const char **argv, const char *prefix)
644651
if (seen[i])
645652
continue;
646653

647-
if (!include_sparse &&
654+
/*
655+
* When using a virtual filesystem, we might re-add a path
656+
* that is currently virtual and we want that to succeed.
657+
*/
658+
if (!include_sparse && !core_virtualfilesystem &&
648659
matches_skip_worktree(&pathspec, i, &skip_worktree_seen)) {
649660
string_list_append(&only_match_skip_worktree,
650661
pathspec.items[i].original);
@@ -668,7 +679,6 @@ int cmd_add(int argc, const char **argv, const char *prefix)
668679
}
669680
}
670681

671-
672682
if (only_match_skip_worktree.nr) {
673683
advise_on_updating_sparse_paths(&only_match_skip_worktree);
674684
exit_status = 1;

builtin/rm.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
304304
for (i = 0; i < active_nr; i++) {
305305
const struct cache_entry *ce = active_cache[i];
306306

307-
if (!include_sparse &&
307+
if (!include_sparse && !core_virtualfilesystem &&
308308
(ce_skip_worktree(ce) ||
309309
!path_in_sparse_checkout(ce->name, &the_index)))
310310
continue;
@@ -341,7 +341,11 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
341341
*original ? original : ".");
342342
}
343343

344-
if (only_match_skip_worktree.nr) {
344+
/*
345+
* When using a virtual filesystem, we might re-add a path
346+
* that is currently virtual and we want that to succeed.
347+
*/
348+
if (!core_virtualfilesystem && only_match_skip_worktree.nr) {
345349
advise_on_updating_sparse_paths(&only_match_skip_worktree);
346350
ret = 1;
347351
}

0 commit comments

Comments
 (0)