mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-08-28 10:15:32 -05:00
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>
61 lines
1.7 KiB
Go
61 lines
1.7 KiB
Go
package patch_building
|
|
|
|
import (
|
|
"github.com/jesseduffield/lazygit/pkg/config"
|
|
. "github.com/jesseduffield/lazygit/pkg/integration/components"
|
|
)
|
|
|
|
// note: this is required to simulate the clipboard during CI
|
|
func expectClipboard(t *TestDriver, matcher *TextMatcher) {
|
|
defer t.Shell().DeleteFile("clipboard")
|
|
|
|
t.FileSystem().FileContent("clipboard", matcher)
|
|
}
|
|
|
|
var CopyRenamedFileDiff = NewIntegrationTest(NewIntegrationTestArgs{
|
|
Description: "Copy the diff of a renamed file to the clipboard; the diff shows the rename rather than a delete and add",
|
|
ExtraCmdArgs: []string{},
|
|
Skip: false,
|
|
SetupConfig: func(config *config.AppConfig) {
|
|
config.GetUserConfig().OS.CopyToClipboardCmd = "printf '%s' {{text}} > clipboard"
|
|
},
|
|
SetupRepo: func(shell *Shell) {
|
|
shell.CreateFileAndAdd("original", "line1\nline2\nline3\nline4\nline5\n")
|
|
shell.Commit("first commit")
|
|
|
|
shell.RenameFileInGit("original", "renamed")
|
|
shell.UpdateFileAndAdd("renamed", "line1\nline2 changed\nline3\nline4\nline5\n")
|
|
shell.Commit("rename with modification")
|
|
},
|
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
|
t.Views().Commits().
|
|
Focus().
|
|
Lines(
|
|
Contains("rename with modification").IsSelected(),
|
|
Contains("first commit"),
|
|
).
|
|
PressEnter()
|
|
|
|
t.Views().CommitFiles().
|
|
IsFocused().
|
|
Lines(
|
|
Contains("original → renamed").IsSelected(),
|
|
).
|
|
Press(keys.Files.CopyFileInfoToClipboard)
|
|
|
|
t.ExpectPopup().Menu().
|
|
Title(Equals("Copy to clipboard")).
|
|
Select(Contains("Diff of selected file")).
|
|
Confirm()
|
|
|
|
t.ExpectToast(Contains("File diff copied to clipboard"))
|
|
|
|
expectClipboard(t,
|
|
Contains("rename from original").
|
|
Contains("rename to renamed").
|
|
Contains("-line2").
|
|
Contains("+line2 changed"),
|
|
)
|
|
},
|
|
})
|