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/reset_upstream.go b/pkg/integration/tests/branch/reset_upstream.go deleted file mode 100644 index 70300c312..000000000 --- a/pkg/integration/tests/branch/reset_upstream.go +++ /dev/null @@ -1,36 +0,0 @@ -package branch - -import ( - "github.com/jesseduffield/lazygit/pkg/config" - . "github.com/jesseduffield/lazygit/pkg/integration/components" -) - -var ResetUpstream = NewIntegrationTest(NewIntegrationTestArgs{ - Description: "Reset the upstream of a branch", - ExtraCmdArgs: []string{}, - Skip: false, - SetupConfig: func(config *config.AppConfig) {}, - SetupRepo: func(shell *Shell) { - shell.EmptyCommit("one") - shell.CloneIntoRemote("origin") - shell.SetBranchUpstream("master", "origin/master") - }, - 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(), - ). - Press(keys.Branches.SetUpstream). - Tap(func() { - t.ExpectPopup().Menu(). - Title(Equals("Upstream options")). - Select(Contains("Unset upstream of selected branch")). - Confirm() - }). - Lines( - Contains("master").DoesNotContain("origin master").IsSelected(), - ) - }, -}) diff --git a/pkg/integration/tests/branch/unset_upstream.go b/pkg/integration/tests/branch/unset_upstream.go new file mode 100644 index 000000000..39454d2ac --- /dev/null +++ b/pkg/integration/tests/branch/unset_upstream.go @@ -0,0 +1,59 @@ +package branch + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var UnsetUpstream = NewIntegrationTest(NewIntegrationTestArgs{ + 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"). + 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 + SelectedLines( + Contains("master").Contains("origin master"), + ). + Press(keys.Branches.SetUpstream). + Tap(func() { + t.ExpectPopup().Menu(). + Title(Equals("Upstream options")). + Select(Contains("Unset upstream of selected branch")). + Confirm() + }). + 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() + }). + SelectedLines( + Contains("branch_to_remove").DoesNotContain("origin branch_to_remove").DoesNotContain("upstream gone"), + ) + }, +}) 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,