Skip to content

Commit

Permalink
clean: only lstat files in pathspec
Browse files Browse the repository at this point in the history
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 <dturner@twopensource.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
David Turner authored and Junio C Hamano committed May 18, 2015
1 parent 282616c commit 838d6a9
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions builtin/clean.c
Original file line number Diff line number Diff line change
Expand Up @@ -940,15 +940,15 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
if (!cache_name_is_other(ent->name, ent->len))
continue;

if (lstat(ent->name, &st))
die_errno("Cannot lstat '%s'", ent->name);

if (pathspec.nr)
matches = dir_path_match(ent, &pathspec, 0, NULL);

if (pathspec.nr && !matches)
continue;

if (lstat(ent->name, &st))
die_errno("Cannot lstat '%s'", ent->name);

if (S_ISDIR(st.st_mode) && !remove_directories &&
matches != MATCHED_EXACTLY)
continue;
Expand Down

0 comments on commit 838d6a9

Please sign in to comment.