Skip to content

Commit 73b88a1

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 676c07e + 4250d6d commit 73b88a1

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
@@ -8,6 +8,7 @@
88
#define DISABLE_SIGN_COMPARE_WARNINGS
99

1010
#include "builtin.h"
11+
#include "environment.h"
1112
#include "advice.h"
1213
#include "config.h"
1314
#include "lockfile.h"
@@ -317,7 +318,7 @@ int cmd_rm(int argc,
317318
for (i = 0; i < the_repository->index->cache_nr; i++) {
318319
const struct cache_entry *ce = the_repository->index->cache[i];
319320

320-
if (!include_sparse &&
321+
if (!include_sparse && !core_virtualfilesystem &&
321322
(ce_skip_worktree(ce) ||
322323
!path_in_sparse_checkout(ce->name, the_repository->index)))
323324
continue;
@@ -354,7 +355,11 @@ int cmd_rm(int argc,
354355
*original ? original : ".");
355356
}
356357

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

read-cache.c

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

3974-
if (!data->include_sparse &&
3974+
if (!data->include_sparse && !core_virtualfilesystem &&
39753975
!path_in_sparse_checkout(path, data->index))
39763976
continue;
39773977

0 commit comments

Comments
 (0)