Skip to content

Commit dfc585f

Browse files
committed
rm: expand the index only when necessary
Originally, rm a pathspec that is out-of-cone in a sparse-index environment, Git dies with "pathspec '<x>' did not match any files", mainly because it does not expand the index so nothing is matched. Expand the index when the pathspec needs an expanded index, i.e. the pathspec contains wildcard that may need a full-index or the pathspec is simply out-of-cone. Signed-off-by: Shaoxuan Yuan <[email protected]>
1 parent a4be140 commit dfc585f

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

builtin/rm.c

+4
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
300300

301301
seen = xcalloc(pathspec.nr, 1);
302302

303+
if (the_index.sparse_index &&
304+
pathspec_needs_expanded_index(&the_index, &pathspec))
305+
ensure_full_index(&the_index);
306+
303307
for (i = 0; i < active_nr; i++) {
304308
const struct cache_entry *ce = active_cache[i];
305309

t/t1092-sparse-checkout-compatibility.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1873,7 +1873,7 @@ test_expect_success 'rm pathspec inside sparse definition' '
18731873
test_all_match git status --porcelain=v2
18741874
'
18751875

1876-
test_expect_failure 'rm pathspec outside sparse definition' '
1876+
test_expect_success 'rm pathspec outside sparse definition' '
18771877
init_repos &&
18781878
18791879
for file in folder1/a folder1/0/1 folder1/0/0/0

0 commit comments

Comments
 (0)