Skip to content

Commit 46e9a7a

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 c8a1f6f commit 46e9a7a

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
@@ -298,6 +298,10 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
298298

299299
seen = xcalloc(pathspec.nr, 1);
300300

301+
if (the_index.sparse_index &&
302+
pathspec_needs_expanded_index(&the_index, &pathspec))
303+
ensure_full_index(&the_index);
304+
301305
for (i = 0; i < active_nr; i++) {
302306
const struct cache_entry *ce = active_cache[i];
303307

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)