Support "copy from"/"copy to" in diff parser - #244
Merged
Conversation
DiffParser only handled "rename from"/"rename to" after a "similarity index" line, but git also emits "copy from"/"copy to" there when copy detection is enabled (e.g. diff.renames = copies), causing a parse error on otherwise valid diffs. File gains an isCopy() flag, and isRename() no longer reports true for copies, since a copy's source file still exists afterward. Fixes #14
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.
Summary
DiffParseronly recognizedrename from/rename toafter asimilarity indexline; git can also emitcopy from/copy tothere when copy detection is active (e.g.diff.renames = copies), which made parsing throwExpected "rename from ", but got "copy from ...".Diff\Filegains anisCopy()flag (serialized intoArray()/fromArray());isRename()no longer reportstruefor copies, since a copy's source file still exists afterward, unlike a rename.Fixes #14
Test plan
vendor/bin/phpunit(226 tests, including two new cases: a copy with content changes, and a pure 100%-similarity copy)castor cs --dry-runcastor phpstan