Conversation
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.
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.
The parser stores an
Only in <dir>: <file>line as aFileDiffwithOrigNameset andNewName == "", and the printer recognises it by the emptyNewName(diff/print.go:39-45).ReverseFileDiffswaps the names unconditionally (diff/reverse.go:22-28), so the reversed entry has aNewName, no hunks, and prints as nothing:ParseMultiFileDiff+ReverseMultiFileDiff+PrintMultiFileDiffontestdata/sample_contains_added_deleted_files.diffprints the reversed hunk, but bothOnly in source_a: file_2.txtandOnly in source_b: file_3.txtare gone. GNUdiff -r b aprints the sameOnly inlines asdiff -r a b, so they should come through unchanged.TestReverseRoundTripOnTestdatareverses twice, so the lost lines come back and it passes. This adds a row toTestReverseMultiFileDiffwith the expected output intestdata/sample_contains_added_deleted_files.reversed(the non-gitdiff -ucommand line is left as is, per the existing rule for non-git headers); it fails on master.go test ./...,go vetandGOARCH=386 go test ./diff/pass on Go 1.26.Written with AI assistance (Claude); I have reviewed the change.