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

Code before:
	}

	return self.c.Confirm(types.ConfirmOpts{
		Title:         self.c.Tr.RenameBranch,
		Prompt:        self.c.Tr.RenameBranchWarning,
		HandleConfirm: promptForNewName,
	})
}

func (self *BranchesController) newBranch(selectedBranch *models.Branch) error {
	return self.c.Helpers().Refs.NewBranch(selectedBranch.FullRefName(), selectedBranch.RefName(), "")
}

func (self *BranchesController) createPullRequestMenu(selectedBranch *models.Branch, checkedOutBranch *models.Branch) error {
	menuItems := make([]*types.MenuItem, 0, 4)

	fromToLabelColumns := func(from string, to string) []string {
		return []string{fmt.Sprintf("%s → %s", from, to)}
	}

	menuItemsForBranch := func(branch *models.Branch) []*types.MenuItem {
		return []*types.MenuItem{
			{
				LabelColumns: fromToLabelColumns(branch.Name, self.c.Tr.DefaultBranch),
				OnPress: func() error {
					if len(branch.UpstreamBranch) == 0 {
						return self.c.ErrorMsg(self.c.Tr.PullRequestNoUpstream)
					}
					return self.createPullRequest(branch.Name, "")
				},
			},
			{
				LabelColumns: fromToLabelColumns(branch.Name, self.c.Tr.SelectBranch),
				OnPress: func() error {
					return self.c.Prompt(types.PromptOpts{
						Title:               branch.Name + " →",
						FindSuggestionsFunc: self.c.Helpers().Suggestions.GetRemoteBranchesSuggestionsFunc("/"),
						HandleConfirm: func(targetBranchName string) error {
							upstreamExists := false
							for _, remoteBranch := range self.c.Model().RemoteBranches {
								upstreamExists = upstreamExists || remoteBranch.Name == targetBranchName
							}
							if !upstreamExists {
								return self.c.ErrorMsg(self.c.Tr.PullRequestNoUpstream)
							}
							return self.createPullRequest(branch.Name, targetBranchName)
						},
					})
				},
			},
		}

Review comment (suggestion):
I'd just call `handleCreatePullRequest` from here (We don't want to do `self.createPullRequest(branch.Name, "")` below and looks like we're doing the right thing on line 212

Code after:
		}
		if err != nil {
			return self.c.Error(err)
		}
		return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.BRANCHES}})
	})
}

func (self *BranchesController) remoteDelete(branch *models.Branch) error {
	return self.c.Helpers().BranchesHelper.ConfirmDeleteRemote(branch.UpstreamRemote, branch.Name)
}

func (self *BranchesController) forceDelete(branch *models.Branch) error {
	title := self.c.Tr.ForceDeleteBranchTitle
	message := utils.ResolvePlaceholderString(
		self.c.Tr.ForceDeleteBranchMessage,
		map[string]string{
			"selectedBranchName": branch.Name,
		},
	)

	return self.c.Confirm(types.ConfirmOpts{
		Title:  title,
		Prompt: message,
		HandleConfirm: func() error {
			if err := self.c.Git().Branch.LocalDelete(branch.Name, true); err != nil {
				return self.c.ErrorMsg(err.Error())
			}
			return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.BRANCHES}})
		},
	})
}

func (self *BranchesController) delete(branch *models.Branch) error {
	menuItems := []*types.MenuItem{}
	checkedOutBranch := self.c.Helpers().Refs.GetCheckedOutRef()

	localDeleteItem := &types.MenuItem{
		Label: self.c.Tr.DeleteLocalBranch,
		Key:   'c',
		OnPress: func() error {
			return self.localDelete(branch)
		},
	}
	if checkedOutBranch.Name == branch.Name {
		localDeleteItem = &types.MenuItem{
			Label:   self.c.Tr.DeleteLocalBranch,
			Key:     'c',
			Tooltip: self.c.Tr.CantDeleteCheckOutBranch,
			OnPress: func() error {
				return self.c.ErrorMsg(self.c.Tr.CantDeleteCheckOutBranch)