Skip to content

Commit fed768b

Browse files
derrickstoleedscho
authored andcommitted
Merge pull request #392: add: allow adding sparse entries when 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.
2 parents 81d954e + 1b752b6 commit fed768b

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"
@@ -49,6 +52,7 @@ static int chmod_pathspec(struct repository *repo,
4952
int err;
5053

5154
if (!include_sparse &&
55+
!core_virtualfilesystem &&
5256
(ce_skip_worktree(ce) ||
5357
!path_in_sparse_checkout(ce->name, repo->index)))
5458
continue;
@@ -134,8 +138,9 @@ static int refresh(struct repository *repo, int verbose, const struct pathspec *
134138
if (!seen[i]) {
135139
const char *path = pathspec->items[i].original;
136140

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

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

546-
if (!include_sparse &&
555+
/*
556+
* When using a virtual filesystem, we might re-add a path
557+
* that is currently virtual and we want that to succeed.
558+
*/
559+
if (!include_sparse && !core_virtualfilesystem &&
547560
matches_skip_worktree(&pathspec, i, &skip_worktree_seen)) {
548561
string_list_append(&only_match_skip_worktree,
549562
pathspec.items[i].original);
@@ -567,7 +580,6 @@ int cmd_add(int argc,
567580
}
568581
}
569582

570-
571583
if (only_match_skip_worktree.nr) {
572584
advise_on_updating_sparse_paths(&only_match_skip_worktree);
573585
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
@@ -3954,7 +3954,7 @@ static void update_callback(struct diff_queue_struct *q,
39543954
struct diff_filepair *p = q->queue[i];
39553955
const char *path = p->one->path;
39563956

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

0 commit comments

Comments
 (0)