diff --git a/pkg/gui/controllers/branches_controller.go b/pkg/gui/controllers/branches_controller.go index 9a1530971..244092681 100644 --- a/pkg/gui/controllers/branches_controller.go +++ b/pkg/gui/controllers/branches_controller.go @@ -194,6 +194,10 @@ func (self *BranchesController) GetOnRenderToMain() func() { } func (self *BranchesController) viewUpstreamOptions(selectedBranch *models.Branch) error { + upstream := lo.Ternary(selectedBranch.RemoteBranchStoredLocally(), + selectedBranch.ShortUpstreamRefName(), + self.c.Tr.UpstreamGenericName) + viewDivergenceItem := &types.MenuItem{ LabelColumns: []string{self.c.Tr.ViewDivergenceFromUpstream}, OnPress: func() error { @@ -204,7 +208,7 @@ func (self *BranchesController) viewUpstreamOptions(selectedBranch *models.Branc return self.c.Helpers().SubCommits.ViewSubCommits(helpers.ViewSubCommitsOpts{ Ref: branch, - TitleRef: fmt.Sprintf("%s <-> %s", branch.RefName(), branch.ShortUpstreamRefName()), + TitleRef: fmt.Sprintf("%s <-> %s", branch.RefName(), upstream), RefToShowDivergenceFrom: branch.FullUpstreamRefName(), Context: self.context(), ShowBranchHeads: false, @@ -293,9 +297,6 @@ func (self *BranchesController) viewUpstreamOptions(selectedBranch *models.Branc Key: 's', } - upstream := lo.Ternary(selectedBranch.RemoteBranchStoredLocally(), - fmt.Sprintf("%s/%s", selectedBranch.UpstreamRemote, selectedBranch.Name), - self.c.Tr.UpstreamGenericName) upstreamResetOptions := utils.ResolvePlaceholderString( self.c.Tr.ViewUpstreamResetOptions, map[string]string{"upstream": upstream}, @@ -332,7 +333,7 @@ func (self *BranchesController) viewUpstreamOptions(selectedBranch *models.Branc LabelColumns: []string{upstreamRebaseOptions}, OpensMenu: true, OnPress: func() error { - if err := self.c.Helpers().MergeAndRebase.RebaseOntoRef(selectedBranch.ShortUpstreamRefName()); err != nil { + if err := self.c.Helpers().MergeAndRebase.RebaseOntoRef(upstream); err != nil { return err } return nil diff --git a/pkg/integration/components/shell.go b/pkg/integration/components/shell.go index 01a9caf3a..4fb2d5f52 100644 --- a/pkg/integration/components/shell.go +++ b/pkg/integration/components/shell.go @@ -142,6 +142,10 @@ func (self *Shell) NewBranchFrom(name string, from string) *Shell { return self.RunCommand([]string{"git", "checkout", "-b", name, from}) } +func (self *Shell) RenameCurrentBranch(newName string) *Shell { + return self.RunCommand([]string{"git", "branch", "-m", newName}) +} + func (self *Shell) Checkout(name string) *Shell { return self.RunCommand([]string{"git", "checkout", name}) } diff --git a/pkg/integration/tests/branch/rebase_to_upstream.go b/pkg/integration/tests/branch/rebase_to_upstream.go index f8b2d6fd1..397a79d1e 100644 --- a/pkg/integration/tests/branch/rebase_to_upstream.go +++ b/pkg/integration/tests/branch/rebase_to_upstream.go @@ -16,8 +16,9 @@ var RebaseToUpstream = NewIntegrationTest(NewIntegrationTestArgs{ EmptyCommit("ensure-master"). EmptyCommit("to-be-added"). // <- this will only exist remotely PushBranchAndSetUpstream("origin", "master"). + RenameCurrentBranch("master-local"). HardReset("HEAD~1"). - NewBranchFrom("base-branch", "master"). + NewBranchFrom("base-branch", "master-local"). EmptyCommit("base-branch-commit"). NewBranch("target"). EmptyCommit("target-commit") @@ -34,13 +35,13 @@ var RebaseToUpstream = NewIntegrationTest(NewIntegrationTestArgs{ Lines( Contains("target").IsSelected(), Contains("base-branch"), - Contains("master"), + Contains("master-local"), ). SelectNextItem(). Lines( Contains("target"), Contains("base-branch").IsSelected(), - Contains("master"), + Contains("master-local"), ). Press(keys.Branches.SetUpstream). Tap(func() { @@ -58,7 +59,7 @@ var RebaseToUpstream = NewIntegrationTest(NewIntegrationTestArgs{ Lines( Contains("target"), Contains("base-branch"), - Contains("master").IsSelected(), + Contains("master-local").IsSelected(), ). Press(keys.Branches.SetUpstream). Tap(func() { diff --git a/pkg/integration/tests/branch/reset_to_upstream.go b/pkg/integration/tests/branch/reset_to_upstream.go index 3cdbb561d..c2ca41f4a 100644 --- a/pkg/integration/tests/branch/reset_to_upstream.go +++ b/pkg/integration/tests/branch/reset_to_upstream.go @@ -19,6 +19,7 @@ var ResetToUpstream = NewIntegrationTest(NewIntegrationTestArgs{ NewBranch("soft-branch"). EmptyCommit("soft commit"). PushBranchAndSetUpstream("origin", "soft-branch"). + RenameCurrentBranch("soft-branch-local"). NewBranch("base"). EmptyCommit("base-branch commit"). CreateFile("file-1", "content"). @@ -33,7 +34,7 @@ var ResetToUpstream = NewIntegrationTest(NewIntegrationTestArgs{ Focus(). Lines( Contains("base").IsSelected(), - Contains("soft-branch"), + Contains("soft-branch-local"), Contains("hard-branch"), ). Press(keys.Branches.SetUpstream). @@ -51,7 +52,7 @@ var ResetToUpstream = NewIntegrationTest(NewIntegrationTestArgs{ SelectNextItem(). Lines( Contains("base"), - Contains("soft-branch").IsSelected(), + Contains("soft-branch-local").IsSelected(), Contains("hard-branch"), ). Press(keys.Branches.SetUpstream). @@ -80,7 +81,7 @@ var ResetToUpstream = NewIntegrationTest(NewIntegrationTestArgs{ Focus(). Lines( Contains("base"), - Contains("soft-branch").IsSelected(), + Contains("soft-branch-local").IsSelected(), Contains("hard-branch"), ). NavigateToLine(Contains("hard-branch")).