Skip to content

Fix file rename and deletion display in diff review#75

Open
C-Hipple wants to merge 1 commit intomainfrom
claude/fix-new-file-hunk-parsing-JAnnb
Open

Fix file rename and deletion display in diff review#75
C-Hipple wants to merge 1 commit intomainfrom
claude/fix-new-file-hunk-parsing-JAnnb

Conversation

@C-Hipple
Copy link
Owner

@C-Hipple C-Hipple commented Mar 6, 2026

Summary

Improves handling of renamed, new, and deleted files in the diff review UI. The backend now explicitly emits ---/+++ lines for new and deleted files, and properly detects renames. The frontend now displays renamed files with an arrow notation (e.g., "old.txt → new.txt") and correctly tracks the original filename.

Changes

  • Backend (renderer.go):

    • Added explicit --- /dev/null and +++ /dev/null lines for new and deleted files so the frontend can identify filenames correctly
    • Added rename detection for modified files where OrigName differs from NewName
    • Added extractGitDiffNames() helper to parse filenames from diff --git headers for rename-only changes
    • Properly emit rename from/rename to lines for all rename scenarios
  • Frontend (Review.tsx):

    • Added origName field to track original filename for renamed files
    • Enhanced rename detection to parse rename from and rename to lines separately
    • Added detection of --- /dev/null to identify new files
    • Added special handling for +++ /dev/null to identify deleted files
    • Updated file header display to show renamed files as "oldname → newname"
    • Fixed state reset logic to properly clear fallbackOrigName between files

Test Plan

  • go build ./... passes
  • go test ./... passes

https://claude.ai/code/session_01DzjiHjQR52hnwWcPZGF22H

For new/deleted files the diff parser's lookahead skips the ---/+++
lines when a "new file mode"/"deleted file mode" line is present,
so formatDiff never emitted them. The frontend relied on the +++ line
to identify the filename and create the file header box; without it,
all content lines were dumped as plain text with no syntax highlighting
or collapsible box.

For renamed files (both with and without content changes) formatDiff
likewise omitted the rename markers, so the frontend showed "Modified"
instead of "Renamed".

Backend (server/renderer.go):
- For NEW files: emit "--- /dev/null" + "+++ b/<name>" after DiffHeader
- For DELETED files: emit "--- a/<name>" + "+++ /dev/null" after DiffHeader
- For MODIFIED renames with changes: emit "rename from/to" + "---/+++"
- For rename-only (no content): parse names from the diff --git line and
  emit "rename from/to" + "---/+++" so the frontend gets the file header
- Add extractGitDiffNames() helper

Frontend (bun_client/frontend/src/components/Review.tsx):
- Add origName?: string to ParsedLine interface
- Track fallbackOrigName alongside fallbackFilename
- "--- /dev/null" → set pendingFileStatus = 'new'
- "+++ /dev/null" → create file-header using fallbackFilename with
  fileStatus 'deleted' (instead of setting currentFile = '/dev/null')
- "rename from X" → set fallbackOrigName = X, pendingFileStatus = 'renamed'
- "rename to Y" → update fallbackFilename = Y, pendingFileStatus = 'renamed'
- Propagate origName to all file-header ParsedLine pushes
- renderDiff: show "origName → newName" for renamed file headers

https://claude.ai/code/session_01DzjiHjQR52hnwWcPZGF22H
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.

2 participants