Skip to content

Commit 838d6a9

Browse files
dturner-twgitster
authored andcommitted
clean: only lstat files in pathspec
Even though "git clean" takes pathspec to limit the part of the working tree to be cleaned, it checked the paths it encounters during its directory traversal with lstat(2), before checking if the path is within the pathspec. Ignore paths outside pathspec and proceed without checking with lstat(2). Even if such a path is unreadable due to e.g. EPERM, "git clean" should not care. Signed-off-by: David Turner <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 282616c commit 838d6a9

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

builtin/clean.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -940,15 +940,15 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
940940
if (!cache_name_is_other(ent->name, ent->len))
941941
continue;
942942

943-
if (lstat(ent->name, &st))
944-
die_errno("Cannot lstat '%s'", ent->name);
945-
946943
if (pathspec.nr)
947944
matches = dir_path_match(ent, &pathspec, 0, NULL);
948945

949946
if (pathspec.nr && !matches)
950947
continue;
951948

949+
if (lstat(ent->name, &st))
950+
die_errno("Cannot lstat '%s'", ent->name);
951+
952952
if (S_ISDIR(st.st_mode) && !remove_directories &&
953953
matches != MATCHED_EXACTLY)
954954
continue;

0 commit comments

Comments
 (0)