Skip to content

Preserve exact hunks across renames - #60

Merged
hzw0813 merged 7 commits into
mainfrom
fix/rename-hunk-pathspec
Aug 15, 2026
Merged

Preserve exact hunks across renames#60
hzw0813 merged 7 commits into
mainfrom
fix/rename-hunk-pathspec

Conversation

@hzw0813

@hzw0813 hzw0813 commented Aug 15, 2026

Copy link
Copy Markdown
Owner

Summary

  • scope per-file Git diffs for renamed paths to both the previous and current path
  • preserve an empty hunk set for pure renames instead of reconstructing the entire destination as newly added
  • preserve the minimal edited hunk for rename+modify changes
  • add regressions for both pure rename and rename+modify cases
  • regenerate tracked dist and document the fix

Why

changedFiles() discovers renames using an unscoped git diff --name-status --find-renames, but then reconstructed each file's zero-context patch using only the destination path. Once the pathspec is restricted to the new path, Git can no longer pair the source and destination, so a renamed file is reinterpreted as a whole-file addition. That overstates file.hunks and can make unchanged call sites appear to be inside changed lines.

The fix supplies both previousPath and path whenever rename/copy metadata provides both identities. A pure rename now has no content hunks, while a rename with one edited line produces exactly that one-line hunk.

Verification

  • independently reproduced the old Git pathspec behavior before modifying the repository
  • full npm test passed after the fix
  • clean npm run clean && npm run build passed
  • git diff --check passed
  • generated dist/git.* refreshed
  • temporary updater workflows removed from the final diff

@hzw0813
hzw0813 merged commit eb27d0f into main Aug 15, 2026
13 checks passed
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