diff options
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/gui/controllers/branches_controller.go | 96 | ||||
-rw-r--r-- | pkg/gui/controllers/remote_branches_controller.go | 161 | ||||
-rw-r--r-- | pkg/gui/gui.go | 3 | ||||
-rw-r--r-- | pkg/gui/keybindings.go | 58 | ||||
-rw-r--r-- | pkg/gui/remote_branches_panel.go | 95 |
5 files changed, 194 insertions, 219 deletions
diff --git a/pkg/gui/controllers/branches_controller.go b/pkg/gui/controllers/branches_controller.go index ff5989656..a151d4bcc 100644 --- a/pkg/gui/controllers/branches_controller.go +++ b/pkg/gui/controllers/branches_controller.go @@ -31,96 +31,70 @@ func NewBranchesController( func (self *BranchesController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding { return []*types.Binding{ { - ViewName: "branches", - Contexts: []string{string(context.LOCAL_BRANCHES_CONTEXT_KEY)}, Key: opts.GetKey(opts.Config.Universal.Select), - Handler: self.handleBranchPress, + Handler: self.checkSelected(self.press), Description: self.c.Tr.LcCheckout, }, { - ViewName: "branches", - Contexts: []string{string(context.LOCAL_BRANCHES_CONTEXT_KEY)}, Key: opts.GetKey(opts.Config.Branches.CreatePullRequest), - Handler: self.handleCreatePullRequestPress, + Handler: self.checkSelected(self.handleCreatePullRequest), Description: self.c.Tr.LcCreatePullRequest, }, { - ViewName: "branches", - Contexts: []string{string(context.LOCAL_BRANCHES_CONTEXT_KEY)}, Key: opts.GetKey(opts.Config.Branches.ViewPullRequestOptions), Handler: self.checkSelected(self.handleCreatePullRequestMenu), Description: self.c.Tr.LcCreatePullRequestOptions, OpensMenu: true, }, { - ViewName: "branches", - Contexts: []string{string(context.LOCAL_BRANCHES_CONTEXT_KEY)}, Key: opts.GetKey(opts.Config.Branches.CopyPullRequestURL), - Handler: self.handleCopyPullRequestURLPress, + Handler: self.copyPullRequestURL, Description: self.c.Tr.LcCopyPullRequestURL, }, { - ViewName: "branches", - Contexts: []string{string(context.LOCAL_BRANCHES_CONTEXT_KEY)}, Key: opts.GetKey(opts.Config.Branches.CheckoutBranchByName), - Handler: self.handleCheckoutByName, + Handler: self.checkoutByName, Description: self.c.Tr.LcCheckoutByName, }, { - ViewName: "branches", - Contexts: []string{string(context.LOCAL_BRANCHES_CONTEXT_KEY)}, Key: opts.GetKey(opts.Config.Branches.ForceCheckoutBranch), - Handler: self.handleForceCheckout, + Handler: self.forceCheckout, Description: self.c.Tr.LcForceCheckout, }, { - ViewName: "branches", - Contexts: []string{string(context.LOCAL_BRANCHES_CONTEXT_KEY)}, Key: opts.GetKey(opts.Config.Universal.New), - Handler: self.checkSelected(self.handleNewBranchOffBranch), + Handler: self.checkSelected(self.newBranch), Description: self.c.Tr.LcNewBranch, }, { - ViewName: "branches", - Contexts: []string{string(context.LOCAL_BRANCHES_CONTEXT_KEY)}, Key: opts.GetKey(opts.Config.Universal.Remove), - Handler: self.checkSelectedAndReal(self.handleDeleteBranch), + Handler: self.checkSelectedAndReal(self.delete), Description: self.c.Tr.LcDeleteBranch, }, { - ViewName: "branches", - Contexts: []string{string(context.LOCAL_BRANCHES_CONTEXT_KEY)}, Key: opts.GetKey(opts.Config.Branches.RebaseBranch), - Handler: opts.Guards.OutsideFilterMode(self.handleRebaseOntoLocalBranch), + Handler: opts.Guards.OutsideFilterMode(self.rebase), Description: self.c.Tr.LcRebaseBranch, }, { - ViewName: "branches", - Contexts: []string{string(context.LOCAL_BRANCHES_CONTEXT_KEY)}, Key: opts.GetKey(opts.Config.Branches.MergeIntoCurrentBranch), - Handler: opts.Guards.OutsideFilterMode(self.handleMerge), + Handler: opts.Guards.OutsideFilterMode(self.merge), Description: self.c.Tr.LcMergeIntoCurrentBranch, }, { - ViewName: "branches", - Contexts: []string{string(context.LOCAL_BRANCHES_CONTEXT_KEY)}, Key: opts.GetKey(opts.Config.Branches.FastForward), - Handler: self.checkSelectedAndReal(self.handleFastForward), + Handler: self.checkSelectedAndReal(self.fastForward), Description: self.c.Tr.FastForward, }, { - ViewName: "branches", - Contexts: []string{string(context.LOCAL_BRANCHES_CONTEXT_KEY)}, Key: opts.GetKey(opts.Config.Commits.ViewResetOptions), - Handler: self.checkSelected(self.handleCreateResetToBranchMenu), + Handler: self.checkSelected(self.createResetMenu), Description: self.c.Tr.LcViewResetOptions, OpensMenu: true, }, { - ViewName: "branches", - Contexts: []string{string(context.LOCAL_BRANCHES_CONTEXT_KEY)}, Key: opts.GetKey(opts.Config.Branches.RenameBranch), - Handler: self.checkSelectedAndReal(self.handleRenameBranch), + Handler: self.checkSelectedAndReal(self.rename), Description: self.c.Tr.LcRenameBranch, }, } @@ -134,23 +108,17 @@ func (self *BranchesController) context() *context.BranchesContext { return self.contexts.Branches } -func (self *BranchesController) handleBranchPress() error { - branch := self.context().GetSelected() - if branch == nil { - return nil - } - - if branch == self.helpers.Refs.GetCheckedOutRef() { +func (self *BranchesController) press(selectedBranch *models.Branch) error { + if selectedBranch == self.helpers.Refs.GetCheckedOutRef() { return self.c.ErrorMsg(self.c.Tr.AlreadyCheckedOutBranch) } self.c.LogAction(self.c.Tr.Actions.CheckoutBranch) - return self.helpers.Refs.CheckoutRef(branch.Name, types.CheckoutRefOptions{}) + return self.helpers.Refs.CheckoutRef(selectedBranch.Name, types.CheckoutRefOptions{}) } -func (self *BranchesController) handleCreatePullRequestPress() error { - branch := self.context().GetSelected() - return self.createPullRequest(branch.Name, "") +func (self *BranchesController) handleCreatePullRequest(selectedBranch *models.Branch) error { + return self.createPullRequest(selectedBranch.Name, "") } func (self *BranchesController) handleCreatePullRequestMenu(selectedBranch *models.Branch) error { @@ -159,7 +127,7 @@ func (self *BranchesController) handleCreatePullRequestMenu(selectedBranch *mode return self.createPullRequestMenu(selectedBranch, checkedOutBranch) } -func (self *BranchesController) handleCopyPullRequestURLPress() error { +func (self *BranchesController) copyPullRequestURL() error { branch := self.context().GetSelected() branchExistsOnRemote := self.git.Remote.CheckRemoteBranchExists(branch.Name) @@ -182,7 +150,7 @@ func (self *BranchesController) handleCopyPullRequestURLPress() error { return nil } -func (self *BranchesController) handleForceCheckout() error { +func (self *BranchesController) forceCheckout() error { branch := self.context().GetSelected() message := self.c.Tr.SureForceCheckout title := self.c.Tr.ForceCheckoutBranch @@ -200,7 +168,7 @@ func (self *BranchesController) handleForceCheckout() error { }) } -func (self *BranchesController) handleCheckoutByName() error { +func (self *BranchesController) checkoutByName() error { return self.c.Prompt(types.PromptOpts{ Title: self.c.Tr.BranchName + ":", FindSuggestionsFunc: self.helpers.Suggestions.GetRefsSuggestionsFunc(), @@ -235,19 +203,15 @@ func (self *BranchesController) createNewBranchWithName(newBranchName string) er return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC}) } -func (self *BranchesController) handleDeleteBranch(branch *models.Branch) error { - return self.deleteBranch(branch, false) -} - -func (self *BranchesController) deleteBranch(branch *models.Branch, force bool) error { +func (self *BranchesController) delete(branch *models.Branch) error { checkedOutBranch := self.helpers.Refs.GetCheckedOutRef() if checkedOutBranch.Name == branch.Name { return self.c.ErrorMsg(self.c.Tr.CantDeleteCheckOutBranch) } - return self.deleteNamedBranch(branch, force) + return self.deleteWithForce(branch, false) } -func (self *BranchesController) deleteNamedBranch(selectedBranch *models.Branch, force bool) error { +func (self *BranchesController) deleteWithForce(selectedBranch *models.Branch, force bool) error { title := self.c.Tr.DeleteBranch var templateStr string if force { @@ -270,7 +234,7 @@ func (self *BranchesController) deleteNamedBranch(selectedBranch *models.Branch, if err := self.git.Branch.Delete(selectedBranch.Name, force); err != nil { errMessage := err.Error() if !force && strings.Contains(errMessage, "git branch -D ") { - return self.deleteNamedBranch(selectedBranch, true) + return self.deleteWithForce(selectedBranch, true) } return self.c.ErrorMsg(errMessage) } @@ -279,17 +243,17 @@ func (self *BranchesController) deleteNamedBranch(selectedBranch *models.Branch, }) } -func (self *BranchesController) handleMerge() error { +func (self *BranchesController) merge() error { selectedBranchName := self.context().GetSelected().Name return self.helpers.MergeAndRebase.MergeRefIntoCheckedOutBranch(selectedBranchName) } -func (self *BranchesController) handleRebaseOntoLocalBranch() error { +func (self *BranchesController) rebase() error { selectedBranchName := self.context().GetSelected().Name return self.helpers.MergeAndRebase.RebaseOntoRef(selectedBranchName) } -func (self *BranchesController) handleFastForward(branch *models.Branch) error { +func (self *BranchesController) fastForward(branch *models.Branch) error { if !branch.IsTrackingRemote() { return self.c.ErrorMsg(self.c.Tr.FwdNoUpstream) } @@ -339,11 +303,11 @@ func (self *BranchesController) handleFastForward(branch *models.Branch) error { }) } -func (self *BranchesController) handleCreateResetToBranchMenu(selectedBranch *models.Branch) error { +func (self *BranchesController) createResetMenu(selectedBranch *models.Branch) error { return self.helpers.Refs.CreateGitResetMenu(selectedBranch.Name) } -func (self *BranchesController) handleRenameBranch(branch *models.Branch) error { +func (self *BranchesController) rename(branch *models.Branch) error { promptForNewName := func() error { return self.c.Prompt(types.PromptOpts{ Title: self.c.Tr.NewBranchNamePrompt + " " + branch.Name + ":", @@ -386,7 +350,7 @@ func (self *BranchesController) handleRenameBranch(branch *models.Branch) error }) } -func (self *BranchesController) handleNewBranchOffBranch(selectedBranch *models.Branch) error { +func (self *BranchesController) newBranch(selectedBranch *models.Branch) error { return self.helpers.Refs.NewBranch(selectedBranch.RefName(), selectedBranch.RefName(), "") } diff --git a/pkg/gui/controllers/remote_branches_controller.go b/pkg/gui/controllers/remote_branches_controller.go new file mode 100644 index 000000000..d469f5657 --- /dev/null +++ b/pkg/gui/controllers/remote_branches_controller.go @@ -0,0 +1,161 @@ +package controllers + +import ( + "fmt" + "strings" + + "github.com/jesseduffield/lazygit/pkg/commands/models" + "github.com/jesseduffield/lazygit/pkg/gui/context" + "github.com/jesseduffield/lazygit/pkg/gui/types" + "github.com/jesseduffield/lazygit/pkg/utils" +) + +type RemoteBranchesController struct { + baseController + *controllerCommon +} + +var _ types.IController = &RemoteBranchesController{} + +func NewRemoteBranchesController( + common *controllerCommon, +) *RemoteBranchesController { + return &RemoteBranchesController{ + baseController: baseController{}, + controllerCommon: common, + } +} + +func (self *RemoteBranchesController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding { + return []*types.Binding{ + { + Key: opts.GetKey(opts.Config.Universal.Select), + // gonna use the exact same handler as the 'n' keybinding because everybody wants this to happen when they checkout a remote branch + Handler: self.checkSelected(self.newLocalBranch), + Description: self.c.Tr.LcCheckout, + }, + { + Key: opts.GetKey(opts.Config.Universal.New), + Handler: self.checkSelected(self.newLocalBranch), + Description: self.c.Tr.LcNewBranch, + }, + { + Key: opts.GetKey(opts.Config.Branches.MergeIntoCurrentBranch), + Handler: opts.Guards.OutsideFilterMode(self.checkSelected(self.merge)), + Description: self.c.Tr.LcMergeIntoCurrentBranch, + }, + { + Key: opts.GetKey(opts.Config.Branches.RebaseBranch), + Handler: opts.Guards.OutsideFilterMode(self.checkSelected(self.rebase)), + Description: self.c.Tr.LcRebaseBranch, + }, + { + Key: opts.GetKey(opts.Config.Universal.Remove), + Handler: self.checkSelected(self.delete), + Description: self.c.Tr.LcDeleteBranch, + }, + { + Key: opts.GetKey(opts.Config.Branches.SetUpstream), + Handler: self.checkSelected(self.setAsUpstream), + Description: self.c.Tr.LcSetUpstream, + }, + { + Key: opts.GetKey(opts.Config.Universal.Return), + Handler: self.escape, + Description: self.c.Tr.ReturnToRemotesList, + }, + { + Key: opts.GetKey(opts.Config.Commits.ViewResetOptions), + Handler: self.checkSelected(self.createResetMenu), + Description: self.c.Tr.LcViewResetOptions, + OpensMenu: true, + }, + } +} + +func (self *RemoteBranchesController) Context() types.Context { + return self.context() +} + +func (self *RemoteBranchesController) context() *context.RemoteBranchesContext { + return self.contexts.RemoteBranches +} + +func (self *RemoteBranchesController) checkSelected(callback func(*models.RemoteBranch) error) func() error { + return func() error { + selectedItem := self.context().GetSelected() + if selectedItem == nil { + return nil + } + + return callback(selectedItem) + } +} + +func (self *RemoteBranchesController) escape() error { + return self.c.PushContext(self.contexts.Remotes) +} + +func (self *RemoteBranchesController) delete(selectedBranch *models.RemoteBranch) error { + message := fmt.Sprintf("%s '%s'?", self.c.Tr.DeleteRemoteBranchMessage, selectedBranch.FullName()) + + return self.c.Ask(types.AskOpts{ + Title: self.c.Tr.DeleteRemoteBranch, + Prompt: message, + HandleConfirm: func() error { + return self.c.WithWaitingStatus(self.c.Tr.DeletingStatus, func() error { + self.c.LogAction(self.c.Tr.Actions.DeleteRemoteBranch) + err := self.git.Remote.DeleteRemoteBranch(selectedBranch.RemoteName, selectedBranch.Name) + if err != nil { + _ = self.c.Error(err) + } + + return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.BRANCHES, types.REMOTES}}) + }) + }, + }) +} + +func (self *RemoteBranchesController) merge(selectedBranch *models.RemoteBranch) error { + return self.helpers.MergeAndRebase.MergeRefIntoCheckedOutBranch(selectedBranch.FullName()) +} + +func (self *RemoteBranchesController) rebase(selectedBranch *models.RemoteBranch) error { + return self.helpers.MergeAndRebase.RebaseOntoRef(selectedBranch.FullName()) +} + +func (self *RemoteBranchesController) createResetMenu(selectedBranch *models.RemoteBranch) error { + return self.helpers.Refs.CreateGitResetMenu(selectedBranch.FullName()) +} + +func (self *RemoteBranchesController) setAsUpstream(selectedBranch *models.RemoteBranch) error { + checkedOutBranch := self.helpers.Refs.GetCheckedOutRef() + + message := utils.ResolvePlaceholderString( + self.c.Tr.SetUpstreamMessage, + map[string]string{ + "checkedOut": checkedOutBranch.Name, + "selected": selectedBranch.FullName(), + }, + ) + + return self.c.Ask(types.AskOpts{ + Title: self.c.Tr.SetUpstreamTitle, + Prompt: message, + HandleConfirm: func() error { + self.c.LogAction(self.c.Tr.Actions.SetBranchUpstream) + if err := self.git.Branch.SetUpstream(selectedBranch.RemoteName, selectedBranch.Name, checkedOutBranch.Name); err != nil { + return self.c.Error(err) + } + + return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.BRANCHES, types.REMOTES}}) + }, + }) +} + +func (self *RemoteBranchesController) newLocalBranch(selectedBranch *models.RemoteBranch) error { + // will set to the remote's branch name without the remote name + nameSuggestion := strings.SplitAfterN(selectedBranch.RefName(), "/", 2)[1] + + return self.helpers.Refs.NewBranch(selectedBranch.RefName(), selectedBranch.RefName(), nameSuggestion) +} diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 9f83f0b74..1cd2229f5 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -589,6 +589,8 @@ func (gui *Gui) resetControllers() { onCommitSuccess, ) + remoteBranchesController := controllers.NewRemoteBranchesController(common) + gui.Controllers = Controllers{ Submodules: submodulesController, Global: controllers.NewGlobalController(common), @@ -655,6 +657,7 @@ func (gui *Gui) resetControllers() { controllers.AttachControllers(gui.State.Contexts.Stash, stashController) controllers.AttachControllers(gui.State.Contexts.Menu, gui.Controllers.Menu) controllers.AttachControllers(gui.State.Contexts.CommitMessage, commitMessageController) + controllers.AttachControllers(gui.State.Contexts.RemoteBranches, remoteBranchesController) controllers.AttachControllers(gui.State.Contexts.Global, gui.Controllers.Sync, gui.Controllers.Undo, gui.Controllers.Global) listControllerFactory := controllers.NewListControllerFactory(gui.c) diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 7c5e0be25..4b0fcd99a 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -388,21 +388,6 @@ func (self *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBi Description: self.c.Tr.LcCopyBranchNameToClipboard, }, { - ViewName: "branches", - Contexts: []string{string(context.REMOTE_BRANCHES_CONTEXT_KEY)}, - Key: opts.GetKey(opts.Config.Universal.Return), - Handler: self.handleRemoteBranchesEscape, - Description: self.c.Tr.ReturnToRemotesList, - }, - { - ViewName: "branches", - Contexts: []string{string(context.REMOTE_BRANCHES_CONTEXT_KEY)}, - Key: opts.GetKey(opts.Config.Commits.ViewResetOptions), - Handler: self.handleCreateResetToRemoteBranchMenu, - Description: self.c.Tr.LcViewResetOptions, - OpensMenu: true, - }, - { ViewName: "commits", Contexts: []string{string(context.LOCAL_COMMITS_CONTEXT_KEY)}, Key: opts.GetKey(opts.Config.Universal.CopyToClipboard), @@ -873,49 +858,6 @@ func (self *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBi Description: self.c.Tr.LcUndo, }, { - ViewName: "branches", - Contexts: []string{string(context.REMOTE_BRANCHES_CONTEXT_KEY)}, - Key: opts.GetKey(opts.Config.Universal.Select), - // gonna use the exact same handler as the 'n' keybinding because everybody wants this to happen when they checkout a remote branch - Handler: self.handleNewBranchOffRemoteBranch, - Description: self.c.Tr.LcCheckout, - }, - { - ViewName: "branches", - Contexts: []string{string(context.REMOTE_BRANCHES_CONTEXT_KEY)}, - Key: opts.GetKey(opts.Config.Universal.New), - Handler: self.handleNewBranchOffRemoteBranch, - Description: self.c.Tr.LcNewBranch, - }, - { - ViewName: "branches", - Contexts: []string{string(context.REMOTE_BRANCHES_CONTEXT_KEY)}, - Key: opts.GetKey(opts.Config.Branches.MergeIntoCurrentBranch), - Handler: opts.Guards.OutsideFilterMode(self.handleMergeRemoteBranch), - Description: self.c.Tr.LcMergeIntoCurrentBranch, - }, - { - ViewName: "branches", - Contexts: []string{string(context.REMOTE_BRANCHES_CONTEXT_KEY)}, - Key: opts.GetKey(opts.Config.Universal.Remove), - Handler: self.handleDeleteRemoteBranch, - Description: self.c.Tr.LcDeleteBranch, - }, - { - ViewName: "branches", - Contexts: []string{string(context.REMOTE_BRANCHES_CONTEXT_KEY)}, - Key: opts.GetKey(opts.Config.Branches.RebaseBranch), - Handler: opts.Guards.OutsideFilterMode(self.handleRebaseOntoRemoteBranch), - Description: self.c.Tr.LcRebaseBranch, - }, - { - ViewName: "branches", - Contexts: []string{string(context.REMOTE_BRANCHES_CONTEXT_KEY)}, - Key: opts.GetKey(opts.Config.Branches.SetUpstream), - Handler: self.handleSetBranchUpstream, - Description: self.c.Tr.LcSetUpstream, - }, - { ViewName: "status", Key: gocui.MouseLeft, Modifier: gocui.ModNone, diff --git a/pkg/gui/remote_branches_panel.go b/pkg/gui/remote_branches_panel.go index eeed4cd13..3f23f0646 100644 --- a/pkg/gui/remote_branches_panel.go +++ b/pkg/gui/remote_branches_panel.go @@ -1,15 +1,5 @@ package gui -import ( - "fmt" - "strings" - - "github.com/jesseduffield/lazygit/pkg/gui/types" - "github.com/jesseduffield/lazygit/pkg/utils" -) - -// list panel functions - func (gui *Gui) remoteBranchesRenderToMain() error { var task updateTask remoteBranch := gui.State.Contexts.RemoteBranches.GetSelected() @@ -27,88 +17,3 @@ func (gui *Gui) remoteBranchesRenderToMain() error { }, }) } - -func (gui *Gui) handleRemoteBranchesEscape() error { - return gui.c.PushContext(gui.State.Contexts.Remotes) -} - -func (gui *Gui) handleMergeRemoteBranch() error { - selectedBranchName := gui.State.Contexts.RemoteBranches.GetSelected().FullName() - return gui.helpers.MergeAndRebase.MergeRefIntoCheckedOutBranch(selectedBranchName) -} - -func (gui *Gui) handleDeleteRemoteBranch() error { - remoteBranch := gui.State.Contexts.RemoteBranches.GetSelected() - if remoteBranch == nil { - return nil - } - message := fmt.Sprintf("%s '%s'?", gui.c.Tr.DeleteRemoteBranchMessage, remoteBranch.FullName()) - - return gui.c.Ask(types.AskOpts{ - Title: gui.c.Tr.DeleteRemoteBranch, - Prompt: message, - HandleConfirm: func() error { - return gui.c.WithWaitingStatus(gui.c.Tr.DeletingStatus, func() error { - gui.c.LogAction(gui.c.Tr.Actions.DeleteRemoteBranch) - err := gui.git.Remote.DeleteRemoteBranch(remoteBranch.RemoteName, remoteBranch.Name) - if err != nil { - _ = gui.c.Error(err) - } - - return gui.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.BRANCHES, types.REMOTES}}) - }) - }, - }) -} - -func (gui *Gui) handleRebaseOntoRemoteBranch() error { - selectedBranchName := gui.State.Contexts.RemoteBranches.GetSelected().FullName() - return gui.helpers.MergeAndRebase.RebaseOntoRef(selectedBranchName) -} - -func (gui *Gui) handleSetBranchUpstream() error { - selectedBranch := gui.State.Contexts.RemoteBranches.GetSelected() - checkedOutBranch := gui.helpers.Refs.GetCheckedOutRef() - - message := utils.ResolvePlaceholderString( - gui.c.Tr.SetUpstreamMessage, - map[string]string{ - "checkedOut": checkedOutBranch.Name, - "selected": selectedBranch.FullName(), - }, - ) - - return gui.c.Ask(types.AskOpts{ - Title: gui.c.Tr.SetUpstreamTitle, - Prompt: message, - HandleConfirm: func() error { - gui.c.LogAction(gui.c.Tr.Actions.SetBranchUpstream) - if err := gui.git.Branch.SetUpstream(selectedBranch.RemoteName, selectedBranch.Name, checkedOutBranch.Name); err != nil { - return gui.c.Error(err) - } - - return gui.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.BRANCHES, types.REMOTES}}) - }, - }) -} - -func (gui *Gui) handleCreateResetToRemoteBranchMenu() error { - selectedBranch := gui.State.Contexts.RemoteBranches.GetSelected() - if selectedBranch == nil { - return nil - } - - return gui.helpers.Refs.CreateGitResetMenu(selectedBranch.FullName()) -} - -func (gui *Gui) handleNewBranchOffRemoteBranch() error { - selectedBranch := gui.State.Contexts.RemoteBranches.GetSelected() - if selectedBranch == nil { - return nil - } - - // will set to the remote's branch name without the remote name - nameSuggestion := strings.SplitAfterN(selectedBranch.RefName(), "/", 2)[1] - - return gui.helpers.Refs.NewBranch(selectedBranch.RefName(), selectedBranch.RefName(), nameSuggestion) -} |