fix: honour [...] bracket expressions and backslash escapes in branch patterns [patch] - #48
Merged
Merged
Conversation
… patterns [patch] BranchPattern promised to match the way git branch --list does, but only understood * and ?. A pattern such as origin/release-[0-9]* was accepted and then matched nothing, so those branches silently dropped out of /state and /branches. The matcher now handles ranges, sets, negation with ! or ^, a literal ] placed first, and \ escapes, keeping the linear no-regex walk. An unclosed [ stays an ordinary character. A * is now checked before a literal match, so a star always acts as a wildcard. Fixes #43 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PtWVWaDh3nqJL1eKD7vFxU
Splits the range parsing out of TryMatchBracket so the method stays under the cognitive-complexity limit. Behaviour is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PtWVWaDh3nqJL1eKD7vFxU
|
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.



Fixes #43
What was wrong
BranchPatternsays it matches "the way git matches one", but it only understood*and?. A client pattern such asorigin/release-[0-9]*passedTryParse, then matched nothing. Those branches dropped out of/stateand/brancheswith no error.Change
Matchesstill walks the pattern and the name once, with no regex. Each non-star element now goes throughMatchesOne, which handles:?\x: an escaped literal[0-9]), sets ([abc]), negation with!or^, a literal]placed first ([]x],[!]]), a-at either end as a literal, and\escapes inside the brackets[with no closing]is still an ordinary character. This keeps the existing "stray bracket is literal" behaviour.*is now checked before a literal match, so a star in the pattern always acts as a wildcard.Out of scope: POSIX classes such as
[[:digit:]], which git's wildmatch also accepts. Nothing reported them, and they can follow if they turn up in a realStatusBranchNamePatterns.Tests
Added 9
BranchPatternTests: the range case from the issue, sets,!/^negation,]placed first,-at either end, backslash escapes, an unclosed[, a bracket after*that needs backtracking, and a pathological*[a-y]× 40 pattern that must still return promptly.BranchPattern.csreverted, 7 of the new tests fail.dotnet test --project GitBranchStateCache.Tests).🤖 Generated with Claude Code
https://claude.ai/code/session_01PtWVWaDh3nqJL1eKD7vFxU
Generated by Claude Code