Skip to content

Renames aren't detected when the new file is untracked #243

Closed

Description

@LandonSchropp

#223 made renames render against their origin for tracked-vs-tracked diffs (staged, single-ref, two-ref). But when a file is renamed in the working tree without staging, the new path is untracked, and revdiff shows the old file as a full deletion plus the new file as an all-+ add instead of pairing them as a rename.

Repro

mv README.md README2.md   # rename in the working tree, leaving README2.md untracked
revdiff --untracked

Expected: one rename entry, README.md → README2.md. Actual: README.md deleted + README2.md all-+ new file. Staging the rename and using --staged renders correctly, so it's specific to the untracked path.

Staged

Image

Unstaged

Image

Cause

Untracked files are diffed independently against /dev/null, so the new file never shares a git diff invocation with the deleted origin and -M has nothing to pair.

Potential Fix

I experimented a bit with Claude Code, and it came up with a slightly hacky way to fix this. However, I'm not familiar with the codebase here, so I can't say whether or not it's a good idea or there's a better approach. 🙂


Marking the untracked file intent-to-add puts it in the same diff, and -M pairs the rename:

git diff -M --stat              # original.txt | 4 ----   (deletion only)
git add -N renamed.txt
git diff -M --stat              # original.txt => renamed.txt   (paired)

To do this without mutating the real index or working tree, run the intent-to-add against a throwaway index via GIT_INDEX_FILE:

tmp=$(mktemp)
cp "$(git rev-parse --git-dir)/index" "$tmp"   # copy so add -N sees existing state
GIT_INDEX_FILE="$tmp" git add -N <untracked paths>
GIT_INDEX_FILE="$tmp" git diff -M ...           # rename-aware, off the copy
rm -f "$tmp"

The real .git/index is byte-identical before and after, and no working files are touched.

Environment

revdiff v1.8.1.

Activity

  1. LandonSchropp commented on Jul 1, 2026

    @LandonSchropp
    Author

    @umputun Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions