Repository navigation
Changes: render rename diff for renamed files instead of full additions - #60
Conversation
|
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
left a comment
There was a problem hiding this comment.
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
- Heavily edited renames show two file sections (
git.ts:94).git statusdetects the rename by comparing HEAD with the index, butgit diff -M HEADcompares HEAD with the working tree. Aftergit mv big.txt moved.txtand a rewrite ofmoved.txtthat drops similarity below 50%, selectingmoved.txtshowsdeleted file big.txtfollowed by--- /dev/null/+++ b/moved.txt. - Copies are treated as renames (
git.ts:94).statusEntriessetsoriginalforCentries too. Withdiff.renames=copies, the copy's diff includes the source file's own unrelated edits. The hard-coded-Malso turns off copy detection. - A plain
mvisn't covered. Withoutgit mv, status reportsD old/?? new, so the diff still goes through/dev/null. The Claude and Codex CLIs usually rename with plainmv, so most agent renames would still look like full additions. diff()can now throw (git.ts:88). It callsstatusEntries, which throws whengit statusfails, for example when a worktree folder is removed while the Changes panel is open. Before this PR,diff()returned whatever git printed.- 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 fromcwd, so when the project folder is a subdirectory of the repo the diff comes back empty.
Smaller things
ChangesPanel.tsx:83stylesdiff,index,---/+++,new fileanddeleted fileas header lines, but notsimilarity index,rename fromorrename 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 hasoriginal; carrying it onChangedFilewould 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 --githeader would catch (1).
Before merge
- GitHub shows
8b9036bas unverified (unknown_key), andmainrequires 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. mainrequires branches to be up to date, so please rebase onto the currentmain.
CI passed on the last run of this branch.
8b9036b to
9fdc245
Compare
|
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. |
BunsDev
left a comment
There was a problem hiding this comment.
Reviewed and verified locally on top of current main (including #61).
- Staged renames now render as rename diffs:
rename from/toplus only the changed lines (pure rename, rename + edit, names with spaces, explicitoriginalfrom the panel). Onmainevery one of these rendered as a/dev/nullfull addition. - When an edit drops similarity below git's rename threshold, the
HEAD:<orig>fallback produces a singlea/<orig>→b/<new>diff. - Three of the four new tests fail against
main'sgit.tsand pass here.git.test.ts13/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:
- 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. git()never rejects, so the outertry { … } catch { return ""; }mostly turns programming errors into an empty diff instead of the panel's error state.- Non-renamed diffs now run a full-repo
git statusinstead of a path-filtered one. Fine at current scale, but worth watching on large repos. - The "heavily rewritten" test also passes on
main(one/dev/nullheader), so it doesn't pin the fallback. Asserting--- a/README.mdwould.
Thanks!
🤖 Generated with Claude Code
|
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. 🚀 |
…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]>
Fixes #56
Description
When viewing diffs for renamed files in the Changes panel,
diff()inapps/desktop/src/main/engine/git.tsexecuted a path-filtered status check (git status --porcelain=v1 -- rel) andgit diff HEAD -- relusing 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/nullwith 100% additions, even when the file was unmodified or had minor edits.Fix
apps/desktop/src/main/engine/git.ts:diff(), look upentry.originalfromstatusEntries(cwd)(matching the pattern used inrevert()).originalexists, pass both paths and-Mtogit diff(git diff -M <target> -- original rel).apps/desktop/test/git.test.tsverifying that diffing a renamed file preserves the rename hunk and modified lines rather than rendering a/dev/nulladdition.