Skip to content

Commit

Permalink
add/rm: 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,
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>
  • Loading branch information
derrickstolee committed Jun 29, 2021
1 parent 403bcde commit 4fa3036
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
13 changes: 10 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 (only_match_skip_worktree.nr && !core_virtualfilesystem) {
advise_on_updating_sparse_paths(&only_match_skip_worktree);
ret = 1;
}
Expand Down Expand Up @@ -652,8 +656,11 @@ int cmd_add(int argc, const char **argv, const char *prefix)
}
}


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 (only_match_skip_worktree.nr && !core_virtualfilesystem) {
advise_on_updating_sparse_paths(&only_match_skip_worktree);
exit_status = 1;
}
Expand Down
6 changes: 5 additions & 1 deletion builtin/rm.c
Original file line number Diff line number Diff line change
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 (only_match_skip_worktree.nr && !core_virtualfilesystem) {
advise_on_updating_sparse_paths(&only_match_skip_worktree);
ret = 1;
}
Expand Down

0 comments on commit 4fa3036

Please sign in to comment.