Skip to content

Fix diff parsing for dirty submodules without an index line - #246

Merged
lyrixx merged 1 commit into
mainfrom
worktree-issue-165-submodule-diff
Sep 7, 2026
Merged

Fix diff parsing for dirty submodules without an index line#246
lyrixx merged 1 commit into
mainfrom
worktree-issue-165-submodule-diff

Conversation

@lyrixx

@lyrixx lyrixx commented Sep 7, 2026

Copy link
Copy Markdown
Member

Summary

  • DiffParser only looked for --- /+++ /Binary files markers inside the index block, but git omits the index line for a "dirty" submodule (working tree changed, same commit checked out), which made the parser choke on the next hunk and throw an exception (reported as getDiff() failing on repos with submodules).
  • Moved that handling out of the index conditional so it runs regardless of whether an index line was present.
  • Added a regression test (testDirtySubmoduleWithoutRaw) reproducing the dirty-submodule diff format from the issue.

Test plan

  • vendor/bin/phpunit — 225 tests, 567 assertions, all green
  • castor cs --dry-run — no style issues
  • castor phpstan — no errors
  • Verified the new test fails with the original code (reproducing the reported exception) and passes with the fix

Fixes #165

A submodule whose working tree changed but still points at the same
commit is reported by git without an "index " line before "--- "/"+++
". DiffParser only looked for those markers inside the "index " block,
so it never consumed them in that case and choked on the next hunk.

Fixes #165
@lyrixx
lyrixx merged commit 0cbbf59 into main Sep 7, 2026
6 checks passed
@lyrixx
lyrixx deleted the worktree-issue-165-submodule-diff branch September 7, 2026 16:09
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.

Parsing error if there is/are git sub-repository

1 participant