]> git.ipfire.org Git - thirdparty/git.git/commit - dir.c
dir: also check directories for matching pathspecs
authorElijah Newren <newren@gmail.com>
Tue, 17 Sep 2019 16:34:56 +0000 (09:34 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 17 Sep 2019 19:20:35 +0000 (12:20 -0700)
commit404ebceda01c5af68926c3ee78934cd95bda2602
treeea53ce58cd8a643f2e0688d6cbecc74d5987d846
parenta5e916c7453bc022cb86d7f8528952ccda6a81ce
dir: also check directories for matching pathspecs

Even if a directory doesn't match a pathspec, it is possible, depending
on the precise pathspecs, that some file underneath it might.  So we
special case and recurse into the directory for such situations.  However,
we previously always added any untracked directory that we recursed into
to the list of untracked paths, regardless of whether the directory
itself matched the pathspec.

For the case of git-clean and a set of pathspecs of "dir/file" and "more",
this caused a problem because we'd end up with dir entries for both of
  "dir"
  "dir/file"
Then correct_untracked_entries() would try to helpfully prune duplicates
for us by removing "dir/file" since it's under "dir", leaving us with
  "dir"
Since the original pathspec only had "dir/file", the only entry left
doesn't match and leaves nothing to be removed.  (Note that if only one
pathspec was specified, e.g. only "dir/file", then the common_prefix_len
optimizations in fill_directory would cause us to bypass this problem,
making it appear in simple tests that we could correctly remove manually
specified pathspecs.)

Fix this by actually checking whether the directory we are about to add
to the list of dir entries actually matches the pathspec; only do this
matching check after we have already returned from recursing into the
directory.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
dir.c
t/t7300-clean.sh