Skip to content

Commit

Permalink
dir: fix treat_leading_path() to return false on non-directories
Browse files Browse the repository at this point in the history
If treat_leading_path() encounters a non-directory in its loop over each
leading path component, it should return false. This bug was introduced
in commit b9670c1 ("dir: fix checks on common prefix directory",
2019-12-19) where the check for `is_directory(sb.buf)` still breaks out
of the loop but doesn't return false anymore. Instead, the loop is
broken out and the last state result in the loop is used in the return
conditional: `state == path_recurse`.

This prevents the warning "warning: could not open directory" errors
from occurring in `git status` or `git ls-files -o` calls on
non-directory pathspecs. The warning was introduced in commit b673155
("dir.c: stop ignoring opendir() error in open_cached_dir()",
2018-02-02).

Signed-off-by: Ivan Tse <ivan.tse1@gmail.com>
  • Loading branch information
ivantsepp committed May 21, 2024
1 parent 4365c6f commit 06462bb
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -2771,8 +2771,10 @@ static int treat_leading_path(struct dir_struct *dir,
baselen = cp - path;
strbuf_reset(&sb);
strbuf_add(&sb, path, baselen);
if (!is_directory(sb.buf))
if (!is_directory(sb.buf)) {
state = path_none;
break;
}
strbuf_reset(&sb);
strbuf_add(&sb, path, prevlen);
strbuf_reset(&subdir);
Expand Down

0 comments on commit 06462bb

Please sign in to comment.