Skip to content

Commit

Permalink
Merge pull request microsoft#392: add: allow adding sparse entries wh…
Browse files Browse the repository at this point in the history
…en 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.
  • Loading branch information
derrickstolee authored and ldennington committed Jan 20, 2022
2 parents 3e36189 + 1bda877 commit 67cd86c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
22 changes: 16 additions & 6 deletions builtin/add.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only)
int err;

if (!include_sparse &&
!core_virtualfilesystem &&
(ce_skip_worktree(ce) ||
!path_in_sparse_checkout(ce->name, &the_index)))
continue;
Expand Down Expand Up @@ -98,7 +99,8 @@ static void update_callback(struct diff_queue_struct *q,
struct diff_filepair *p = q->queue[i];
const char *path = p->one->path;

if (!include_sparse && !path_in_sparse_checkout(path, &the_index))
if (!include_sparse && !core_virtualfilesystem &&
!path_in_sparse_checkout(path, &the_index))
continue;

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

if (matches_skip_worktree(pathspec, i, &skip_worktree_seen) ||
!path_in_sparse_checkout(path, &the_index)) {
if (!core_virtualfilesystem &&
(matches_skip_worktree(pathspec, i, &skip_worktree_seen) ||
!path_in_sparse_checkout(path, &the_index))) {
string_list_append(&only_match_skip_worktree,
pathspec->items[i].original);
} else {
Expand All @@ -218,7 +221,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 @@ -653,7 +660,11 @@ int cmd_add(int argc, const char **argv, const char *prefix)
if (seen[i])
continue;

if (!include_sparse &&
/*
* When using a virtual filesystem, we might re-add a path
* that is currently virtual and we want that to succeed.
*/
if (!include_sparse && !core_virtualfilesystem &&
matches_skip_worktree(&pathspec, i, &skip_worktree_seen)) {
string_list_append(&only_match_skip_worktree,
pathspec.items[i].original);
Expand All @@ -677,7 +688,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 @@ -301,7 +301,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
for (i = 0; i < active_nr; i++) {
const struct cache_entry *ce = active_cache[i];

if (!include_sparse &&
if (!include_sparse && !core_virtualfilesystem &&
(ce_skip_worktree(ce) ||
!path_in_sparse_checkout(ce->name, &the_index)))
continue;
Expand Down Expand Up @@ -338,7 +338,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 67cd86c

Please sign in to comment.