Repository navigation
Write a partial rename patch as a plain change to the new path - #193
Merged
Merged
Conversation
GitFilePatch.PatchFor always wrote the file's full header, so for a renamed file it carried the rename from / rename to lines under whatever subset of hunks the caller picked. Reverse-applying one hunk of a staged rename to the index then undid the rename as well: b left the index and the other hunk moved onto a. A subset of a renamed or copied file's hunks is now written under a plain modification header on the new path, and the full header is kept only when every hunk is selected. Fixes #126 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JgoVAth3nGZUgbKrSgVCYX
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JgoVAth3nGZUgbKrSgVCYX
|
This was referenced Oct 7, 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.



Fixes #126
What changed
GitFilePatch.PatchFor(hunks)always wrote the file's full header. For a renamed file, that header includessimilarity index,rename fromandrename to. So when a caller picked one hunk of a staged rename and unstaged it withApply(file.PatchFor([hunk])).ToIndex().Reversed(), git also undid the rename:bdropped out of the index and the other hunk's change ended up ona.Now, when
PatchForis given only some of a renamed or copied file's hunks, it writes them under a plain modification header on the new path:diff --git,---and+++lines all name the new pathWhen every hunk is selected, the full rename header is kept as before. That's the option the issue's acceptance criteria describe.
Tests
GitPatchTests.PatchForSomeHunksOfARenameWritesAPlainChangeToTheNewPathandPatchForSomeHunksOfAQuotedRenameKeepsTheQuotingcheck the exact header text produced.GitPatchTests.PatchForEveryHunkOfARenameKeepsTheRenameHeaderis a guard for the all-hunks case. It passes with or without the fix.GitPatchRoundTripTests.UnstagingOneHunkOfAStagedRenameKeepsTheRenameAsyncruns the issue's reproduction against real git. After the reverse-apply, the index still holdsbas a rename ofawith only the line-28 change, and the line-2 change is unstaged.With the fix reverted, the three new behaviour tests fail; with it, they pass. The full suite passes locally (750 tests, 0 failed).
🤖 Generated with Claude Code
https://claude.ai/code/session_01JgoVAth3nGZUgbKrSgVCYX
Generated by Claude Code