Skip to content

Changes: render rename diff for renamed files instead of full additions - #60

Merged
BunsDev merged 2 commits into
TypeSafeAI:mainfrom
Yash990-bit:fix-rename-diff
Oct 3, 2026
Merged

BunsDev merged 2 commits into
TypeSafeAI:mainfrom
Yash990-bit:fix-rename-diff

Conversation

@Yash990-bit

Copy link
Copy Markdown
Contributor

Fixes #56

Description

When viewing diffs for renamed files in the Changes panel, diff() in apps/desktop/src/main/engine/git.ts executed a path-filtered status check (git status --porcelain=v1 -- rel) and git diff HEAD -- rel using only the destination filename.

Because git cannot correlate the destination path with the source in HEAD from that pathspec alone, it rendered the entire file as a new file from /dev/null with 100% additions, even when the file was unmodified or had minor edits.

Fix

  • In apps/desktop/src/main/engine/git.ts:diff(), look up entry.original from statusEntries(cwd) (matching the pattern used in revert()).
  • If original exists, pass both paths and -M to git diff (git diff -M <target> -- original rel).
  • Added a unit test in apps/desktop/test/git.test.ts verifying that diffing a renamed file preserves the rename hunk and modified lines rather than rendering a /dev/null addition.

@Yash990-bit

Copy link
Copy Markdown
Contributor Author

Hi @BunsDev, could you please take a look at this rename diff fix when you get a chance? Verified with unit tests and signed with SSH. Happy to address any feedback!

@BunsDev BunsDev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for picking up #56. The git mv + small edit case works. A few common cases still produce a full-addition diff, or mix another file's content into the diff.

Correctness

  1. Heavily edited renames show two file sections (git.ts:94). git status detects the rename by comparing HEAD with the index, but git diff -M HEAD compares HEAD with the working tree. After git mv big.txt moved.txt and a rewrite of moved.txt that drops similarity below 50%, selecting moved.txt shows deleted file big.txt followed by --- /dev/null / +++ b/moved.txt.
  2. Copies are treated as renames (git.ts:94). statusEntries sets original for C entries too. With diff.renames=copies, the copy's diff includes the source file's own unrelated edits. The hard-coded -M also turns off copy detection.
  3. A plain mv isn't covered. Without git mv, status reports D old / ?? new, so the diff still goes through /dev/null. The Claude and Codex CLIs usually rename with plain mv, so most agent renames would still look like full additions.
  4. diff() can now throw (git.ts:88). It calls statusEntries, which throws when git status fails, for example when a worktree folder is removed while the Changes panel is open. Before this PR, diff() returned whatever git printed.
  5. Projects in a subdirectory (git.ts:96). This predates the PR, but the new rename path has the same problem. Status paths are relative to the repo root, yet they're passed as pathspecs from cwd, so when the project folder is a subdirectory of the repo the diff comes back empty.

Smaller things

  • ChangesPanel.tsx:83 styles diff, index, ---/+++, new file and deleted file as header lines, but not similarity index, rename from or rename to. A pure rename shows four unstyled lines and no hunk.
  • Every diff click now runs a full git status --untracked-files=all, plus a second, path-filtered status when the path isn't found. status() already has original; carrying it on ChangedFile would avoid the rescan. The fallback status call also looks unreachable given --untracked-files=all.
  • The resolve / relative / find lookup duplicates revert() (git.ts:102-105). A shared helper would keep the two from drifting.
  • The test covers only a small append. A test that rewrites the renamed file and asserts there is exactly one diff --git header would catch (1).

Before merge

  • GitHub shows 8b9036b as unverified (unknown_key), and main requires verified signatures. Add the SSH key you sign with as a Signing key under Settings → SSH and GPG keys. The rebase below then produces a verified commit.
  • main requires branches to be up to date, so please rebase onto the current main.

CI passed on the last run of this branch.

@Yash990-bit

Copy link
Copy Markdown
Contributor Author

Hi @BunsDev, thanks for the detailed and thoughtful review! I've addressed all the feedback:

Verified signature & rebase: Added the signing key to GitHub settings and rebased cleanly onto current main. The commit is now verified.
Heavily edited renames: If a rewrite causes git diff's similarity to drop and output multiple file sections, it now falls back to comparing HEAD: directly against the working file so there is always exactly one diff --git header.
Copies vs renames: Restricted original lookup only to renames (R), so copies (C) are not treated as renames.
Avoided status rescan: ChangedFile now carries original from status() directly to the Changes panel and changes:diff, avoiding an extra status rescan on each diff click.
Subdirectory projects: Added repoContext to resolve repository root and prefix so diffs work seamlessly when opening a project from a repo subdirectory.
Safe error handling: diff() is wrapped safely and will not throw on deleted worktree directories.
Diff styling: Added similarity index, rename from, rename to, and copy from/to line headers in ChangesPanel.tsx.
Tests: Added unit tests covering heavily rewritten renames (asserting a single diff header), pure renames, and subdirectory diffs.

@BunsDev BunsDev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed and verified locally on top of current main (including #61).

  • Staged renames now render as rename diffs: rename from/to plus only the changed lines (pure rename, rename + edit, names with spaces, explicit original from the panel). On main every one of these rendered as a /dev/null full addition.
  • When an edit drops similarity below git's rename threshold, the HEAD:<orig> fallback produces a single a/<orig> → b/<new> diff.
  • Three of the four new tests fail against main's git.ts and pass here. git.test.ts 13/13; Changes-panel e2e specs (app, layout, review) 37/37; CI green.
  • Subdirectory projects: in-project files now diff correctly (they came back empty before).

Non-blocking notes for a follow-up:

  1. The fallback git diff HEAD:<orig> <path> has no --, so a heavily rewritten rename whose destination starts with - drops back to the full-addition view. That matches today's behaviour, so it's not a regression.
  2. git() never rejects, so the outer try { … } catch { return ""; } mostly turns programming errors into an empty diff instead of the panel's error state.
  3. Non-renamed diffs now run a full-repo git status instead of a path-filtered one. Fine at current scale, but worth watching on large repos.
  4. The "heavily rewritten" test also passes on main (one /dev/null header), so it doesn't pin the fallback. Asserting --- a/README.md would.

Thanks!

🤖 Generated with Claude Code

@BunsDev
BunsDev merged commit 48566d3 into TypeSafeAI:main Oct 3, 2026
1 check passed
@Yash990-bit

Copy link
Copy Markdown
Contributor Author

Thanks for the review and for verifying everything locally! Glad we got the rename diff handling merged. I’ll keep the follow-up notes in mind for future improvements. 🚀

BunsDev added a commit that referenced this pull request Oct 3, 2026
…67)

The three contributor bug fixes landed today: send rejections reach the
caller (#61), staged renames diff as renames (#60, with its follow-ups
noted), and worktree.sh survives a failed fetch (#62). #39's branding
images merged yesterday. Drop all four from "Open contributor PRs".

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

Changes panel: diff for renamed file renders as full addition instead of rename diff

2 participants