Skip to content

Support "copy from"/"copy to" in diff parser - #244

Merged
lyrixx merged 1 commit into
mainfrom
worktree-issue-14-copy-diff-parse
Sep 7, 2026
Merged

Support "copy from"/"copy to" in diff parser#244
lyrixx merged 1 commit into
mainfrom
worktree-issue-14-copy-diff-parse

Conversation

@lyrixx

@lyrixx lyrixx commented Sep 7, 2026

Copy link
Copy Markdown
Member

Summary

  • DiffParser only recognized rename from/rename to after a similarity index line; git can also emit copy from/copy to there when copy detection is active (e.g. diff.renames = copies), which made parsing throw Expected "rename from ", but got "copy from ...".
  • Diff\File gains an isCopy() flag (serialized in toArray()/fromArray()); isRename() no longer reports true for 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-run
  • castor phpstan

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
@lyrixx
lyrixx merged commit f17e2a2 into main Sep 7, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Error parsing diff Expected "rename from ", but got "copy from si"

1 participant