Pin context lines and rename detection in Patch() - #128
Merged
Merged
Conversation
Patch() now always passes -U3 (or the WithContext value) and passes --no-renames unless DetectRenames() was called. Before, a host with diff.context=0 produced zero-context hunks that Apply(...).ToIndex() could not stage, and git's default rename detection (or diff.renames=copies) decided the patch shape instead of the builder. Fixes #121 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VKxYoUXQqgRKJR6ynbvnms
|
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 #121
What changed
GitPatchBuilderpinned the prefixes, color, ext-diff, textconv andsuppressBlankEmpty, but two settings still came from the host's git config:-UwhenWithContext(n)was called. It now always passes-U3, or theWithContextvalue. Before this, a repository withdiff.context=0produced@@ -25 +25 @@hunks, andApply(...).ToIndex()failed on them witherror: patch failed: f.txt:25.--no-renamesunlessDetectRenames()was called, in which case it passes--find-renamesas before. Before this, git's default rename detection, ordiff.renames=copies, decided the patch shape instead of the builder.The doc comments on
WithContextandDetectRenamesnow say that the default ignores the host's config.I left out the issue's optional
copy from/copy toparsing. With--no-renamesor--find-renamesalways on the command line, git no longer emits copy headers for this builder.Tests
BuildsTheDefaultPatchVectornow expects-U3and--no-renamesat the end of the vector.PinsContextAndRenameDetectionWhenNeitherIsRequestedandExplicitContextAndRenamesReplaceThePinnedDefaultscheck the argument list.RoundTripsUnderZeroContextConfigurationAsyncsetsdiff.context=0in the fixture repository, changes line 25 of 50, and checks that the patch goes back throughApply(...).ToIndex().ReportsAStagedRenameAsDeleteAndAddUnlessRequestedAsyncsetsdiff.renames=copies. It checks that a staged rename comes back as a delete plus an add by default, and asRenamedwithOriginalPathwhenDetectRenames()is called.With the builder change reverted, all four fail. The zero-context test fails with the error from the issue,
patch failed: f.txt:25. With the change, the full suite passes: 712 tests, 0 failed.🤖 Generated with Claude Code
https://claude.ai/code/session_01VKxYoUXQqgRKJR6ynbvnms
Generated by Claude Code