git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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 */,
Previous: Sean WhittonNext: René Scharfe
Message 2 of 6 in “[BUG] 'git status --ignored' <pathspec> matches partial names”
  1. Sean WhittonSep 14, 2026
  2. René ScharfeSep 15, 2026
  3. dir: skip excluded directory with nested repo on prefix matchRené Scharfe, Sep 18, 2026
  4. Junio C HamanoSep 22, 2026
  5. René ScharfeSep 26, 2026
  6. dir: skip excluded directory with nested repo on prefix matchRené Scharfe, Sep 26, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.