Skip to content

Commit e8a204b

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 51ce5a3 commit e8a204b

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

builtin/add.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
/*
24
* "git add" builtin command
35
*
46
* Copyright (C) 2006 Linus Torvalds
57
*/
68

79
#include "builtin.h"
10+
#include "environment.h"
811
#include "advice.h"
912
#include "config.h"
1013
#include "environment.h"
@@ -50,6 +53,7 @@ static int chmod_pathspec(struct repository *repo,
5053
int err;
5154

5255
if (!include_sparse &&
56+
!core_virtualfilesystem &&
5357
(ce_skip_worktree(ce) ||
5458
!path_in_sparse_checkout(ce->name, repo->index)))
5559
continue;
@@ -135,8 +139,9 @@ static int refresh(struct repository *repo, int verbose, const struct pathspec *
135139
if (!seen[i]) {
136140
const char *path = pathspec->items[i].original;
137141

138-
if (matches_skip_worktree(pathspec, i, &skip_worktree_seen) ||
139-
!path_in_sparse_checkout(path, repo->index)) {
142+
if (!core_virtualfilesystem &&
143+
(matches_skip_worktree(pathspec, i, &skip_worktree_seen) ||
144+
!path_in_sparse_checkout(path, repo->index))) {
140145
string_list_append(&only_match_skip_worktree,
141146
pathspec->items[i].original);
142147
} else {
@@ -146,7 +151,11 @@ static int refresh(struct repository *repo, int verbose, const struct pathspec *
146151
}
147152
}
148153

149-
if (only_match_skip_worktree.nr) {
154+
/*
155+
* When using a virtual filesystem, we might re-add a path
156+
* that is currently virtual and we want that to succeed.
157+
*/
158+
if (!core_virtualfilesystem && only_match_skip_worktree.nr) {
150159
advise_on_updating_sparse_paths(&only_match_skip_worktree);
151160
ret = 1;
152161
}
@@ -545,7 +554,11 @@ int cmd_add(int argc,
545554
if (seen[i])
546555
continue;
547556

548-
if (!include_sparse &&
557+
/*
558+
* When using a virtual filesystem, we might re-add a path
559+
* that is currently virtual and we want that to succeed.
560+
*/
561+
if (!include_sparse && !core_virtualfilesystem &&
549562
matches_skip_worktree(&pathspec, i, &skip_worktree_seen)) {
550563
string_list_append(&only_match_skip_worktree,
551564
pathspec.items[i].original);
@@ -569,7 +582,6 @@ int cmd_add(int argc,
569582
}
570583
}
571584

572-
573585
if (only_match_skip_worktree.nr) {
574586
advise_on_updating_sparse_paths(&only_match_skip_worktree);
575587
exit_status = 1;

builtin/rm.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#define USE_THE_REPOSITORY_VARIABLE
88

99
#include "builtin.h"
10+
#include "environment.h"
1011
#include "advice.h"
1112
#include "config.h"
1213
#include "environment.h"
@@ -315,7 +316,7 @@ int cmd_rm(int argc,
315316
for (unsigned int i = 0; i < the_repository->index->cache_nr; i++) {
316317
const struct cache_entry *ce = the_repository->index->cache[i];
317318

318-
if (!include_sparse &&
319+
if (!include_sparse && !core_virtualfilesystem &&
319320
(ce_skip_worktree(ce) ||
320321
!path_in_sparse_checkout(ce->name, the_repository->index)))
321322
continue;
@@ -352,7 +353,11 @@ int cmd_rm(int argc,
352353
*original ? original : ".");
353354
}
354355

355-
if (only_match_skip_worktree.nr) {
356+
/*
357+
* When using a virtual filesystem, we might re-add a path
358+
* that is currently virtual and we want that to succeed.
359+
*/
360+
if (!core_virtualfilesystem && only_match_skip_worktree.nr) {
356361
advise_on_updating_sparse_paths(&only_match_skip_worktree);
357362
ret = 1;
358363
}

read-cache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3955,7 +3955,7 @@ static void update_callback(struct diff_queue_struct *q,
39553955
struct diff_filepair *p = q->queue[i];
39563956
const char *path = p->one->path;
39573957

3958-
if (!data->include_sparse &&
3958+
if (!data->include_sparse && !core_virtualfilesystem &&
39593959
!path_in_sparse_checkout(path, data->index))
39603960
continue;
39613961

0 commit comments

Comments
 (0)