Skip to content

Commit 9b3c78b

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 7be559f + de88116 commit 9b3c78b

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
@@ -48,6 +48,7 @@ static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only)
4848
int err;
4949

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

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

104106
switch (fix_unmerged_status(p, data)) {
@@ -207,8 +209,9 @@ static int refresh(int verbose, const struct pathspec *pathspec)
207209
if (!seen[i]) {
208210
const char *path = pathspec->items[i].original;
209211

210-
if (matches_skip_worktree(pathspec, i, &skip_worktree_seen) ||
211-
!path_in_sparse_checkout(path, &the_index)) {
212+
if (!core_virtualfilesystem &&
213+
(matches_skip_worktree(pathspec, i, &skip_worktree_seen) ||
214+
!path_in_sparse_checkout(path, &the_index))) {
212215
string_list_append(&only_match_skip_worktree,
213216
pathspec->items[i].original);
214217
} else {
@@ -218,7 +221,11 @@ static int refresh(int verbose, const struct pathspec *pathspec)
218221
}
219222
}
220223

221-
if (only_match_skip_worktree.nr) {
224+
/*
225+
* When using a virtual filesystem, we might re-add a path
226+
* that is currently virtual and we want that to succeed.
227+
*/
228+
if (!core_virtualfilesystem && only_match_skip_worktree.nr) {
222229
advise_on_updating_sparse_paths(&only_match_skip_worktree);
223230
ret = 1;
224231
}
@@ -656,7 +663,11 @@ int cmd_add(int argc, const char **argv, const char *prefix)
656663
if (seen[i])
657664
continue;
658665

659-
if (!include_sparse &&
666+
/*
667+
* When using a virtual filesystem, we might re-add a path
668+
* that is currently virtual and we want that to succeed.
669+
*/
670+
if (!include_sparse && !core_virtualfilesystem &&
660671
matches_skip_worktree(&pathspec, i, &skip_worktree_seen)) {
661672
string_list_append(&only_match_skip_worktree,
662673
pathspec.items[i].original);
@@ -680,7 +691,6 @@ int cmd_add(int argc, const char **argv, const char *prefix)
680691
}
681692
}
682693

683-
684694
if (only_match_skip_worktree.nr) {
685695
advise_on_updating_sparse_paths(&only_match_skip_worktree);
686696
exit_status = 1;

builtin/rm.c

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

304-
if (!include_sparse &&
304+
if (!include_sparse && !core_virtualfilesystem &&
305305
(ce_skip_worktree(ce) ||
306306
!path_in_sparse_checkout(ce->name, &the_index)))
307307
continue;
@@ -338,7 +338,11 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
338338
*original ? original : ".");
339339
}
340340

341-
if (only_match_skip_worktree.nr) {
341+
/*
342+
* When using a virtual filesystem, we might re-add a path
343+
* that is currently virtual and we want that to succeed.
344+
*/
345+
if (!core_virtualfilesystem && only_match_skip_worktree.nr) {
342346
advise_on_updating_sparse_paths(&only_match_skip_worktree);
343347
ret = 1;
344348
}

0 commit comments

Comments
 (0)