Re: [BUG] 'git status --ignored' <pathspec> matches partial names
- From
René Scharfe <l.s.r@web.de>
- Date
- Sep 15, 2026, 15:54 UTC
- Message-ID
- <ff9404bc-63e1-43bc-8419-9685f0bfa32d@web.de>
- In-Reply-To
- <87ld94klhf.fsf@athena.silentflame.com>
On 9/14/26 3:31 PM, Sean Whitton wrote:
Show 19 quoted lines
> Steps to reproduce: > > git init foo > cd foo > mkdir bar > echo bar/ >.gitignore > git init bar/baz > git init bar/quux > git status --porcelain --ignored --untracked-files -- ba > > Expected output: > none, "ba" doesn't match "bar". > > Actual output: > !! bar/baz/ > !! bar/quux/ > > Credits to Lester Longley for the reproduction, in Emacs bug#81625. >
Bisects to 95c11ecc73 (Fix error-prone fill_directory() API; make it only return matches, 2020-04-01).
I can reproduce the issue using the instructions above, but not in Git's own repo like this:
$ git status --porcelain --ignored --untracked-files -- .depend | grep -c '^!!' 266 $ git status --porcelain --ignored --untracked-files -- .depen | grep -c '^!!' 0
Below is a quick fix, but perhaps this optimization can be repaired instead of removed.
René
diff --git a/dir.c b/dir.c index 95d8a1cce9..3718301a89 100644 --- a/dir.c +++ b/dir.c @@ -1991,11 +1991,9 @@ static enum path_treatment treat_directory(struct dir_struct *dir, /* * We don't want to descend into paths that don't match the necessary * patterns. Clearly, if we don't have a pathspec, then we can't check - * for matching patterns. Also, if (excluded) then we know we matched - * the exclusion patterns so as an optimization we can skip checking * for matching patterns. */ - if (pathspec && !excluded) { + if (pathspec) { matches_how = match_pathspec_with_flags(istate, pathspec, dirname, len, 0 /* prefix */,