diff --git a/pkg/integration/tests/branch/rebase_copied_branch.go b/pkg/integration/tests/branch/rebase_copied_branch.go new file mode 100644 index 000000000..162c69af7 --- /dev/null +++ b/pkg/integration/tests/branch/rebase_copied_branch.go @@ -0,0 +1,69 @@ +package branch + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var RebaseCopiedBranch = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Make a copy of a branch, rebase it, check that the original branch is unaffected", + ExtraCmdArgs: []string{}, + Skip: false, + GitVersion: AtLeast("2.38.0"), + SetupConfig: func(config *config.AppConfig) { + config.AppState.GitLogShowGraph = "never" + }, + SetupRepo: func(shell *Shell) { + shell. + EmptyCommit("master 1"). + EmptyCommit("master 2"). + NewBranchFrom("branch1", "master^"). + EmptyCommit("branch 1"). + EmptyCommit("branch 2"). + NewBranch("branch2") + + shell.SetConfig("rebase.updateRefs", "true") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Commits().Lines( + Contains("CI * branch 2"), + Contains("CI branch 1"), + Contains("CI master 1"), + ) + + t.Views().Branches(). + Focus(). + Lines( + Contains("branch2").IsSelected(), + Contains("branch1"), + Contains("master"), + ). + NavigateToLine(Contains("master")). + Press(keys.Branches.RebaseBranch). + Tap(func() { + t.ExpectPopup().Menu(). + Title(Equals("Rebase 'branch2' onto 'master'")). + Select(Contains("Simple rebase")). + Confirm() + }) + + t.Views().Commits().Lines( + Contains("CI * branch 2"), // wrong, don't want a star here + Contains("CI branch 1"), + Contains("CI master 2"), + Contains("CI master 1"), + ) + + t.Views().Branches(). + Focus(). + NavigateToLine(Contains("branch1")). + PressPrimaryAction() + + t.Views().Commits().Lines( + Contains("CI * branch 2"), // wrong, don't want a star here + Contains("CI branch 1"), + Contains("CI master 2"), // wrong, don't want this commit + Contains("CI master 1"), + ) + }, +}) diff --git a/pkg/integration/tests/interactive_rebase/drop_commit_in_copied_branch_with_update_ref.go b/pkg/integration/tests/interactive_rebase/drop_commit_in_copied_branch_with_update_ref.go new file mode 100644 index 000000000..567e746a5 --- /dev/null +++ b/pkg/integration/tests/interactive_rebase/drop_commit_in_copied_branch_with_update_ref.go @@ -0,0 +1,55 @@ +package interactive_rebase + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var DropCommitInCopiedBranchWithUpdateRef = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Drops a commit in a branch that is a copy of another branch, and verify that the other branch is left alone", + ExtraCmdArgs: []string{}, + Skip: false, + GitVersion: AtLeast("2.38.0"), + SetupConfig: func(config *config.AppConfig) { + config.AppState.GitLogShowGraph = "never" + }, + SetupRepo: func(shell *Shell) { + shell. + NewBranch("branch1"). + CreateNCommits(3). + NewBranch("branch2") + + shell.SetConfig("rebase.updateRefs", "true") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Commits(). + Focus(). + Lines( + Contains("CI * commit 03").IsSelected(), + Contains("CI commit 02"), + Contains("CI commit 01"), + ). + NavigateToLine(Contains("commit 02")). + Press(keys.Universal.Remove). + Tap(func() { + t.ExpectPopup().Confirmation(). + Title(Equals("Drop commit")). + Content(Equals("Are you sure you want to drop the selected commit(s)?")). + Confirm() + }). + Lines( + Contains("CI * commit 03"), // don't want a star here because branch1 should no longer be pointing to it + Contains("CI commit 01"), + ) + + t.Views().Branches(). + Focus(). + NavigateToLine(Contains("branch1")). + PressPrimaryAction() + + t.Views().Commits().Lines( + Contains("CI * commit 03"), // branch1 has changed like branch2, but shouldn't have + Contains("CI commit 01"), + ) + }, +}) diff --git a/pkg/integration/tests/interactive_rebase/interactive_rebase_of_copied_branch.go b/pkg/integration/tests/interactive_rebase/interactive_rebase_of_copied_branch.go new file mode 100644 index 000000000..d29cbe102 --- /dev/null +++ b/pkg/integration/tests/interactive_rebase/interactive_rebase_of_copied_branch.go @@ -0,0 +1,41 @@ +package interactive_rebase + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var InteractiveRebaseOfCopiedBranch = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Check that interactively rebasing a branch that is a copy of another branch doesn't affect the original branch", + ExtraCmdArgs: []string{}, + Skip: false, + GitVersion: AtLeast("2.38.0"), + SetupConfig: func(config *config.AppConfig) { + config.AppState.GitLogShowGraph = "never" + }, + SetupRepo: func(shell *Shell) { + shell. + NewBranch("branch1"). + CreateNCommits(3). + NewBranch("branch2") + + shell.SetConfig("rebase.updateRefs", "true") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Commits(). + Focus(). + Lines( + Contains("CI * commit 03"), + Contains("CI commit 02"), + Contains("CI commit 01"), + ). + NavigateToLine(Contains("commit 01")). + Press(keys.Universal.Edit). + Lines( + Contains("update-ref").Contains("branch1"), // we don't want this + Contains("pick").Contains("CI commit 03"), + Contains("pick").Contains("CI commit 02"), + Contains("CI <-- YOU ARE HERE --- commit 01"), + ) + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index cb1a66ac5..cdbcc7871 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -47,6 +47,7 @@ var tests = []*components.IntegrationTest{ branch.RebaseAbortOnConflict, branch.RebaseAndDrop, branch.RebaseCancelOnConflict, + branch.RebaseCopiedBranch, branch.RebaseDoesNotAutosquash, branch.RebaseFromMarkedBase, branch.RebaseToUpstream, @@ -170,6 +171,7 @@ var tests = []*components.IntegrationTest{ interactive_rebase.AmendNonHeadCommitDuringRebase, interactive_rebase.DeleteUpdateRefTodo, interactive_rebase.DontShowBranchHeadsForTodoItems, + interactive_rebase.DropCommitInCopiedBranchWithUpdateRef, interactive_rebase.DropTodoCommitWithUpdateRef, interactive_rebase.DropWithCustomCommentChar, interactive_rebase.EditFirstCommit, @@ -178,6 +180,7 @@ var tests = []*components.IntegrationTest{ interactive_rebase.EditTheConflCommit, interactive_rebase.FixupFirstCommit, interactive_rebase.FixupSecondCommit, + interactive_rebase.InteractiveRebaseOfCopiedBranch, interactive_rebase.MidRebaseRangeSelect, interactive_rebase.Move, interactive_rebase.MoveInRebase,