Skip to content

fix: swap GIT binary patch sections when reversing - #100

Open
SashaMIT wants to merge 1 commit into
sourcegraph:masterfrom
SashaMIT:fix/reverse-binary-sections
Open

SashaMIT wants to merge 1 commit into
sourcegraph:masterfrom
SashaMIT:fix/reverse-binary-sections

Conversation

@SashaMIT

@SashaMIT SashaMIT commented Oct 11, 2026 •

Copy link
Copy Markdown

ReverseFileDiff swaps the index hashes and the diff --git paths. A GIT binary patch still keeps its two encoded sections in the original order.

git apply uses the first section as the forward result and the second as the reverse result. git diff -R --binary writes them in the opposite order. With only the hashes swapped, git apply --check reports creates incorrect result and the file is left unchanged.

The two sections are now swapped. A literal patch and a delta patch both reverse. On the reported bin.dat patch, git apply of the reversed diff turns 00 01 02 03 back into 00 01.

go test -count=1 ./diff/ passed. Before the swap, TestReverseFileDiffGitBinarySemantics still had literal 4 ahead of literal 2.

Fixes #98

git apply uses the first encoded section as the forward result, so leaving the sections in the original order makes the reversed patch fail.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ReverseFileDiff on a git binary patch gives a diff that git apply rejects

1 participant