Skip to content

fix/reverse: keep "Only in" entries when reversing - #99

Open
youdie006 wants to merge 1 commit into
sourcegraph:masterfrom
youdie006:reverse-keeps-only-in
Open

youdie006 wants to merge 1 commit into
sourcegraph:masterfrom
youdie006:reverse-keeps-only-in

Conversation

@youdie006

Copy link
Copy Markdown
Contributor

The parser stores an Only in <dir>: <file> line as a FileDiff with OrigName set and NewName == "", and the printer recognises it by the empty NewName (diff/print.go:39-45). ReverseFileDiff swaps the names unconditionally (diff/reverse.go:22-28), so the reversed entry has a NewName, no hunks, and prints as nothing:

ParseMultiFileDiff + ReverseMultiFileDiff + PrintMultiFileDiff on testdata/sample_contains_added_deleted_files.diff prints the reversed hunk, but both Only in source_a: file_2.txt and Only in source_b: file_3.txt are gone. GNU diff -r b a prints the same Only in lines as diff -r a b, so they should come through unchanged.

TestReverseRoundTripOnTestdata reverses twice, so the lost lines come back and it passes. This adds a row to TestReverseMultiFileDiff with the expected output in testdata/sample_contains_added_deleted_files.reversed (the non-git diff -u command line is left as is, per the existing rule for non-git headers); it fails on master. go test ./..., go vet and GOARCH=386 go test ./diff/ pass on Go 1.26.

Written with AI assistance (Claude); I have reviewed the change.

An "Only in" line is parsed as OrigName=<path>, NewName="", and the
printer recognises it by the empty NewName. ReverseFileDiff swapped the
names, so the reversed entry printed as nothing. GNU diff prints the
same "Only in" line in both directions, so leave those names alone.
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.

1 participant