Match caller file paths literally, so file[1].txt no longer also matches file1.txt - #159
Merged
Merged
Conversation
…hes file1.txt [patch]
Add, Unstage, Patch, Diff, Log and RevList passed their RelativeFilePath
operands to git as pathspecs, so glob characters and a leading colon in a
real file name were read as pattern syntax: Unstage("file[1].txt") also
unstaged file1.txt, Unstage(":foo") unstaged foo, and ForPath returned
another file's hunks. Those builders now pass --literal-pathspecs whenever
they emit a path. It is not set on other commands, because git exports it
to the hooks it runs.
Fixes #125
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WAdbE4VMmkBh1tzMGpC9Wy
|
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 #125
Problem
Builders that take a
RelativeFilePathpassed it to git as a pathspec. Glob characters (*?[]) and a leading:in a real file name were therefore read as pattern syntax:Unstage("file[1].txt")also unstagedfile1.txtUnstage(":foo")unstagedfooand left:foostagedPatch().Staged().ForPath("file[1].txt")also returned the hunks forfile1.txtChange
GitCommandBuildergainsprotected virtual bool PassesPathsLiterally. When it is true,BuildArgumentsemits the global--literal-pathspecsoption before the verb.GitRestoreBuilder,GitAddBuilder,GitPatchBuilder,GitDiffBuilder,GitLogBuilderandGitRevListBuilder.GitRestoreBuilderalways passes a path, so it always sets the option.GIT_LITERAL_PATHSPECS, so enabling it oncommitand similar commands would change how hooks read their own pathspecs.GitCheckoutBuilder's trailing--carries no path, so it is unaffected.Tests
Integration/GitLiteralPathspecTestsruns against real git and covers:Unstage("file[1].txt")leavesfile1.txtstagedUnstage(":foo")unstages:fooand notfoo. This test is inconclusive on Windows, where a file name can't contain:Add().ForPath("file[1].txt")stages only that filePatch().Staged().ForPath("file[1].txt")returns only that fileWith the builder changes reverted, all 4 fail on their assertions. With them in place, the full suite passes: 731 of 731, on git 2.43.
🤖 Generated with Claude Code
https://claude.ai/code/session_01WAdbE4VMmkBh1tzMGpC9Wy
Generated by Claude Code