You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bug: gitignore behavior mismatch to the git in specific scenarios #877
import (
"testing""github.com/go-git/go-billy/v5/osfs""github.com/go-git/go-git/v5/plumbing/format/gitignore""github.com/stretchr/testify/assert"
)
funcTestGitIgnore(t*testing.T) {
fs:=osfs.New("/tmp/ignore-check")
ps, err:=gitignore.ReadPatterns(fs, nil)
assert.NoError(t, err)
assert.Equal(t, 2, len(ps))
matcher:=gitignore.NewMatcher(ps)
assert.True(t, matcher.Match([]string{"abc"}, true), "abc should be ignored")
assert.True(t, matcher.Match([]string{"abc/def"}, true), "abc/def should be ignored") # thistestfailedassert.False(t, matcher.Match([]string{"abc/ghi"}, true), "abc/ghi should not be ignored")
assert.False(t, matcher.Match([]string{"def"}, true), "def (root) should not be ignored")
}
changed the title [-]bug: gitignore may be mismatched to the git behavior in specific scenarios[/-][+]bug: gitignore behavior mismatch to the git in specific scenarios[/+]on Oct 13, 2023
To help us keep things tidy and focus on the active tasks, we've introduced a stale bot to spot issues/PRs that haven't had any activity in a while.
This particular issue hasn't had any updates or activity in the past 90 days, so it's been labeled as 'stale'. If it remains inactive for the next 30 days, it'll be automatically closed.
We understand everyone's busy, but if this issue is still important to you, please feel free to add a comment or make an update to keep it active.
@AriehSchneier your March question — fix go-git's matcher, or delegate to git-pkgs/gitignore — is
measurable, so here are numbers rather than an opinion.
The control is your own 6aa9efc, the parent of the delegating commit, so the comparison isolates
the engine swap instead of five months of drift.
build
Matcher.Match (4,463)
Status() (2,224)
main (tarball taken 2026-09-09)
2
1
your 6aa9efc — own matcher
4
1
your 3edf6ec — delegating, git-pkgs/gitignore v1.1.1
5
4
the same, with both library bugs patched
2
1
Compared as sets, not counts. Delegating as it stands trades two failures for three: it fixes
grafana's testdata/**output/, and it breaks deps/ (a file named after the directory that
excluded it) in three places, which is also the whole of the Status() regression. Those three are git-pkgs/gitignore#22. There is a second one I filed today, git-pkgs/gitignore#23: a dir-only
pattern with a wildcard, *.egg-info/, matches the directory but nothing inside it — that one the
bench never asked about, and it hits 9 real rule lines across 8 of those repos.
With both patched, delegating lands exactly where main already is: 2 and 1.
The part that matters for this issue. The repro in the opening comment — root abc, nested abc/.gitignore with !def — passes on all four builds. It doesn't reproduce any more, whichever
engine you pick. What does still fail on all four is the sibling shape from #694, both patterns in
one file:
test/
!test/keep
git keeps test/keep ignored (once a directory is excluded it never looks inside again), and all
four builds re-include it. It is also the last thing standing in both columns above — the two
remaining divergences are .vscode + !.vscode/extensions.json from ollama, the same shape. So
the engine choice is orthogonal to it: neither library gets it right today.
A correction to my own comment above, with the numbers that force it.
I measured those four builds on a corpus that never asked what was inside a directory. Adding that
one variant took it from 4,463 questions to 8,953, and it moves every row here — including the
conclusion I stated, that delegating "lands exactly where main already is".
Same setup as before: git 2.55.0 as the oracle, one Go helper built once per tree, nothing else
changing between rows.
(Status() answers 6,714 of the 8,953; it declines directories, so I don't make a row up for them.)
Row three is the one I reported in March terms, and on the bigger corpus it reads 24 against main's
12 — the tie was an artefact of the questions, not a property of the engines. But that row's library
is v1.1.1 plus one patch, and it has gone stale: git-pkgs/gitignore#22 and #24 are both merged now,
and the library measured on its own sits at 12 over the same questions. That's the last row, and
it's the only one that answers the question as it stands in 2026.
Delegating to HEAD scores 12 under Matcher.Match — and compared as sets, not counts, they are the same twelve main already fails. Nothing fixed, nothing broken. A real tie this time.
Status() is where delegating still costs something: 11 against 5, one case bought and seven lost.
All seven are contents of a directory whose name reads like a file — .vscode/extensions.json/… in
ollama, docker/volumes/functions/main/index.ts/… in supabase. Which of the two open library issues
they trace to (git-pkgs/gitignore#25 or #26) I haven't pinned down; I'm reporting the number, not the
cause.
So at the matcher the engine choice is a wash today, and whatever decides it isn't conformance. The Status() gap is the part worth watching, and it lives upstream rather than here.
Closing the loose end from my comment this morning: I said delegating costs 7 cases in Status() and that I had not attributed them. Now I have, and the attribution changes what the 7 mean.
Same delegating build, only the library tree swapped — twice, to two patched copies of git-pkgs/gitignore HEAD:
library under the delegator
Status() divergences
of the 7
HEAD as shipped
11
—
HEAD, no implicit ** on negations
67
fixes 6, leaves 1
HEAD, no implicit ** at all (the ceiling)
1818
fixes 4, leaves 3
So six of the seven are git-pkgs/gitignore#26 — a negation inherits the implicit ** that appendTrailingDoubleStar appends, so !volumes/functions/main/index.ts re-includes everything under that path too. The seventh is a different bug, #25: app/ui/app/.vscode/extensions.json, where .vscode is excluded and git refuses to let !.vscode/extensions.json bring it back. Both are open with repros.
Two things worth flagging, since neither is what I expected:
The ceiling row is not a superset of the patch row. Dropping the implicit ** everywhere fixes four of the seven but leaves the two ollama ones that the negation-only patch fixes — because once exclusions lose their **, .vscode stops covering its own contents and those paths diverge again for a new reason. The mechanism is load-bearing for exclusions; it is only wrong on negations.
And the negation-only patch costs 66 new breakages in Status() on this corpus (67 total against 11). It is the right diagnosis and the wrong patch — the library uses that same implicit ** to emulate the walk down ancestors it does not have, so removing it from negations takes the walk away with it. I said as much in #26; this is the same result seen through go-git.
None of this moves the matcher numbers from this morning: delegating and main still return the same 12. The 7 are Status()-only, and they have two ticket numbers rather than an unknown cause.
A correction to my own comment of 11 Sep in this thread. I said delegating to git-pkgs/gitignore cost 7 cases in Status(), and traced most of them to two bugs I'd reported in that library. Those bugs are fixed and tagged (v1.3.0, today). The cost is no longer 7, and not in the direction I'd have guessed: rebuilt on the fixed library, the delegating branch gets worse.
Same corpus and oracle as before — 8,953 nested-.gitignore queries over 43 repos, git check-ignore --no-index, git 2.55.0 — one Go helper built three times, only the trees under it changing. The branch pins v1.1.1; in both delegating rows I swap the library tree and change nothing else. main and the older delegating build were re-measured today as controls, and both reproduce their old numbers with the same rows:
build
Matcher.Match
Status()
go-git main, own matcher
12 / 8,953
5 / 6,714
3edf6ec delegating, library at the commit before the fix (#22 and #24 in)
12
11
the same 3edf6ec, library swapped for v1.3.0
84
81
git-pkgs/gitignore v1.3.0 on its own, used as a whole-tree matcher
0
—
The 82 new ones in the first column all point the same way — git says not ignored, go-git says ignored — across 10 repos and 14 pattern shapes. That's the direction that hides files from Status().
It isn't the library. Two rules, with settings.json an actual directory:
.gitignore: .vscode/*
!.vscode/settings.json
git check-ignore --no-index says .vscode/settings.json/keep.txt is not ignored, and .vscode/other.json is. ReadPatterns + NewMatcher(ps).Match([]string{".vscode", "settings.json", "keep.txt"}, false) returns false on 3edf6ec as branched and true on 3edf6ec + v1.3.0. The library asked directly — NewFromDirectory + MatchPath — agrees with git.
The mechanism is in the bridge, pattern.go: pattern.Match builds a fresh extgitignore matcher per pattern per query and feeds it a single line. Since v1.3.0 that matcher walks the parent directories of the path it is handed, so .vscode/* on its own now answers "ignored" for anything under .vscode/settings.json; the negation, alone in its own matcher, no longer matches that descendant at all, because the implicit trailing ** that used to make it cascade was removed in the same release. go-git's Matcher is then choosing between one Exclude and nothing. Before v1.3.0 the implicit ** made the negation cascade too, and the two errors cancelled.
So what's worth delegating is the library's whole-tree Matcher, which owns the parent walk and last-match-wins across every rule file; a per-pattern bridge delegates the pattern and keeps the matching, and that is where the 84 come from. main looks to be going its own way — Scope in 9a978dd is the same fix made in-house — so this may well be moot. I'm posting it because the numbers I left in this thread say otherwise, and anyone rebuilding that branch today lands on the wrong side of them.
One number in my comment this morning is wrong, and it's the one describing the bench rather than any result: the 8,953 queries come from 33 repositories, not 43. 43 is the level-1 corpus in the same repo — one root .gitignore each, 9,852 queries — and I pasted its census onto a level-2 number. My earlier comments in this thread say 33, which is the right one.
Nothing else changes: main 12, the branch as pinned 12, the branch on v1.3.0 84, and the two-rule repro at the end stands on its own without the corpus.
Activity
[-]bug: gitignore may be mismatched to the git behavior in specific scenarios[/-][+]bug: gitignore behavior mismatch to the git in specific scenarios[/+]j4k4 commentedon Dec 27, 2023
I'm having the same issue, which is quite annoying to deal with.
I've created a sample repository which helps to reproduce the issue, too: https://github.com/j4k4/go-git-status-bug
Looks like it has to do something with the domain, as dropping the following line makes it behave correctly again:
github-actions commentedon Dec 20, 2024
To help us keep things tidy and focus on the active tasks, we've introduced a stale bot to spot issues/PRs that haven't had any activity in a while.
This particular issue hasn't had any updates or activity in the past 90 days, so it's been labeled as 'stale'. If it remains inactive for the next 30 days, it'll be automatically closed.
We understand everyone's busy, but if this issue is still important to you, please feel free to add a comment or make an update to keep it active.
Thanks for your understanding and cooperation!
pjbgf commentedon Mar 24, 2026
Stumbled into this blog post that covers this in further detail: https://nesbitt.io/2026/02/12/the-many-flavors-of-ignore-files.html
plumbing: gitignore, Pass parent patterns to recursive ReadPatterns c…
AriehSchneier commentedon Mar 26, 2026
A test suite and details of where we are currently lacking:
AriehSchneier@6aa9efc
AriehSchneier commentedon Mar 30, 2026
@pjbgf Do we want to update our implementation, or do we want to use https://github.com/git-pkgs/gitignore?
If we want to use https://github.com/git-pkgs/gitignore I have a branch that appears to work and match gits implementation (required us to bump go.mod to 1.25 which it looks like is about to happen anyway, I can rebase my changes once that happens):
AriehSchneier@3edf6ec
KaizenShogun commentedon Sep 9, 2026
@AriehSchneier your March question — fix go-git's matcher, or delegate to
git-pkgs/gitignore— ismeasurable, so here are numbers rather than an opinion.
Setup. One Go helper (
gitignore.ReadPatterns+Matcher.Match, andWorktree.Status()as asecond entry point), built four times from the same source, with only the go-git tree changing.
Corpus: the rule files of 33 large repos as written, 4,463 nested-
.gitignorequeries, withgit check-ignore --no-index(git 2.55.0) as the oracle. Bench:https://github.com/KaizenShogun/gitignore-conformance.
The control is your own
6aa9efc, the parent of the delegating commit, so the comparison isolatesthe engine swap instead of five months of drift.
Matcher.Match(4,463)Status()(2,224)main(tarball taken 2026-09-09)6aa9efc— own matcher3edf6ec— delegating,git-pkgs/gitignorev1.1.1Compared as sets, not counts. Delegating as it stands trades two failures for three: it fixes
grafana's
testdata/**output/, and it breaksdeps/(a file named after the directory thatexcluded it) in three places, which is also the whole of the
Status()regression. Those three aregit-pkgs/gitignore#22. There is a second one I filed today, git-pkgs/gitignore#23: a dir-only
pattern with a wildcard,
*.egg-info/, matches the directory but nothing inside it — that one thebench never asked about, and it hits 9 real rule lines across 8 of those repos.
With both patched, delegating lands exactly where
mainalready is: 2 and 1.The part that matters for this issue. The repro in the opening comment — root
abc, nestedabc/.gitignorewith!def— passes on all four builds. It doesn't reproduce any more, whicheverengine you pick. What does still fail on all four is the sibling shape from #694, both patterns in
one file:
git keeps
test/keepignored (once a directory is excluded it never looks inside again), and allfour builds re-include it. It is also the last thing standing in both columns above — the two
remaining divergences are
.vscode+!.vscode/extensions.jsonfrom ollama, the same shape. Sothe engine choice is orthogonal to it: neither library gets it right today.
KaizenShogun commentedon Sep 11, 2026
A correction to my own comment above, with the numbers that force it.
I measured those four builds on a corpus that never asked what was inside a directory. Adding that
one variant took it from 4,463 questions to 8,953, and it moves every row here — including the
conclusion I stated, that delegating "lands exactly where
mainalready is".Same setup as before: git 2.55.0 as the oracle, one Go helper built once per tree, nothing else
changing between rows.
Matcher.MatchStatus()main(2026-09-09)6aa9efc— own matcher3edf6ec— delegating, v1.1.1 + git-pkgs/gitignore#22(
Status()answers 6,714 of the 8,953; it declines directories, so I don't make a row up for them.)Row three is the one I reported in March terms, and on the bigger corpus it reads 24 against
main's12 — the tie was an artefact of the questions, not a property of the engines. But that row's library
is v1.1.1 plus one patch, and it has gone stale: git-pkgs/gitignore#22 and #24 are both merged now,
and the library measured on its own sits at 12 over the same questions. That's the last row, and
it's the only one that answers the question as it stands in 2026.
Delegating to HEAD scores 12 under
Matcher.Match— and compared as sets, not counts, they are thesame twelve
mainalready fails. Nothing fixed, nothing broken. A real tie this time.Status()is where delegating still costs something: 11 against 5, one case bought and seven lost.All seven are contents of a directory whose name reads like a file —
.vscode/extensions.json/…inollama,
docker/volumes/functions/main/index.ts/…in supabase. Which of the two open library issuesthey trace to (git-pkgs/gitignore#25 or #26) I haven't pinned down; I'm reporting the number, not the
cause.
So at the matcher the engine choice is a wash today, and whatever decides it isn't conformance. The
Status()gap is the part worth watching, and it lives upstream rather than here.Bench, corpus and instructions to reproduce any row: https://github.com/KaizenShogun/gitignore-conformance
KaizenShogun commentedon Sep 11, 2026
Closing the loose end from my comment this morning: I said delegating costs 7 cases in
Status()and that I had not attributed them. Now I have, and the attribution changes what the 7 mean.Same delegating build, only the library tree swapped — twice, to two patched copies of
git-pkgs/gitignoreHEAD:Status()divergences**on negations**at all (the ceiling)So six of the seven are git-pkgs/gitignore#26 — a negation inherits the implicit
**thatappendTrailingDoubleStarappends, so!volumes/functions/main/index.tsre-includes everything under that path too. The seventh is a different bug, #25:app/ui/app/.vscode/extensions.json, where.vscodeis excluded and git refuses to let!.vscode/extensions.jsonbring it back. Both are open with repros.Two things worth flagging, since neither is what I expected:
The ceiling row is not a superset of the patch row. Dropping the implicit
**everywhere fixes four of the seven but leaves the two ollama ones that the negation-only patch fixes — because once exclusions lose their**,.vscodestops covering its own contents and those paths diverge again for a new reason. The mechanism is load-bearing for exclusions; it is only wrong on negations.And the negation-only patch costs 66 new breakages in
Status()on this corpus (67 total against 11). It is the right diagnosis and the wrong patch — the library uses that same implicit**to emulate the walk down ancestors it does not have, so removing it from negations takes the walk away with it. I said as much in #26; this is the same result seen through go-git.None of this moves the matcher numbers from this morning: delegating and
mainstill return the same 12. The 7 areStatus()-only, and they have two ticket numbers rather than an unknown cause.KaizenShogun commentedon Sep 13, 2026
A correction to my own comment of 11 Sep in this thread. I said delegating to
git-pkgs/gitignorecost 7 cases inStatus(), and traced most of them to two bugs I'd reported in that library. Those bugs are fixed and tagged (v1.3.0, today). The cost is no longer 7, and not in the direction I'd have guessed: rebuilt on the fixed library, the delegating branch gets worse.Same corpus and oracle as before — 8,953 nested-
.gitignorequeries over 43 repos,git check-ignore --no-index, git 2.55.0 — one Go helper built three times, only the trees under it changing. The branch pins v1.1.1; in both delegating rows I swap the library tree and change nothing else.mainand the older delegating build were re-measured today as controls, and both reproduce their old numbers with the same rows:Matcher.MatchStatus()main, own matcher3edf6ecdelegating, library at the commit before the fix (#22 and #24 in)3edf6ec, library swapped for v1.3.0git-pkgs/gitignorev1.3.0 on its own, used as a whole-tree matcherThe 82 new ones in the first column all point the same way — git says not ignored, go-git says ignored — across 10 repos and 14 pattern shapes. That's the direction that hides files from
Status().It isn't the library. Two rules, with
settings.jsonan actual directory:git check-ignore --no-indexsays.vscode/settings.json/keep.txtis not ignored, and.vscode/other.jsonis.ReadPatterns+NewMatcher(ps).Match([]string{".vscode", "settings.json", "keep.txt"}, false)returnsfalseon3edf6ecas branched andtrueon3edf6ec+ v1.3.0. The library asked directly —NewFromDirectory+MatchPath— agrees with git.The mechanism is in the bridge,
pattern.go:pattern.Matchbuilds a freshextgitignorematcher per pattern per query and feeds it a single line. Since v1.3.0 that matcher walks the parent directories of the path it is handed, so.vscode/*on its own now answers "ignored" for anything under.vscode/settings.json; the negation, alone in its own matcher, no longer matches that descendant at all, because the implicit trailing**that used to make it cascade was removed in the same release. go-git'sMatcheris then choosing between one Exclude and nothing. Before v1.3.0 the implicit**made the negation cascade too, and the two errors cancelled.So what's worth delegating is the library's whole-tree
Matcher, which owns the parent walk and last-match-wins across every rule file; a per-pattern bridge delegates the pattern and keeps the matching, and that is where the 84 come from.mainlooks to be going its own way —Scopein 9a978dd is the same fix made in-house — so this may well be moot. I'm posting it because the numbers I left in this thread say otherwise, and anyone rebuilding that branch today lands on the wrong side of them.Bench and corpus: https://github.com/KaizenShogun/gitignore-conformance
KaizenShogun commentedon Sep 13, 2026
One number in my comment this morning is wrong, and it's the one describing the bench rather than any result: the 8,953 queries come from 33 repositories, not 43. 43 is the level-1 corpus in the same repo — one root
.gitignoreeach, 9,852 queries — and I pasted its census onto a level-2 number. My earlier comments in this thread say 33, which is the right one.Nothing else changes:
main12, the branch as pinned 12, the branch on v1.3.0 84, and the two-rule repro at the end stands on its own without the corpus.