Repository navigation
Description
Worktree.Status() reports a file as ignored when its directory matched X/** and a later rule re-includes the file. The pattern matcher gets it right on every version I tested, so this is the walk, not gitignore.
Bisected to 70ab8844 ("worktree: skip ignored directories during Status walk", #2048, 2026-05-04). Its parent 89091499 agrees with git; 70ab8844 does not; main today (8372f31) still does not.
Repro
mkdir -p t/volumes/functions && cd t && git init -q
printf 'volumes/functions/**\n!volumes/functions/deno.json*\n' > .gitignore
touch volumes/functions/deno.jsonsample volumes/functions/otro.txt
git status --porcelain --ignored
# ?? .gitignore
# ?? volumes/
# !! volumes/functions/otro.txt <- only otro.txt is ignoredgit check-ignore -v agrees, rule by rule:
volumes/functions/deno.jsonsample -> .gitignore:2:!volumes/functions/deno.json* (NOT ignored)
volumes/functions/otro.txt -> .gitignore:1:volumes/functions/** (ignored)
Through go-git, opening that worktree and reading Status(), deno.jsonsample is reported as not untracked, i.e. ignored:
| version | deno.jsonsample via Status() |
otro.txt |
|---|---|---|
| git (reference) | not ignored | ignored |
| v5.19.2 | not ignored ✔ | ignored ✔ |
89091499 (parent of the commit) |
not ignored ✔ | ignored ✔ |
70ab8844 |
ignored ✘ | ignored ✔ |
main 8372f31 |
ignored ✘ | ignored ✔ |
gitignore.NewMatcher(ReadPatterns(...)).Match([]string{"volumes","functions","deno.jsonsample"}, false) returns false — correct — on all four, including main. Only the Status() walk disagrees, which is why the pattern tests don't catch it.
Why it happens
The walk prunes a directory when the matcher calls it ignored, and for volumes/functions the matcher says true — because ** happily matches the empty remainder. git check-ignore volumes/functions/ says the same thing (.gitignore:1:volumes/functions/**). But git's own walk does not treat that as a reason to stop descending: X/** excludes the contents of X, and a later !X/keep can still re-include one of them. Asking Match(dir, true) and pruning on the answer conflates "this directory's contents are excluded" with "nothing inside can be re-included".
The commit also fixed the mirror case, so please don't just revert it
Same shape, but with the directory itself excluded (X/ instead of X/**) — here git really does refuse to descend, and the re-inclusion is dead:
printf 'volumes/functions/\n!volumes/functions/deno.json*\n' > .gitignore
git status --porcelain --ignored
# !! volumes/ <- everything below is ignored, the negation cannot reach in| version | deno.jsonsample via Status() |
|---|---|
| git (reference) | ignored |
| v5.19.2 | not ignored ✘ |
89091499 |
not ignored ✘ |
70ab8844, main |
ignored ✔ |
So 70ab8844 traded one wrong family for another: it made X/ correct and X/** wrong. What separates them isn't whether the matcher says the directory is ignored — it says yes to both — but whether the pattern excluded the directory itself or only its contents.
How much it costs
I run a conformance bench that replays 33 real repositories' whole .gitignore trees against git check-ignore as the oracle: 4,463 matcher queries and 2,224 through Status(). main diverges on 1 of 2,224 through Status(), and this is it — the case above is supabase/supabase's docker/.gitignore, verbatim. One query sounds like a corner, so here's the wider count from the same corpus: 5 of the 33 repositories write "ignore everything, keep this" with a negation reaching inside — elasticsearch, grafana, node, next.js, supabase — 14 rule lines between them. My corpus only materialises paths that hit the exact combination once; the construct itself is the one the gitignore docs recommend for the job.
I chased it past the matcher because Status() is the door a consumer actually reaches for: someone using go-git to find out what's untracked never calls ReadPatterns themselves, so a matcher that's right and a walk that isn't still hands them a wrong answer.
Bench, corpus and the go-git adapter, if you want to reproduce any row: https://github.com/KaizenShogun/gitignore-conformance
Activity
KaizenShogun commentedon Sep 15, 2026
A note for whoever writes the fix, because two independent attempts have now landed in the same trap.
#2386 (Go, here) and treeverse/dvc#11096 (Python, different author, different project, for my report of the same bug there) both make
Status()/the matcher stop pruning at a re-included directory — and both break the same four paths in my corpus, fixing one. The shape is one line of.gitignoreaway:!f/deno.json*re-includes the directory, so git descends — and thenf/**ignores what it finds inside. Re-including a directory is permission to look, not a verdict about its contents; both patches turn it into the verdict. The walk has to resume rule evaluation below the re-included directory, which is the part neither patch does.Measured against gitignore-conformance: 8,953 queries for
Match, 6,714 forStatus(),git check-ignore2.55.0 as the oracle.KaizenShogun commentedon Sep 22, 2026
The cause is in
pattern.go, one layer below both doors — so fixing this inworktree/status, where #2386 goes, leaves anyone who callsgitignoredirectly with the same wrong answer.I measured that instead of asserting it. One line,
pattern.go:511:main(8372f31) againstmainplus that line, through all three doors the library exposes. Corpus is 33 repositories' real.gitignoretrees replayed againstgit check-ignore2.55.0. Sets, not counts — a 5 → 8 could be one fix and four breakages, and here it is:maingitignore.Matcher.Matchgitignore.ScopeWorktree.Status()The
Scoperow is the one that locates it.Scopeis already the right door — it is go-git'smay_prune_directory, andworktree_status.gouses it — and it gets 1,009 of 1,010 right. Its single divergence isdocker/volumes/functions/fromsupabase/supabase, the directory in this report, and it goes away with a change inglobMatch. The prune decision is being answered two layers down.I am not asking you to apply that line
Look at the last column. It fixes the file in this report and breaks four paths, all in the same tree:
volumes/functions/deno.jsonsample/keepandvolumes/functions/main/index.ts/keep. Once the walk stops pruning it descends, and underneath sits the other half —!volumes/functions/deno.json*re-includes a directory, and go-git then treats that as a verdict about everything below it instead of resuming rule evaluation there. That is #2112, and it is the family I flagged on this thread on 15 Sep, when #2386 and treeverse/dvc#11096 each fixed one row and broke four of exactly this shape — the repro in that comment is one of the four here. Three independent attempts now, two languages, three different places in the code, the same trade. The missing mechanism is "a re-included directory is permission to look, not a verdict about its contents", and no one-line change anywhere gets there. #2112 has to move first, or at the same time.Your own tests disagree with git, and the test oracle is why
go test ./plumbing/format/gitignore/is green onmainand fails on the patched tree in four rows:TestIgnoreDoubleStarSuffixRequiresSegment(node_modulesandsrc/node_modulesas directories) andTestWildmatchSlashSemantics(**/bar/**vsdeep/foo/bar/,a/**/*/**vsa/b/). All four expect excluded. git does not say that:check-ignore xcheck-ignore x/**/node_modules/**node_modules**/node_modules/**src/node_modulesa/**aa/**/*/**a/b**/bar/**deep/foo/bara/(control)aThe suite ships its own oracle and still passes, because
gitOracleinconformance_test.godoesarg += "/"before callingcheck-ignore -q. A trailing**matches the empty remainder the slash leaves behind, so with the slash git says "excluded" for every one of these and the test agrees with a question nobody asked. Strip the slash and the same helper reproduces the table above. One line of the test helper, and four expectations stop being green by accident.For the record on
3189ee9d(#2279), which wrote line 511: I am not asking for a revert. It fixed the mirror case —**/node_modules/**marking every directory excluded andStatus()losing everything below the root — and my corpus confirms that is still fixed;mainand the patched tree diverge on the same 12 matcher rows.|| isDiris holding up the majority case on its own, which is precisely why it cannot be the prune decision.Corpus, adapters and the exact rows, if you want to reproduce any of this: https://github.com/KaizenShogun/gitignore-conformance