Implement Git-compatible wildmatch for gitignore patterns#1940
Open
AriehSchneier wants to merge 2 commits intogo-git:mainfrom
Open
Implement Git-compatible wildmatch for gitignore patterns#1940AriehSchneier wants to merge 2 commits intogo-git:mainfrom
AriehSchneier wants to merge 2 commits intogo-git:mainfrom
Conversation
a5a20a2 to
fb9676c
Compare
6f2b90c to
d584230
Compare
6ac0f75 to
52e4307
Compare
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. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Signed-off-by: Arieh Schneier <15041913+AriehSchneier@users.noreply.github.com>
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 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Signed-off-by: Arieh Schneier <15041913+AriehSchneier@users.noreply.github.com>
52e4307 to
5e14981
Compare
This was referenced Apr 19, 2026
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