Keep partial rename patches on the focused diff

Selecting a rename's content changes must remain distinct from selecting
the file operation itself. Build and remove that partial patch through
the focused commit diff, and keep asserting that the rename stays in its
source commit after the content change is taken out.

Co-Authored-By: GitHub Copilot <copilot@github.com>
This commit is contained in:
Stefan Haller
2026-10-01 17:28:30 +02:00
co-authored by GitHub Copilot
parent e59185bdc7
commit 6c98bcfb38
2 changed files with 39 additions and 29 deletions
@@ -1,15 +1,17 @@
package patch_building
package main_view
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var RenamedFilePartial = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Select part of a renamed file's changes into a custom patch and remove it from the commit, keeping the rename in place",
var RemoveContentChangeFromRenamedFile = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Remove a renamed file's content change from a commit while keeping its rename",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupConfig: func(config *config.AppConfig) {
config.GetUserConfig().Gui.UseHunkModeInStagingView = false
},
SetupRepo: func(shell *Shell) {
shell.CreateFileAndAdd("original", "line1\nline2\nline3\nline4\nline5\n")
shell.Commit("first commit")
@@ -32,42 +34,50 @@ var RenamedFilePartial = NewIntegrationTest(NewIntegrationTestArgs{
Lines(
Contains("original → renamed").IsSelected(),
).
PressEnter()
Press(keys.Universal.FocusMainView)
// The main view shows the rename together with its content change.
t.Views().PatchBuilding().
t.Views().Main().
IsFocused().
Content(Contains("rename from original").Contains("rename to renamed")).
SelectedLines(Contains("-line2")).
Press(keys.Universal.ToggleRangeSelect).
Press(keys.Universal.NextItem).
SelectedLines(
Contains("-line2"),
Contains("+line2 changed"),
).
PressPrimaryAction()
t.Views().Information().Content(Contains("Building patch"))
// Only part of the file is in the patch, so the patch leaves the rename behind in
// the commit and carries the content change alone. The pane beside the diff shows
// it that way, over the name the file was renamed to.
t.Views().Secondary().
ContainsLines(
Contains("diff --git a/renamed b/renamed"),
Contains("index"),
Contains("--- a/renamed"),
Contains("+++ b/renamed"),
).
ContainsLines(
Contains(" line1"),
Contains("-line2"),
Contains("+line2 changed"),
Contains(" line3"),
).
// Add the hunk (a line selection, as opposed to adding the whole
// file), so this is a partial patch.
PressPrimaryAction()
t.Views().Information().Content(Contains("Building patch"))
)
t.Common().SelectPatchOption(Contains("Remove patch from original commit"))
// The rename is preserved; only the content change is gone, so the file
// is still shown as a rename but now has no content change.
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("original → renamed").IsSelected(),
)
t.Views().CommitFiles().Lines(
Contains("original → renamed").IsSelected(),
)
t.Views().Main().
IsFocused().
Content(DoesNotContain("line2 changed"))
t.Views().Commits().
Focus().
Lines(
Contains("rename with modification").IsSelected(),
Contains("first commit"),
)
t.Views().Commits().Lines(
Contains("rename with modification").IsSelected(),
Contains("first commit"),
)
},
})
+1 -1
View File
@@ -444,6 +444,7 @@ var tests = []*components.IntegrationTest{
main_view.PatchMarksShowWheneverTheirDiffIsOnScreen,
main_view.RangeSelectDiffLines,
main_view.RawFallbackUnderAnExternalDiff,
main_view.RemoveContentChangeFromRenamedFile,
main_view.RemoveLinesFromTheCustomPatch,
main_view.RemovePartOfAddedFileFromCommit,
main_view.RemovePatchFromCommit,
@@ -497,7 +498,6 @@ var tests = []*components.IntegrationTest{
misc.StartInGitDir,
patch_building.CopyRenamedFileDiff,
patch_building.RenameSimilarityThresholdChange,
patch_building.RenamedFilePartial,
patch_building.RenamedFileWhole,
patch_building.SelectAllFiles,
patch_building.SelectDirecoriesSharingPrefix,