Skip to content

Commit 5c76cdc

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. Remove the `ensure_full_index()` method so `git-rm` does not always expand the index when the expansion is unnecessary, i.e. when <pathspec> does not have any possibilities to match anything outside of sparse-checkout definition. 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 outside of sparse-checkout definition. Signed-off-by: Shaoxuan Yuan <[email protected]>
1 parent 305343e commit 5c76cdc

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

builtin/rm.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,9 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
296296

297297
seen = xcalloc(pathspec.nr, 1);
298298

299-
/* TODO: audit for interaction with sparse-index. */
300-
ensure_full_index(&the_index);
299+
if (pathspec_needs_expanded_index(&the_index, &pathspec))
300+
ensure_full_index(&the_index);
301+
301302
for (i = 0; i < active_nr; i++) {
302303
const struct cache_entry *ce = active_cache[i];
303304

0 commit comments

Comments
 (0)