Skip to content

Commit 34ce49a

Browse files
derrickstoleemjcheetham
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 bd130cb + 09edaa7 commit 34ce49a

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

builtin/add.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
#include "builtin.h"
8+
#include "environment.h"
89
#include "advice.h"
910
#include "config.h"
1011
#include "lockfile.h"
@@ -45,6 +46,7 @@ static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only)
4546
int err;
4647

4748
if (!include_sparse &&
49+
!core_virtualfilesystem &&
4850
(ce_skip_worktree(ce) ||
4951
!path_in_sparse_checkout(ce->name, the_repository->index)))
5052
continue;
@@ -125,8 +127,9 @@ static int refresh(int verbose, const struct pathspec *pathspec)
125127
if (!seen[i]) {
126128
const char *path = pathspec->items[i].original;
127129

128-
if (matches_skip_worktree(pathspec, i, &skip_worktree_seen) ||
129-
!path_in_sparse_checkout(path, the_repository->index)) {
130+
if (!core_virtualfilesystem &&
131+
(matches_skip_worktree(pathspec, i, &skip_worktree_seen) ||
132+
!path_in_sparse_checkout(path, the_repository->index))) {
130133
string_list_append(&only_match_skip_worktree,
131134
pathspec->items[i].original);
132135
} else {
@@ -136,7 +139,11 @@ static int refresh(int verbose, const struct pathspec *pathspec)
136139
}
137140
}
138141

139-
if (only_match_skip_worktree.nr) {
142+
/*
143+
* When using a virtual filesystem, we might re-add a path
144+
* that is currently virtual and we want that to succeed.
145+
*/
146+
if (!core_virtualfilesystem && only_match_skip_worktree.nr) {
140147
advise_on_updating_sparse_paths(&only_match_skip_worktree);
141148
ret = 1;
142149
}
@@ -512,7 +519,11 @@ int cmd_add(int argc, const char **argv, const char *prefix)
512519
if (seen[i])
513520
continue;
514521

515-
if (!include_sparse &&
522+
/*
523+
* When using a virtual filesystem, we might re-add a path
524+
* that is currently virtual and we want that to succeed.
525+
*/
526+
if (!include_sparse && !core_virtualfilesystem &&
516527
matches_skip_worktree(&pathspec, i, &skip_worktree_seen)) {
517528
string_list_append(&only_match_skip_worktree,
518529
pathspec.items[i].original);
@@ -536,7 +547,6 @@ int cmd_add(int argc, const char **argv, const char *prefix)
536547
}
537548
}
538549

539-
540550
if (only_match_skip_worktree.nr) {
541551
advise_on_updating_sparse_paths(&only_match_skip_worktree);
542552
exit_status = 1;

builtin/rm.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
#include "builtin.h"
8+
#include "environment.h"
89
#include "advice.h"
910
#include "config.h"
1011
#include "lockfile.h"
@@ -311,7 +312,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
311312
for (i = 0; i < the_repository->index->cache_nr; i++) {
312313
const struct cache_entry *ce = the_repository->index->cache[i];
313314

314-
if (!include_sparse &&
315+
if (!include_sparse && !core_virtualfilesystem &&
315316
(ce_skip_worktree(ce) ||
316317
!path_in_sparse_checkout(ce->name, the_repository->index)))
317318
continue;
@@ -348,7 +349,11 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
348349
*original ? original : ".");
349350
}
350351

351-
if (only_match_skip_worktree.nr) {
352+
/*
353+
* When using a virtual filesystem, we might re-add a path
354+
* that is currently virtual and we want that to succeed.
355+
*/
356+
if (!core_virtualfilesystem && only_match_skip_worktree.nr) {
352357
advise_on_updating_sparse_paths(&only_match_skip_worktree);
353358
ret = 1;
354359
}

read-cache.c

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

3943-
if (!data->include_sparse &&
3943+
if (!data->include_sparse && !core_virtualfilesystem &&
39443944
!path_in_sparse_checkout(path, data->index))
39453945
continue;
39463946

0 commit comments

Comments
 (0)