Skip to content

Commit

Permalink
Merge pull request #392: add: allow adding sparse entries when virtual
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
derrickstolee authored and dscho committed Oct 30, 2021
2 parents 83be6be + 4140d37 commit 843847a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
14 changes: 11 additions & 3 deletions builtin/add.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,11 @@ static int refresh(int verbose, const struct pathspec *pathspec)
}
}

if (only_match_skip_worktree.nr) {
/*
* When using a virtual filesystem, we might re-add a path
* that is currently virtual and we want that to succeed.
*/
if (!core_virtualfilesystem && only_match_skip_worktree.nr) {
advise_on_updating_sparse_paths(&only_match_skip_worktree);
ret = 1;
}
Expand Down Expand Up @@ -628,7 +632,12 @@ int cmd_add(int argc, const char **argv, const char *prefix)
if (seen[i])
continue;

if (matches_skip_worktree(&pathspec, i, &skip_worktree_seen)) {
/*
* When using a virtual filesystem, we might re-add a path
* that is currently virtual and we want that to succeed.
*/
if (!core_virtualfilesystem &&
matches_skip_worktree(&pathspec, i, &skip_worktree_seen)) {
string_list_append(&only_match_skip_worktree,
pathspec.items[i].original);
continue;
Expand All @@ -651,7 +660,6 @@ int cmd_add(int argc, const char **argv, const char *prefix)
}
}


if (only_match_skip_worktree.nr) {
advise_on_updating_sparse_paths(&only_match_skip_worktree);
exit_status = 1;
Expand Down
8 changes: 6 additions & 2 deletions builtin/rm.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
ensure_full_index(&the_index);
for (i = 0; i < active_nr; i++) {
const struct cache_entry *ce = active_cache[i];
if (ce_skip_worktree(ce))
if (!core_virtualfilesystem && ce_skip_worktree(ce))
continue;
if (!ce_path_match(&the_index, ce, &pathspec, seen))
continue;
Expand Down Expand Up @@ -332,7 +332,11 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
*original ? original : ".");
}

if (only_match_skip_worktree.nr) {
/*
* When using a virtual filesystem, we might re-add a path
* that is currently virtual and we want that to succeed.
*/
if (!core_virtualfilesystem && only_match_skip_worktree.nr) {
advise_on_updating_sparse_paths(&only_match_skip_worktree);
ret = 1;
}
Expand Down

0 comments on commit 843847a

Please sign in to comment.