jesseduffield.lazygit/pkg/commands/models
Stefan Haller f84ada4941 Show renamed files in the custom patch builder
When loading the files of a commit we passed --no-renames, so a rename
showed up as a separate delete and add rather than a single R entry.
That made it impossible to work with a rename that also modifies the
file: the modifications were spread across a full deletion and a full
addition instead of appearing as the handful of lines that actually
changed. The staging view already shows renames and lets you stage
their hunks, so there was no good reason for the patch builder to
differ; the flag was only there because the commit-file parser couldn't
cope with the rename record format.

Switch the commit-file loader and the per-file diff to --find-renames,
teach the parser about the rename record (a status followed by two
paths), and carry the previous path through the patch builder so the
diff for a rename is loaded with both paths, which is what makes git
emit the rename in the first place.

A whole-file selection keeps the rename in the header, so the rename
moves or is discarded together with the file's contents. A partial
selection instead strips the rename metadata and points the header at
the new path, so applying the patch only changes the contents and
leaves the rename in place; the blob index line is kept so that a 3-way
apply can still fall back to a blob merge.

Discarding a renamed file from a commit now discards both the new and
the old path, so the new file is removed and the old one is restored.

Changing the rename similarity threshold refreshes the commit files
panel too, not just the files panel, so that a rename can turn into a
delete and add or back. It is disabled while building a patch, however,
because the patch builder caches each file's diff by path and would
desync if a rename changed into a delete and add underneath it.

Finally, copying a file's diff from the commit files panel now passes
both paths for a rename, so the copied diff shows the rename instead of
a new-file add.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-04 13:05:09 +02:00
..
author.go Keep track of authors across local commits and branch commits for suggestions 2023-07-22 10:47:04 +10:00
branch.go Add ShortRefName to Ref interface 2024-08-28 18:27:52 +02:00
commit.go Add HeadCommitIdx helper function 2026-06-22 09:16:57 +02:00
commit_file.go Show renamed files in the custom patch builder 2026-07-04 13:05:09 +02:00
commit_test.go Add HeadCommitIdx helper function 2026-06-22 09:16:57 +02:00
file.go Better main view display for conflicing files 2025-04-09 10:27:57 +02:00
github.go Add GitHub commands and model for fetching PR status 2026-04-01 09:13:55 +02:00
ref.go Move the Ref interface from gui/types to models 2025-07-31 15:21:34 +02:00
remote.go Add PushUrls field to models.Remote 2026-05-04 13:09:47 +02:00
remote_branch.go Add ShortRefName to Ref interface 2024-08-28 18:27:52 +02:00
stash_entry.go Add hash field to models.StashEntry 2025-08-25 19:23:30 +02:00
submodule_config.go Show all submodules recursively 2024-03-07 20:16:28 +01:00
tag.go Revert "Add IsAnnotated field to models.Tag struct" 2025-07-28 10:53:51 +02:00
working_tree_state.go Make WorkingTreeState a struct, and add cherry-picking and reverting states 2025-04-20 15:53:17 +02:00
worktree.go Show branch name and detached HEAD in worktrees tab 2026-03-08 12:51:46 +01:00