From 6c98bcfb382e30821c1432d810c535b24693aa0e Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 20 Aug 2026 20:16:27 +0200 Subject: [PATCH] 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 --- ...emove_content_change_from_renamed_file.go} | 66 +++++++++++-------- pkg/integration/tests/test_list.go | 2 +- 2 files changed, 39 insertions(+), 29 deletions(-) rename pkg/integration/tests/{patch_building/renamed_file_partial.go => main_view/remove_content_change_from_renamed_file.go} (52%) diff --git a/pkg/integration/tests/patch_building/renamed_file_partial.go b/pkg/integration/tests/main_view/remove_content_change_from_renamed_file.go similarity index 52% rename from pkg/integration/tests/patch_building/renamed_file_partial.go rename to pkg/integration/tests/main_view/remove_content_change_from_renamed_file.go index 3c37c13a2..dbcacb160 100644 --- a/pkg/integration/tests/patch_building/renamed_file_partial.go +++ b/pkg/integration/tests/main_view/remove_content_change_from_renamed_file.go @@ -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"), + ) }, }) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index 01a5b0870..05d491341 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -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,