Repository: jesseduffield/lazygit
File: pkg/gui/controllers/branches_controller.go (Go)

Code before:
						return self.c.Error(err)
					}
					return nil
				})
			},
			Key: 's',
		},
	}

	if selectedBranch.IsTrackingRemote() {
		options = append(options, &types.MenuItem{
			LabelColumns: []string{self.c.Tr.ViewUpstreamResetOptions},
			OpensMenu:    true,
			OnPress: func() error {
				err := self.c.Helpers().Refs.CreateGitResetMenu(fmt.Sprintf("%s/%s", selectedBranch.UpstreamRemote, selectedBranch.Name))
				if err != nil {
					return self.c.Error(err)
				}
				return nil
			},
			Key: 'g',
		})
	}

	return self.c.Menu(types.CreateMenuOptions{
		Title: self.c.Tr.Actions.SetUnsetUpstream,
		Items: options,
	})
}

func (self *BranchesController) Context() types.Context {
	return self.context()
}

func (self *BranchesController) context() *context.BranchesContext {
	return self.c.Contexts().Branches
}

func (self *BranchesController) press(selectedBranch *models.Branch) error {
	if selectedBranch == self.c.Helpers().Refs.GetCheckedOutRef() {
		return self.c.ErrorMsg(self.c.Tr.AlreadyCheckedOutBranch)
	}

	worktreeForRef, ok := self.worktreeForBranch(selectedBranch)
	if ok && !worktreeForRef.IsCurrent {
		return self.promptToCheckoutWorktree(worktreeForRef)
	}

	self.c.LogAction(self.c.Tr.Actions.CheckoutBranch)
	return self.c.Helpers().Refs.CheckoutRef(selectedBranch.Name, types.CheckoutRefOptions{})
}

Review comment (suggestion):
Now that we're doing more than just setting/unsetting the upstream in this menu, can we:
* change the menu title to be 'Upstream options'
* update the keybinding to have the label 'View upstream options'
* Give the keybinding a tooltip saying 'View options relating to the branch's upstream e.g. setting/unsetting the upstream and resetting to the upstream'

Code after:
				return nil
			},
			Key: 'u',
		},
		{
			LabelColumns: []string{self.c.Tr.SetUpstream},
			OnPress: func() error {
				return self.c.Helpers().Upstream.PromptForUpstreamWithoutInitialContent(selectedBranch, func(upstream string) error {
					upstreamRemote, upstreamBranch, err := self.c.Helpers().Upstream.ParseUpstream(upstream)
					if err != nil {
						return self.c.Error(err)
					}

					if err := self.c.Git().Branch.SetUpstream(upstreamRemote, upstreamBranch, selectedBranch.Name); err != nil {
						return self.c.Error(err)
					}
					if err := self.c.Refresh(types.RefreshOptions{
						Mode: types.SYNC,
						Scope: []types.RefreshableView{
							types.BRANCHES,
							types.COMMITS,
						},
					}); err != nil {
						return self.c.Error(err)
					}
					return nil
				})
			},
			Key: 's',
		},
	}

	if selectedBranch.IsTrackingRemote() {
		upstream := fmt.Sprintf("%s/%s", selectedBranch.UpstreamRemote, selectedBranch.Name)
		upstreamResetOptions := utils.ResolvePlaceholderString(
			self.c.Tr.ViewUpstreamResetOptions,
			map[string]string{"upstream": upstream},
		)
		upstreamResetTooltip := utils.ResolvePlaceholderString(
			self.c.Tr.ViewUpstreamResetOptionsTooltip,
			map[string]string{"upstream": upstream},
		)

		options = append(options, &types.MenuItem{
			LabelColumns: []string{upstreamResetOptions},
			OpensMenu:    true,
			OnPress: func() error {
				if selectedBranch.RemoteBranchNotStoredLocally() {
					return self.c.ErrorMsg(self.c.Tr.UpstreamNotStoredLocallyError)
				}