Skip to content

Consume a rename's source path when git reports it in the worktree column [patch] - #470

Merged
matt-edmondson merged 2 commits into
mainfrom
fix/437-worktree-rename
Oct 6, 2026
Merged

matt-edmondson merged 2 commits into
mainfrom
fix/437-worktree-rename

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #437

What changed

GitCli.ListPendingChanges skipped a rename's trailing source-path entry only when the rename was in the index status column (entry[0]). Git can also report a rename in the worktree column. That happens when a file added with git add -N matches a deleted tracked file, and the record then reads R new.txt\0ab cd.txt\0. The source entry ab cd.txt was parsed as a record of its own, so the commit prompt listed a phantom cd.txt and showed the wrong change count.

The check now also looks at entry[1], and the comment explains both cases.

Tests

New CommitTests.AWorktreeRenameReportsOnlyItsDestination, the issue's repro:

  1. Commit ab cd.txt.
  2. Delete it and create new.txt with the same content.
  3. Run git add -N new.txt.

The test first asserts that git really reports R new.txt (so it can't pass by accident), then that only new.txt is listed.

  • With the GitCli.cs change reverted, the new test fails (Assert.AreEqual(1, changes.Count)).
  • With the change, 104 of 106 pass, 1 is skipped, and 1 fails.
  • The failure is GitCliTests.CloningAnLfsRepositoryRestoresTheFileContentRatherThanThePointer. It fails the same way on unchanged main in this sandbox, where the LFS smudge filter doesn't run on a local clone. It is unrelated to this change.

🤖 Generated with Claude Code

https://claude.ai/code/session_01CaZMWc5xm4vDRcyMefDXyV


Generated by Claude Code

claude added 2 commits October 6, 2026 10:27
…lumn [patch]

git status --porcelain reports a rename detected in the worktree (an
intent-to-add file matched against a deleted tracked file) as " R", with
the source path following as a bare entry. ListPendingChanges only checked
the index column, so that source was parsed as its own record and the
commit prompt listed a file that does not exist.

Fixes #437

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01CaZMWc5xm4vDRcyMefDXyV
@sonarqubecloud

sonarqubecloud Bot commented Oct 6, 2026

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 19a4e35 into main Oct 6, 2026
14 checks passed
@matt-edmondson
matt-edmondson deleted the fix/437-worktree-rename branch October 6, 2026 12:32
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.

Commit prompt lists a phantom file when a rename is reported in the worktree status column (e.g. after git add -N)

2 participants