Move partial-patch destination tests onto the commit diff

Line-level patch moves must keep their behavior for added and deleted
files, adjacent additions, stacked branches, and conflicting earlier
destinations. Select those lines directly in the focused diff so only
the intended changes move and file-level metadata stays with the source
when appropriate.

Co-Authored-By: GitHub Copilot <copilot@github.com>
This commit is contained in:
Stefan Haller
2026-09-27 18:26:56 +02:00
co-authored by GitHub Copilot
parent 505b464e89
commit 3b5bfe4529
7 changed files with 70 additions and 85 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 MoveToLaterCommitPartialHunk = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Move a patch from a commit to a later commit, with only parts of a hunk in the patch",
var MovePartialPatchToLaterCommit = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Move one of two adjacent additions from a commit to a later commit",
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("file1", "")
shell.Commit("first commit")
@@ -36,23 +38,15 @@ var MoveToLaterCommitPartialHunk = NewIntegrationTest(NewIntegrationTestArgs{
Lines(
Contains("file1").IsSelected(),
).
PressEnter()
Press(keys.Universal.FocusMainView)
t.Views().PatchBuilding().
t.Views().Main().
IsFocused().
PressPrimaryAction().
PressEscape()
SelectedLines(Contains("+1st line")).
PressPrimaryAction()
t.Views().Information().Content(Contains("Building patch"))
t.Views().CommitFiles().
IsFocused().
PressEscape()
t.Views().Commits().
IsFocused().
SelectPreviousItem()
t.Views().Commits().Focus().SelectPreviousItem()
t.Common().SelectPatchOption(Contains("Move patch to selected commit"))
t.Views().Commits().
@@ -73,8 +67,7 @@ var MoveToLaterCommitPartialHunk = NewIntegrationTest(NewIntegrationTestArgs{
).
SelectNextItem().
Tap(func() {
t.Views().Main().
Content(Contains("+1st line\n 2nd line"))
t.Views().Main().Content(Contains("+1st line\n 2nd line"))
}).
PressEscape()
@@ -89,9 +82,7 @@ var MoveToLaterCommitPartialHunk = NewIntegrationTest(NewIntegrationTestArgs{
Contains("file1").IsSelected(),
).
Tap(func() {
t.Views().Main().
Content(Contains("+2nd line").
DoesNotContain("1st line"))
t.Views().Main().Content(Contains("+2nd line").DoesNotContain("1st line"))
})
},
})
@@ -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 MoveToNewCommitPartialHunk = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Move a patch from a commit to a new commit, with only parts of a hunk in the patch",
var MovePartialPatchToNewCommit = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Move one of two adjacent additions from a commit to a new commit",
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("file1", "")
shell.Commit("first commit")
@@ -36,14 +38,14 @@ var MoveToNewCommitPartialHunk = NewIntegrationTest(NewIntegrationTestArgs{
Lines(
Contains("file1").IsSelected(),
).
PressEnter()
Press(keys.Universal.FocusMainView)
t.Views().PatchBuilding().
t.Views().Main().
IsFocused().
SelectedLines(Contains("+1st line")).
PressPrimaryAction()
t.Views().Information().Content(Contains("Building patch"))
t.Common().SelectPatchOption(Contains("Move patch into new commit after the original commit"))
t.ExpectPopup().CommitMessagePanel().
@@ -66,19 +68,12 @@ var MoveToNewCommitPartialHunk = NewIntegrationTest(NewIntegrationTestArgs{
Contains("file1").IsSelected(),
).
Tap(func() {
t.Views().Main().
Content(Contains("+1st line\n 2nd line"))
t.Views().Main().Content(Contains("+1st line\n 2nd line"))
}).
PressEscape()
t.Views().Commits().
IsFocused().
Lines(
Contains("third commit"),
Contains("new commit").IsSelected(),
Contains("commit to move from"),
Contains("first commit"),
).
SelectNextItem().
PressEnter()
@@ -88,9 +83,7 @@ var MoveToNewCommitPartialHunk = NewIntegrationTest(NewIntegrationTestArgs{
Contains("file1").IsSelected(),
).
Tap(func() {
t.Views().Main().
Content(Contains("+2nd line").
DoesNotContain("1st line"))
t.Views().Main().Content(Contains("+2nd line").DoesNotContain("1st line"))
})
},
})
@@ -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 MoveToEarlierCommitFromAddedFile = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Move a patch from a file that was added in a commit to an earlier commit",
var MovePatchFromAddedFileToEarlierCommit = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Move part of an added file from a commit to an earlier commit",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupConfig: func(config *config.AppConfig) {
config.GetUserConfig().Gui.UseHunkModeInStagingView = false
},
SetupRepo: func(shell *Shell) {
shell.EmptyCommit("first commit")
shell.EmptyCommit("destination commit")
@@ -31,23 +33,18 @@ var MoveToEarlierCommitFromAddedFile = NewIntegrationTest(NewIntegrationTestArgs
Lines(
Contains("A file").IsSelected(),
).
PressEnter()
Press(keys.Universal.FocusMainView)
t.Views().PatchBuilding().
t.Views().Main().
IsFocused().
SelectNextItem().
NavigateToLine(Contains("+2nd line")).
PressPrimaryAction()
t.Views().Information().Content(Contains("Building patch"))
t.Views().Commits().
Focus().
SelectNextItem()
t.Views().Commits().Focus().SelectNextItem()
t.Common().SelectPatchOption(Contains("Move patch to selected commit"))
// This results in a conflict at the commit we're moving from, because
// it tries to add a file that already exists
// The source commit tries to add a file that the moved line now causes to exist.
t.Common().AcknowledgeConflicts()
t.Views().Files().
@@ -69,7 +66,7 @@ var MoveToEarlierCommitFromAddedFile = NewIntegrationTest(NewIntegrationTestArgs
Contains(">>>>>>>"),
).
SelectNextItem().
PressPrimaryAction() // choose the version with all three lines
PressPrimaryAction()
t.Common().ContinueOnConflictsResolved("rebase")
@@ -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 MoveToNewCommitFromAddedFile = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Move a patch from a file that was added in a commit to a new commit",
var MovePatchFromAddedFileToNewCommit = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Move part of an added file from a commit to a new commit",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupConfig: func(config *config.AppConfig) {
config.GetUserConfig().Gui.UseHunkModeInStagingView = false
},
SetupRepo: func(shell *Shell) {
shell.EmptyCommit("first commit")
@@ -30,15 +32,14 @@ var MoveToNewCommitFromAddedFile = NewIntegrationTest(NewIntegrationTestArgs{
Lines(
Contains("file1").IsSelected(),
).
PressEnter()
Press(keys.Universal.FocusMainView)
t.Views().PatchBuilding().
t.Views().Main().
IsFocused().
SelectNextItem().
NavigateToLine(Contains("+2nd line")).
PressPrimaryAction()
t.Views().Information().Content(Contains("Building patch"))
t.Common().SelectPatchOption(Contains("Move patch into new commit after the original commit"))
t.ExpectPopup().CommitMessagePanel().
@@ -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 MoveToNewCommitFromDeletedFile = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Move a patch from a file that was deleted in a commit to a new commit",
var MovePatchFromDeletedFileToNewCommit = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Move part of a deleted file from a commit to a new commit",
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("file1", "1st line\n2nd line\n3rd line\n")
shell.Commit("first commit")
@@ -30,15 +32,14 @@ var MoveToNewCommitFromDeletedFile = NewIntegrationTest(NewIntegrationTestArgs{
Lines(
Contains("D file1").IsSelected(),
).
PressEnter()
Press(keys.Universal.FocusMainView)
t.Views().PatchBuilding().
t.Views().Main().
IsFocused().
SelectNextItem().
NavigateToLine(Contains("-2nd line")).
PressPrimaryAction()
t.Views().Information().Content(Contains("Building patch"))
t.Common().SelectPatchOption(Contains("Move patch into new commit after the original commit"))
t.ExpectPopup().CommitMessagePanel().
@@ -74,7 +75,6 @@ var MoveToNewCommitFromDeletedFile = NewIntegrationTest(NewIntegrationTestArgs{
t.Views().CommitFiles().
IsFocused().
Lines(
// In the original commit the file is no longer deleted, but modified
Contains("M file1").IsSelected(),
).
Tap(func() {
@@ -1,17 +1,18 @@
package patch_building
package main_view
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var MoveToNewCommitInLastCommitOfStackedBranch = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Move a patch from a commit to a new commit, in the last commit of a branch in the middle of a stack",
var MovePatchToNewCommitInStackedBranch = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Move a patch to a new commit after the last commit of a branch in the middle of a stack",
ExtraCmdArgs: []string{},
Skip: false,
GitVersion: AtLeast("2.38.0"),
SetupConfig: func(config *config.AppConfig) {
config.GetUserConfig().Git.Log.ShowGraph = "never"
config.GetUserConfig().Gui.UseHunkModeInStagingView = false
},
SetupRepo: func(shell *Shell) {
shell.
@@ -46,12 +47,14 @@ var MoveToNewCommitInLastCommitOfStackedBranch = NewIntegrationTest(NewIntegrati
Equals(" A file1"),
Equals(" A file2"),
).
SelectNextItem().
PressPrimaryAction().
PressEscape()
Press(keys.Universal.FocusMainView)
t.Views().Main().
IsFocused().
SelectedLines(Contains("+file1 content")).
PressPrimaryAction()
t.Views().Information().Content(Contains("Building patch"))
t.Common().SelectPatchOption(Contains("Move patch into new commit after the original commit"))
t.ExpectPopup().CommitMessagePanel().
+6 -6
View File
@@ -411,7 +411,12 @@ var tests = []*components.IntegrationTest{
main_view.MoveMultiFileRangeToIndex,
main_view.MovePartOfAdjacentAddedLinesToIndex,
main_view.MovePartialPatchToIndex,
main_view.MovePartialPatchToLaterCommit,
main_view.MovePartialPatchToNewCommit,
main_view.MovePatchFromAddedFileToEarlierCommit,
main_view.MovePatchFromAddedFileToIndexWithConflict,
main_view.MovePatchFromAddedFileToNewCommit,
main_view.MovePatchFromDeletedFileToNewCommit,
main_view.MovePatchToEarlierCommit,
main_view.MovePatchToIndex,
main_view.MovePatchToIndexWithConflict,
@@ -420,6 +425,7 @@ var tests = []*components.IntegrationTest{
main_view.MovePatchToLaterCommit,
main_view.MovePatchToNewCommit,
main_view.MovePatchToNewCommitBefore,
main_view.MovePatchToNewCommitInStackedBranch,
main_view.NavigateByHunkAndFile,
main_view.NoSelectionOverABinaryDiff,
main_view.NoSelectionOverACommitLog,
@@ -483,12 +489,6 @@ var tests = []*components.IntegrationTest{
patch_building.CopyRenamedFileDiff,
patch_building.DiscardLinesFromCommit,
patch_building.EditLineInPatchBuildingPanel,
patch_building.MoveToEarlierCommitFromAddedFile,
patch_building.MoveToLaterCommitPartialHunk,
patch_building.MoveToNewCommitFromAddedFile,
patch_building.MoveToNewCommitFromDeletedFile,
patch_building.MoveToNewCommitInLastCommitOfStackedBranch,
patch_building.MoveToNewCommitPartialHunk,
patch_building.RemoveFromCommit,
patch_building.RemovePartsOfAddedFile,
patch_building.RenameSimilarityThresholdChange,