Repository navigation
Implement Git-compatible wildmatch for gitignore patterns - #1940
Merged
Merged
Conversation
AriehSchneier
force-pushed
the
fix-gitignore
branch
3 times, most recently
from
March 31, 2026 03:50
a5a20a2 to
fb9676c
Compare
AriehSchneier
force-pushed
the
fix-gitignore
branch
3 times, most recently
from
April 4, 2026 13:23
6f2b90c to
d584230
Compare
AriehSchneier
force-pushed
the
fix-gitignore
branch
5 times, most recently
from
April 14, 2026 22:49
6ac0f75 to
52e4307
Compare
AriehSchneier
force-pushed
the
fix-gitignore
branch
from
April 17, 2026 00:29
52e4307 to
5e14981
Compare
This was referenced Apr 19, 2026
AriehSchneier
force-pushed
the
fix-gitignore
branch
4 times, most recently
from
April 30, 2026 00:52
7b54df0 to
c9620cc
Compare
Member
|
@AriehSchneier please note that commits assisted by AI must have a I have some additional changes to add to this PR which I will at some point today. |
This commit adds a complete test suite for evaluating go-git's gitignore implementation against Git's canonical behavior, based on Git's official test suite (t3070-wildmatch.sh and t0008-ignores.sh). Test Files: - complete_wildmatch_test.go: Complete wildmatch pattern tests - git_canonical_test.go: Canonical test suite from Git source - wildmatch_canonical_test.go: Wildmatch-specific canonical tests The test suite identifies several compatibility issues with Git's behavior: - Bracket expression negation ([!...] vs [^...]) - Double star pattern matching (data/**, foo**/bar) - Advanced bracket expressions (a[]]b, a[]-]b) - POSIX character classes ([[:alpha:]], [[:digit:]]) - Multi-level path counting (*/*/*) This test suite provides a baseline for future compatibility improvements without implementing the fixes themselves. Assisted-by: Claude Sonnet 4.5 <[email protected]> Signed-off-by: Arieh Schneier <[email protected]>
This commit replaces filepath.Match with a custom wildmatch implementation that provides full Git compatibility for gitignore pattern matching. Key improvements: - POSIX character classes: [:digit:], [:upper:], [:alpha:], [:xdigit:], etc. - Proper bracket expression negation with [!...] and [^...] - Escaped characters in patterns and bracket expressions - Complex bracket ranges and edge cases (e.g., [\\]], [[-\\]], [--A]) - Malformed character class detection (returns false for invalid classes) - Patterns with ** embedded in segments (e.g., foo**/bar, **/bar**) Implementation details: - wildmatch(): Core pattern matching with star backtracking - matchBracket(): Bracket expression matching following Git's logic - matchCharClass(): POSIX character class validation with (matched, valid) tuple - findBracketEnd(): Correctly handles malformed [:class:] patterns as literals Based on Git's wildmatch.c implementation from the Git source code. Test results: 84/84 tests passing (100%) - TestGitCanonicalSuite: All canonical Git behavior tests passing - TestWildmatchCanonicalSuite: All wildmatch-specific tests passing - TestCompleteWildmatchSuite: Complete Git test matrix passing - TestPatternSuite: All pattern matching tests passing - TestMatcherSuite: All matcher integration tests passing Assisted-by: Claude Sonnet 4.5 <[email protected]> Signed-off-by: Arieh Schneier <[email protected]>
AriehSchneier
force-pushed
the
fix-gitignore
branch
from
April 30, 2026 11:27
c9620cc to
19a0551
Compare
1 of 20 tasks
Fix two divergences from Git's wildmatch: - Trailing '\' no longer matches itself; the escape branch falls through to backtracking per wildmatch.c's escape/default path. - POSIX classes are ASCII-only, matching sane-ctype.h: high-bit bytes never classify. Share the [:name:] header parser between findBracketEnd and matchBracket as parsePosixClass. Consolidate complete_wildmatch_test.go, git_canonical_test.go, and wildmatch_canonical_test.go into conformance_test.go. Without -short, each expectation is cross-validated against `git check-ignore` on a materialized scratch repo (file ops confined via *os.Root). Add FuzzMatch over ParsePattern+Match. Assisted-by: Claude Opus 4.7 <[email protected]> Signed-off-by: Paulo Gomes <[email protected]>
Go-git currently doesn't support core.ignorecase=true. To ensure the tests still pass correctly, verify that check would pass if core.ignorecase=false. This should be removed once that support is added to go-git. Signed-off-by: Paulo Gomes <[email protected]>
pjbgf
approved these changes
Apr 30, 2026
pjbgf
left a comment
Member
There was a problem hiding this comment.
@AriehSchneier thanks for working on this, a much needed addition to go-git. 🙇 🙇 🙇
I made a few additional changes while I was checking for upstream conformance:
- Consolidated the different upstream-test cases on a single file.
- Trailing
\fix in wildmatch a pattern ending in\falls through to backtracking and fails to match, matchingwildmatch.c's escape. - POSIX classes are now ASCII-only.
matchCharClassreplacesunicode.Is*with byte-range checks, mirroringsane-ctype.hso high-bit bytes never satisfy[[:alpha:]]/[[:digit:]]/etc. - Shared
parsePosixClasshelper. The[:name:]header parser used to be duplicated infindBracketEndandmatchBracket, now this is a helper function. - When
!testing.Short()several test cases will go on and also verify if the matching expectations aligns with upstream Git. - Added checks for Git
v2.11.0(due to compatibility checks) to ensure we accommodate for cases whereby upstream behaviour changed over time. - Added checks to enforce that MacOS and Windows behaviour aligns with Git with
core.ignorecase=false, at least until we add support forcore.ignorecase=true. - Added
FuzzMatchto fuzz test this logic going forwards.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR implements a Git-compatible wildmatch function to fix gitignore pattern matching compatibility issues.
Summary
Replaces
filepath.Matchwith a custom wildmatch implementation that provides full Git compatibility for gitignore pattern matching.Changes
Commit 1: Add comprehensive gitignore compatibility test suite
Commit 2: Implement Git-compatible wildmatch for gitignore patterns
Test Results
84/84 tests passing (100%)
Implementation
Based directly on Git's wildmatch.c implementation from the Git source code, ensuring full compatibility with Git's gitignore pattern matching behavior.
Fixes #877
🤖 Generated with Claude Code