Skip to content

Commit cae2f8c

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 <[email protected]>
1 parent fa3e997 commit cae2f8c

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 "lockfile.h"
@@ -47,6 +50,7 @@ static int chmod_pathspec(struct repository *repo,
4750
int err;
4851

4952
if (!include_sparse &&
53+
!core_virtualfilesystem &&
5054
(ce_skip_worktree(ce) ||
5155
!path_in_sparse_checkout(ce->name, repo->index)))
5256
continue;
@@ -132,8 +136,9 @@ static int refresh(struct repository *repo, int verbose, const struct pathspec *
132136
if (!seen[i]) {
133137
const char *path = pathspec->items[i].original;
134138

135-
if (matches_skip_worktree(pathspec, i, &skip_worktree_seen) ||
136-
!path_in_sparse_checkout(path, repo->index)) {
139+
if (!core_virtualfilesystem &&
140+
(matches_skip_worktree(pathspec, i, &skip_worktree_seen) ||
141+
!path_in_sparse_checkout(path, repo->index))) {
137142
string_list_append(&only_match_skip_worktree,
138143
pathspec->items[i].original);
139144
} else {
@@ -143,7 +148,11 @@ static int refresh(struct repository *repo, int verbose, const struct pathspec *
143148
}
144149
}
145150

146-
if (only_match_skip_worktree.nr) {
151+
/*
152+
* When using a virtual filesystem, we might re-add a path
153+
* that is currently virtual and we want that to succeed.
154+
*/
155+
if (!core_virtualfilesystem && only_match_skip_worktree.nr) {
147156
advise_on_updating_sparse_paths(&only_match_skip_worktree);
148157
ret = 1;
149158
}
@@ -529,7 +538,11 @@ int cmd_add(int argc,
529538
if (seen[i])
530539
continue;
531540

532-
if (!include_sparse &&
541+
/*
542+
* When using a virtual filesystem, we might re-add a path
543+
* that is currently virtual and we want that to succeed.
544+
*/
545+
if (!include_sparse && !core_virtualfilesystem &&
533546
matches_skip_worktree(&pathspec, i, &skip_worktree_seen)) {
534547
string_list_append(&only_match_skip_worktree,
535548
pathspec.items[i].original);
@@ -553,7 +566,6 @@ int cmd_add(int argc,
553566
}
554567
}
555568

556-
557569
if (only_match_skip_worktree.nr) {
558570
advise_on_updating_sparse_paths(&only_match_skip_worktree);
559571
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 "lockfile.h"
@@ -314,7 +315,7 @@ int cmd_rm(int argc,
314315
for (unsigned int i = 0; i < the_repository->index->cache_nr; i++) {
315316
const struct cache_entry *ce = the_repository->index->cache[i];
316317

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

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

read-cache.c

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

3956-
if (!data->include_sparse &&
3956+
if (!data->include_sparse && !core_virtualfilesystem &&
39573957
!path_in_sparse_checkout(path, data->index))
39583958
continue;
39593959

0 commit comments

Comments
 (0)