From bb705d91a44bfe877edb40dbf4d4f164ad923d7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luka=20Marku=C5=A1i=C4=87?= Date: Sun, 22 Oct 2023 12:00:22 +0200 Subject: [PATCH 1/3] Rename integration test "ResetUpstream" We are unsetting upstream in it, not resetting to upstream --- .../tests/branch/{reset_upstream.go => unset_upstream.go} | 2 +- pkg/integration/tests/test_list.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename pkg/integration/tests/branch/{reset_upstream.go => unset_upstream.go} (94%) diff --git a/pkg/integration/tests/branch/reset_upstream.go b/pkg/integration/tests/branch/unset_upstream.go similarity index 94% rename from pkg/integration/tests/branch/reset_upstream.go rename to pkg/integration/tests/branch/unset_upstream.go index 70300c312..c38c0cd58 100644 --- a/pkg/integration/tests/branch/reset_upstream.go +++ b/pkg/integration/tests/branch/unset_upstream.go @@ -5,7 +5,7 @@ import ( . "github.com/jesseduffield/lazygit/pkg/integration/components" ) -var ResetUpstream = NewIntegrationTest(NewIntegrationTestArgs{ +var UnsetUpstream = NewIntegrationTest(NewIntegrationTestArgs{ Description: "Reset the upstream of a branch", ExtraCmdArgs: []string{}, Skip: false, diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index cea838380..5716507f8 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -52,10 +52,10 @@ var tests = []*components.IntegrationTest{ branch.Rename, branch.Reset, branch.ResetToUpstream, - branch.ResetUpstream, branch.SetUpstream, branch.ShowDivergenceFromUpstream, branch.Suggestions, + branch.UnsetUpstream, cherry_pick.CherryPick, cherry_pick.CherryPickConflicts, cherry_pick.CherryPickDuringRebase, From e0fc8fe25b9298b630b9de4558fbd698c8b33b6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luka=20Marku=C5=A1i=C4=87?= Date: Sat, 4 Nov 2023 23:19:38 +0100 Subject: [PATCH 2/3] Introduce failing "UnsetUpstream" test --- .../tests/branch/unset_upstream.go | 43 +++++++++++++++---- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/pkg/integration/tests/branch/unset_upstream.go b/pkg/integration/tests/branch/unset_upstream.go index c38c0cd58..1d4746fd3 100644 --- a/pkg/integration/tests/branch/unset_upstream.go +++ b/pkg/integration/tests/branch/unset_upstream.go @@ -6,21 +6,27 @@ import ( ) var UnsetUpstream = NewIntegrationTest(NewIntegrationTestArgs{ - Description: "Reset the upstream of a branch", + Description: "Unset upstream of selected branch, both when it exists and when it doesn't", ExtraCmdArgs: []string{}, Skip: false, SetupConfig: func(config *config.AppConfig) {}, SetupRepo: func(shell *Shell) { - shell.EmptyCommit("one") - shell.CloneIntoRemote("origin") - shell.SetBranchUpstream("master", "origin/master") + shell. + EmptyCommit("one"). + NewBranch("branch_to_remove"). + Checkout("master"). + CloneIntoRemote("origin"). + SetBranchUpstream("master", "origin/master"). + SetBranchUpstream("branch_to_remove", "origin/branch_to_remove"). + // to get the "(upstream gone)" branch status + RunCommand([]string{"git", "push", "origin", "--delete", "branch_to_remove"}) }, Run: func(t *TestDriver, keys config.KeybindingConfig) { t.Views().Branches(). Focus(). Press(keys.Universal.NextScreenMode). // we need to enlargen the window to see the upstream - Lines( - Contains("master").Contains("origin master").IsSelected(), + SelectedLines( + Contains("master").Contains("origin master"), ). Press(keys.Branches.SetUpstream). Tap(func() { @@ -29,8 +35,29 @@ var UnsetUpstream = NewIntegrationTest(NewIntegrationTestArgs{ Select(Contains("Unset upstream of selected branch")). Confirm() }). - Lines( - Contains("master").DoesNotContain("origin master").IsSelected(), + SelectedLines( + Contains("master").DoesNotContain("origin master"), + ) + + t.Views().Branches(). + Focus(). + SelectNextItem(). + SelectedLines( + Contains("branch_to_remove").Contains("origin branch_to_remove").Contains("upstream gone"), + ). + Press(keys.Branches.SetUpstream). + Tap(func() { + t.ExpectPopup().Menu(). + Title(Equals("Upstream options")). + Select(Contains("Unset upstream of selected branch")). + Confirm() + t.ExpectPopup().Alert(). + Title(Equals("Error")). + Content(Equals("The selected branch has no upstream (or the upstream is not stored locally)")). + Cancel() + }). + SelectedLines( + Contains("branch_to_remove").Contains("origin branch_to_remove").Contains("upstream gone"), ) }, }) From d145e818d04f5788ca29a5bb8d84f1ecad9c8f5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luka=20Marku=C5=A1i=C4=87?= Date: Sat, 4 Nov 2023 17:48:31 +0100 Subject: [PATCH 3/3] Fix unsetting upstream when it doesn't exist --- pkg/gui/controllers/branches_controller.go | 5 ++++- pkg/integration/tests/branch/unset_upstream.go | 6 +----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/pkg/gui/controllers/branches_controller.go b/pkg/gui/controllers/branches_controller.go index 403c51b4f..3de005a2b 100644 --- a/pkg/gui/controllers/branches_controller.go +++ b/pkg/gui/controllers/branches_controller.go @@ -257,9 +257,12 @@ func (self *BranchesController) viewUpstreamOptions(selectedBranch *models.Branc Key: 'r', } + if !selectedBranch.IsTrackingRemote() { + unsetUpstreamItem.DisabledReason = self.c.Tr.UpstreamNotSetError + } + if !selectedBranch.RemoteBranchStoredLocally() { viewDivergenceItem.DisabledReason = self.c.Tr.UpstreamNotSetError - unsetUpstreamItem.DisabledReason = self.c.Tr.UpstreamNotSetError upstreamResetItem.DisabledReason = self.c.Tr.UpstreamNotSetError upstreamRebaseItem.DisabledReason = self.c.Tr.UpstreamNotSetError } diff --git a/pkg/integration/tests/branch/unset_upstream.go b/pkg/integration/tests/branch/unset_upstream.go index 1d4746fd3..39454d2ac 100644 --- a/pkg/integration/tests/branch/unset_upstream.go +++ b/pkg/integration/tests/branch/unset_upstream.go @@ -51,13 +51,9 @@ var UnsetUpstream = NewIntegrationTest(NewIntegrationTestArgs{ Title(Equals("Upstream options")). Select(Contains("Unset upstream of selected branch")). Confirm() - t.ExpectPopup().Alert(). - Title(Equals("Error")). - Content(Equals("The selected branch has no upstream (or the upstream is not stored locally)")). - Cancel() }). SelectedLines( - Contains("branch_to_remove").Contains("origin branch_to_remove").Contains("upstream gone"), + Contains("branch_to_remove").DoesNotContain("origin branch_to_remove").DoesNotContain("upstream gone"), ) }, })