Repository: jesseduffield/lazygit (language: go)

Issue:
Upstream reset offers local branch name instead of remote branch name
**Describe the bug**
Upstream reset offers local branch name instead of remote branch name.

**To Reproduce**
Steps to reproduce the behavior:

1. Checkout a remote branch `branch-remote`
2. Rename local branch using 'R' to `branch-local`
3. Click 'Upstream' then 'Reset'
4. The popup offers reset options using local branch name
5. Select any option (except 'Cancel')
6. Observe error: `fatal: ambiguous argument 'origin/branch-local': unknown revision or path not in the working tree.`

**Expected behavior**
Upstream reset actions should use remote branch name.

For comparison, upstream rebase actions properly use remote branch name.

**Screenshots**
N/A

**Version info:**
```
$ lazygit --version
commit=, build date=, build source=homebrew, version=0.44.1, os=linux, arch=amd64, git version=2.43.0
```

```
$ git --version
git version 2.43.0
```

**Additional context**
N/A

**Note:** please try updating to the latest version or [manually building](https://github.com/jesseduffield/lazygit/#manual) the latest `master` to see if the issue still occurs.

<!--
If you want to try and debug this issue yourself, you can run `lazygit --debug` in one terminal panel and `lazygit --logs` in another to view the logs.
-->



Discussion / hints:

Fix patch:
diff --git a/pkg/gui/controllers/branches_controller.go b/pkg/gui/controllers/branches_controller.go
index 9a1530971cd..244092681b0 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 01a9caf3a80..4fb2d5f529e 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})
 }


Test patch:
diff --git a/pkg/integration/tests/branch/rebase_to_upstream.go b/pkg/integration/tests/branch/rebase_to_upstream.go
index f8b2d6fd138..397a79d1e43 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 3cdbb561d80..c2ca41f4a3b 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")).