1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-08-07 22:02:56 +03:00

refactor prompt opts

This commit is contained in:
Jesse Duffield
2020-11-28 13:35:58 +11:00
parent da3b0bf7c8
commit 5671ec5f58
12 changed files with 270 additions and 180 deletions

View File

@@ -207,20 +207,24 @@ func (gui *Gui) handleCheckoutRef(ref string, options handleCheckoutRefOptions)
} }
func (gui *Gui) handleCheckoutByName(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleCheckoutByName(g *gocui.Gui, v *gocui.View) error {
return gui.prompt(gui.Tr.BranchName+":", "", func(response string) error { return gui.prompt(promptOpts{
return gui.handleCheckoutRef(response, handleCheckoutRefOptions{ title: gui.Tr.BranchName + ":",
onRefNotFound: func(ref string) error { showSuggestions: true,
handleConfirm: func(response string) error {
return gui.handleCheckoutRef(response, handleCheckoutRefOptions{
onRefNotFound: func(ref string) error {
return gui.ask(askOpts{ return gui.ask(askOpts{
title: gui.Tr.BranchNotFoundTitle, title: gui.Tr.BranchNotFoundTitle,
prompt: fmt.Sprintf("%s %s%s", gui.Tr.BranchNotFoundPrompt, ref, "?"), prompt: fmt.Sprintf("%s %s%s", gui.Tr.BranchNotFoundPrompt, ref, "?"),
handleConfirm: func() error { handleConfirm: func() error {
return gui.createNewBranchWithName(ref) return gui.createNewBranchWithName(ref)
}, },
}) })
}, },
}) })
}) }},
)
} }
func (gui *Gui) getCheckedOutBranch() *models.Branch { func (gui *Gui) getCheckedOutBranch() *models.Branch {
@@ -427,17 +431,20 @@ func (gui *Gui) handleRenameBranch(g *gocui.Gui, v *gocui.View) error {
// way to get it to show up in the reflog) // way to get it to show up in the reflog)
promptForNewName := func() error { promptForNewName := func() error {
return gui.prompt(gui.Tr.NewBranchNamePrompt+" "+branch.Name+":", "", func(newBranchName string) error { return gui.prompt(promptOpts{
if err := gui.GitCommand.RenameBranch(branch.Name, newBranchName); err != nil { title: gui.Tr.NewBranchNamePrompt + " " + branch.Name + ":",
return gui.surfaceError(err) handleConfirm: func(newBranchName string) error {
} if err := gui.GitCommand.RenameBranch(branch.Name, newBranchName); err != nil {
// need to checkout so that the branch shows up in our reflog and therefore return gui.surfaceError(err)
// doesn't get lost among all the other branches when we switch to something else }
if err := gui.GitCommand.Checkout(newBranchName, commands.CheckoutOptions{Force: false}); err != nil { // need to checkout so that the branch shows up in our reflog and therefore
return gui.surfaceError(err) // doesn't get lost among all the other branches when we switch to something else
} if err := gui.GitCommand.Checkout(newBranchName, commands.CheckoutOptions{Force: false}); err != nil {
return gui.surfaceError(err)
}
return gui.refreshSidePanels(refreshOptions{mode: ASYNC}) return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
},
}) })
} }
@@ -483,25 +490,30 @@ func (gui *Gui) handleNewBranchOffCurrentItem() error {
// will set to the remote's existing name // will set to the remote's existing name
prefilledName = item.ID() prefilledName = item.ID()
} }
return gui.prompt(message, prefilledName, func(response string) error {
if err := gui.GitCommand.NewBranch(response, item.ID()); err != nil {
return err
}
// if we're currently in the branch commits context then the selected commit return gui.prompt(promptOpts{
// is about to go to the top of the list title: message,
if context.GetKey() == BRANCH_COMMITS_CONTEXT_KEY { initialContent: prefilledName,
context.GetPanelState().SetSelectedLineIdx(0) handleConfirm: func(response string) error {
} if err := gui.GitCommand.NewBranch(response, item.ID()); err != nil {
if context.GetKey() != gui.Contexts.Branches.Context.GetKey() {
if err := gui.pushContext(gui.Contexts.Branches.Context); err != nil {
return err return err
} }
}
gui.State.Panels.Branches.SelectedLineIdx = 0 // if we're currently in the branch commits context then the selected commit
// is about to go to the top of the list
if context.GetKey() == BRANCH_COMMITS_CONTEXT_KEY {
context.GetPanelState().SetSelectedLineIdx(0)
}
return gui.refreshSidePanels(refreshOptions{mode: ASYNC}) if context.GetKey() != gui.Contexts.Branches.Context.GetKey() {
if err := gui.pushContext(gui.Contexts.Branches.Context); err != nil {
return err
}
}
gui.State.Panels.Branches.SelectedLineIdx = 0
return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
},
}) })
} }

View File

@@ -233,12 +233,16 @@ func (gui *Gui) handleRenameCommit(g *gocui.Gui, v *gocui.View) error {
return gui.surfaceError(err) return gui.surfaceError(err)
} }
return gui.prompt(gui.Tr.LcRenameCommit, message, func(response string) error { return gui.prompt(promptOpts{
if err := gui.GitCommand.RenameCommit(response); err != nil { title: gui.Tr.LcRenameCommit,
return gui.surfaceError(err) initialContent: message,
} handleConfirm: func(response string) error {
if err := gui.GitCommand.RenameCommit(response); err != nil {
return gui.surfaceError(err)
}
return gui.refreshSidePanels(refreshOptions{mode: ASYNC}) return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
},
}) })
} }
@@ -517,11 +521,14 @@ func (gui *Gui) handleTagCommit(g *gocui.Gui, v *gocui.View) error {
} }
func (gui *Gui) handleCreateLightweightTag(commitSha string) error { func (gui *Gui) handleCreateLightweightTag(commitSha string) error {
return gui.prompt(gui.Tr.TagNameTitle, "", func(response string) error { return gui.prompt(promptOpts{
if err := gui.GitCommand.CreateLightweightTag(response, commitSha); err != nil { title: gui.Tr.TagNameTitle,
return gui.surfaceError(err) handleConfirm: func(response string) error {
} if err := gui.GitCommand.CreateLightweightTag(response, commitSha); err != nil {
return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []int{COMMITS, TAGS}}) return gui.surfaceError(err)
}
return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []int{COMMITS, TAGS}})
},
}) })
} }

View File

@@ -28,16 +28,44 @@ type createPopupPanelOpts struct {
// when handlersManageFocus is true, do not return from the confirmation context automatically. It's expected that the handlers will manage focus, whether that means switching to another context, or manually returning the context. // when handlersManageFocus is true, do not return from the confirmation context automatically. It's expected that the handlers will manage focus, whether that means switching to another context, or manually returning the context.
handlersManageFocus bool handlersManageFocus bool
showSuggestionsPanel bool showSuggestions bool
} }
type askOpts struct { type askOpts struct {
title string title string
prompt string prompt string
handleConfirm func() error handleConfirm func() error
handleClose func() error handleClose func() error
handlersManageFocus bool handlersManageFocus bool
showSuggestionsPanel bool showSuggestions bool
}
type promptOpts struct {
title string
initialContent string
handleConfirm func(string) error
showSuggestions bool
}
func (gui *Gui) ask(opts askOpts) error {
return gui.createPopupPanel(createPopupPanelOpts{
title: opts.title,
prompt: opts.prompt,
handleConfirm: opts.handleConfirm,
handleClose: opts.handleClose,
handlersManageFocus: opts.handlersManageFocus,
showSuggestions: opts.showSuggestions,
})
}
func (gui *Gui) prompt(opts promptOpts) error {
return gui.createPopupPanel(createPopupPanelOpts{
title: opts.title,
prompt: opts.initialContent,
editable: true,
handleConfirmPrompt: opts.handleConfirm,
showSuggestions: opts.showSuggestions,
})
} }
func (gui *Gui) createLoaderPanel(prompt string) error { func (gui *Gui) createLoaderPanel(prompt string) error {
@@ -47,27 +75,6 @@ func (gui *Gui) createLoaderPanel(prompt string) error {
}) })
} }
func (gui *Gui) ask(opts askOpts) error {
return gui.createPopupPanel(createPopupPanelOpts{
title: opts.title,
prompt: opts.prompt,
handleConfirm: opts.handleConfirm,
handleClose: opts.handleClose,
handlersManageFocus: opts.handlersManageFocus,
showSuggestionsPanel: opts.showSuggestionsPanel,
})
}
func (gui *Gui) prompt(title string, initialContent string, handleConfirm func(string) error) error {
return gui.createPopupPanel(createPopupPanelOpts{
title: title,
prompt: initialContent,
editable: true,
handleConfirmPrompt: handleConfirm,
showSuggestionsPanel: true,
})
}
func (gui *Gui) wrappedConfirmationFunction(handlersManageFocus bool, function func() error) func(*gocui.Gui, *gocui.View) error { func (gui *Gui) wrappedConfirmationFunction(handlersManageFocus bool, function func() error) func(*gocui.Gui, *gocui.View) error {
return func(g *gocui.Gui, v *gocui.View) error { return func(g *gocui.Gui, v *gocui.View) error {
if function != nil { if function != nil {
@@ -173,7 +180,7 @@ func (gui *Gui) getConfirmationPanelDimensions(wrap bool, prompt string) (int, i
height/2 + panelHeight/2 height/2 + panelHeight/2
} }
func (gui *Gui) prepareConfirmationPanel(title, prompt string, hasLoader bool, showSuggestionsPanel bool) (*gocui.View, error) { func (gui *Gui) prepareConfirmationPanel(title, prompt string, hasLoader bool, showSuggestions bool) (*gocui.View, error) {
x0, y0, x1, y1 := gui.getConfirmationPanelDimensions(true, prompt) x0, y0, x1, y1 := gui.getConfirmationPanelDimensions(true, prompt)
confirmationView, err := gui.g.SetView("confirmation", x0, y0, x1, y1, 0) confirmationView, err := gui.g.SetView("confirmation", x0, y0, x1, y1, 0)
if err != nil { if err != nil {
@@ -189,7 +196,7 @@ func (gui *Gui) prepareConfirmationPanel(title, prompt string, hasLoader bool, s
confirmationView.FgColor = theme.GocuiDefaultTextColor confirmationView.FgColor = theme.GocuiDefaultTextColor
} }
if showSuggestionsPanel { if showSuggestions {
suggestionsViewHeight := 11 suggestionsViewHeight := 11
suggestionsView, err := gui.g.SetView("suggestions", x0, y1, x1, y1+suggestionsViewHeight, 0) suggestionsView, err := gui.g.SetView("suggestions", x0, y1, x1, y1+suggestionsViewHeight, 0)
if err != nil { if err != nil {
@@ -215,7 +222,7 @@ func (gui *Gui) createPopupPanel(opts createPopupPanelOpts) error {
if view, _ := g.View("confirmation"); view != nil { if view, _ := g.View("confirmation"); view != nil {
gui.deleteConfirmationView() gui.deleteConfirmationView()
} }
confirmationView, err := gui.prepareConfirmationPanel(opts.title, opts.prompt, opts.hasLoader, opts.showSuggestionsPanel) confirmationView, err := gui.prepareConfirmationPanel(opts.title, opts.prompt, opts.hasLoader, opts.showSuggestions)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -98,15 +98,15 @@ func (gui *Gui) handleCustomCommandKeybinding(customCommand config.CustomCommand
return gui.surfaceError(err) return gui.surfaceError(err)
} }
return gui.prompt( return gui.prompt(promptOpts{
title, title: title,
initialValue, initialContent: initialValue,
func(str string) error { handleConfirm: func(str string) error {
promptResponses[idx] = str promptResponses[idx] = str
return wrappedF() return wrappedF()
}, },
) })
} }
case "menu": case "menu":
f = func() error { f = func() error {

View File

@@ -128,9 +128,12 @@ func (gui *Gui) handleCreateDiffingMenuPanel(g *gocui.Gui, v *gocui.View) error
{ {
displayString: gui.Tr.LcEnterRefToDiff, displayString: gui.Tr.LcEnterRefToDiff,
onPress: func() error { onPress: func() error {
return gui.prompt(gui.Tr.LcEnteRefName, "", func(response string) error { return gui.prompt(promptOpts{
gui.State.Modes.Diffing.Ref = strings.TrimSpace(response) title: gui.Tr.LcEnteRefName,
return gui.refreshSidePanels(refreshOptions{mode: ASYNC}) handleConfirm: func(response string) error {
gui.State.Modes.Diffing.Ref = strings.TrimSpace(response)
return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
},
}) })
}, },
}, },

View File

@@ -496,15 +496,19 @@ func (gui *Gui) handlePullFiles(g *gocui.Gui, v *gocui.View) error {
} }
} }
return gui.prompt(gui.Tr.EnterUpstream, "origin/"+currentBranch.Name, func(upstream string) error { return gui.prompt(promptOpts{
if err := gui.GitCommand.SetUpstreamBranch(upstream); err != nil { title: gui.Tr.EnterUpstream,
errorMessage := err.Error() initialContent: "origin/" + currentBranch.Name,
if strings.Contains(errorMessage, "does not exist") { handleConfirm: func(upstream string) error {
errorMessage = fmt.Sprintf("upstream branch %s not found.\nIf you expect it to exist, you should fetch (with 'f').\nOtherwise, you should push (with 'shift+P')", upstream) if err := gui.GitCommand.SetUpstreamBranch(upstream); err != nil {
errorMessage := err.Error()
if strings.Contains(errorMessage, "does not exist") {
errorMessage = fmt.Sprintf("upstream branch %s not found.\nIf you expect it to exist, you should fetch (with 'f').\nOtherwise, you should push (with 'shift+P')", upstream)
}
return gui.createErrorPanel(errorMessage)
} }
return gui.createErrorPanel(errorMessage) return gui.pullFiles(PullFilesOptions{})
} },
return gui.pullFiles(PullFilesOptions{})
}) })
} }
@@ -610,8 +614,12 @@ func (gui *Gui) pushFiles(g *gocui.Gui, v *gocui.View) error {
if gui.GitCommand.PushToCurrent { if gui.GitCommand.PushToCurrent {
return gui.pushWithForceFlag(v, false, "", "--set-upstream") return gui.pushWithForceFlag(v, false, "", "--set-upstream")
} else { } else {
return gui.prompt(gui.Tr.EnterUpstream, "origin "+currentBranch.Name, func(response string) error { return gui.prompt(promptOpts{
return gui.pushWithForceFlag(v, false, response, "") title: gui.Tr.EnterUpstream,
initialContent: "origin " + currentBranch.Name,
handleConfirm: func(response string) error {
return gui.pushWithForceFlag(v, false, response, "")
},
}) })
} }
} else if currentBranch.Pullables == "0" { } else if currentBranch.Pullables == "0" {
@@ -662,9 +670,12 @@ func (gui *Gui) anyFilesWithMergeConflicts() bool {
} }
func (gui *Gui) handleCustomCommand(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleCustomCommand(g *gocui.Gui, v *gocui.View) error {
return gui.prompt(gui.Tr.CustomCommand, "", func(command string) error { return gui.prompt(promptOpts{
gui.SubProcess = gui.OSCommand.RunCustomCommand(command) title: gui.Tr.CustomCommand,
return gui.Errors.ErrSubProcess handleConfirm: func(command string) error {
gui.SubProcess = gui.OSCommand.RunCustomCommand(command)
return gui.Errors.ErrSubProcess
},
}) })
} }

View File

@@ -41,9 +41,12 @@ func (gui *Gui) handleCreateFilteringMenuPanel(g *gocui.Gui, v *gocui.View) erro
menuItems = append(menuItems, &menuItem{ menuItems = append(menuItems, &menuItem{
displayString: gui.Tr.LcFilterPathOption, displayString: gui.Tr.LcFilterPathOption,
onPress: func() error { onPress: func() error {
return gui.prompt(gui.Tr.LcEnterFileName, "", func(response string) error { return gui.prompt(promptOpts{
gui.State.Modes.Filtering.Path = strings.TrimSpace(response) title: gui.Tr.LcEnterFileName,
return gui.Errors.ErrRestart handleConfirm: func(response string) error {
gui.State.Modes.Filtering.Path = strings.TrimSpace(response)
return gui.Errors.ErrRestart
},
}) })
}, },
}) })

View File

@@ -52,10 +52,14 @@ func (gui *Gui) handleCreateGitFlowMenu(g *gocui.Gui, v *gocui.View) error {
startHandler := func(branchType string) func() error { startHandler := func(branchType string) func() error {
return func() error { return func() error {
title := utils.ResolvePlaceholderString(gui.Tr.NewGitFlowBranchPrompt, map[string]string{"branchType": branchType}) title := utils.ResolvePlaceholderString(gui.Tr.NewGitFlowBranchPrompt, map[string]string{"branchType": branchType})
return gui.prompt(title, "", func(name string) error {
subProcess := gui.OSCommand.PrepareSubProcess("git", "flow", branchType, "start", name) return gui.prompt(promptOpts{
gui.SubProcess = subProcess title: title,
return gui.Errors.ErrSubProcess handleConfirm: func(name string) error {
subProcess := gui.OSCommand.PrepareSubProcess("git", "flow", branchType, "start", name)
gui.SubProcess = subProcess
return gui.Errors.ErrSubProcess
},
}) })
} }
} }

View File

@@ -85,14 +85,21 @@ func (gui *Gui) handleRemoteEnter() error {
} }
func (gui *Gui) handleAddRemote(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleAddRemote(g *gocui.Gui, v *gocui.View) error {
return gui.prompt(gui.Tr.LcNewRemoteName, "", func(remoteName string) error { return gui.prompt(promptOpts{
return gui.prompt(gui.Tr.LcNewRemoteUrl, "", func(remoteUrl string) error { title: gui.Tr.LcNewRemoteName,
if err := gui.GitCommand.AddRemote(remoteName, remoteUrl); err != nil { handleConfirm: func(remoteName string) error {
return err return gui.prompt(promptOpts{
} title: gui.Tr.LcNewRemoteUrl,
return gui.refreshSidePanels(refreshOptions{scope: []int{REMOTES}}) handleConfirm: func(remoteUrl string) error {
}) if err := gui.GitCommand.AddRemote(remoteName, remoteUrl); err != nil {
return err
}
return gui.refreshSidePanels(refreshOptions{scope: []int{REMOTES}})
},
})
},
}) })
} }
func (gui *Gui) handleRemoveRemote(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleRemoveRemote(g *gocui.Gui, v *gocui.View) error {
@@ -127,32 +134,40 @@ func (gui *Gui) handleEditRemote(g *gocui.Gui, v *gocui.View) error {
}, },
) )
return gui.prompt(editNameMessage, remote.Name, func(updatedRemoteName string) error { return gui.prompt(promptOpts{
if updatedRemoteName != remote.Name { title: editNameMessage,
if err := gui.GitCommand.RenameRemote(remote.Name, updatedRemoteName); err != nil { initialContent: remote.Name,
return gui.surfaceError(err) handleConfirm: func(updatedRemoteName string) error {
if updatedRemoteName != remote.Name {
if err := gui.GitCommand.RenameRemote(remote.Name, updatedRemoteName); err != nil {
return gui.surfaceError(err)
}
} }
}
editUrlMessage := utils.ResolvePlaceholderString( editUrlMessage := utils.ResolvePlaceholderString(
gui.Tr.LcEditRemoteUrl, gui.Tr.LcEditRemoteUrl,
map[string]string{ map[string]string{
"remoteName": updatedRemoteName, "remoteName": updatedRemoteName,
}, },
) )
urls := remote.Urls urls := remote.Urls
url := "" url := ""
if len(urls) > 0 { if len(urls) > 0 {
url = urls[0] url = urls[0]
}
return gui.prompt(editUrlMessage, url, func(updatedRemoteUrl string) error {
if err := gui.GitCommand.UpdateRemoteUrl(updatedRemoteName, updatedRemoteUrl); err != nil {
return gui.surfaceError(err)
} }
return gui.refreshSidePanels(refreshOptions{scope: []int{BRANCHES, REMOTES}})
}) return gui.prompt(promptOpts{
title: editUrlMessage,
initialContent: url,
handleConfirm: func(updatedRemoteUrl string) error {
if err := gui.GitCommand.UpdateRemoteUrl(updatedRemoteName, updatedRemoteUrl); err != nil {
return gui.surfaceError(err)
}
return gui.refreshSidePanels(refreshOptions{scope: []int{BRANCHES, REMOTES}})
},
})
},
}) })
} }

View File

@@ -117,11 +117,15 @@ func (gui *Gui) handleStashSave(stashFunc func(message string) error) error {
if len(gui.trackedFiles()) == 0 && len(gui.stagedFiles()) == 0 { if len(gui.trackedFiles()) == 0 && len(gui.stagedFiles()) == 0 {
return gui.createErrorPanel(gui.Tr.NoTrackedStagedFilesStash) return gui.createErrorPanel(gui.Tr.NoTrackedStagedFilesStash)
} }
return gui.prompt(gui.Tr.StashChanges, "", func(stashComment string) error {
if err := stashFunc(stashComment); err != nil { return gui.prompt(promptOpts{
return gui.surfaceError(err) title: gui.Tr.StashChanges,
} handleConfirm: func(stashComment string) error {
return gui.refreshSidePanels(refreshOptions{scope: []int{STASH, FILES}}) if err := stashFunc(stashComment); err != nil {
return gui.surfaceError(err)
}
return gui.refreshSidePanels(refreshOptions{scope: []int{STASH, FILES}})
},
}) })
} }

View File

@@ -126,30 +126,47 @@ func (gui *Gui) resetSubmodule(submodule *models.SubmoduleConfig) error {
} }
func (gui *Gui) handleAddSubmodule() error { func (gui *Gui) handleAddSubmodule() error {
return gui.prompt(gui.Tr.LcNewSubmoduleUrl, "", func(submoduleUrl string) error { return gui.prompt(promptOpts{
nameSuggestion := filepath.Base(strings.TrimSuffix(submoduleUrl, filepath.Ext(submoduleUrl))) title: gui.Tr.LcNewSubmoduleUrl,
handleConfirm: func(submoduleUrl string) error {
nameSuggestion := filepath.Base(strings.TrimSuffix(submoduleUrl, filepath.Ext(submoduleUrl)))
return gui.prompt(gui.Tr.LcNewSubmoduleName, nameSuggestion, func(submoduleName string) error { return gui.prompt(promptOpts{
return gui.prompt(gui.Tr.LcNewSubmodulePath, submoduleName, func(submodulePath string) error { title: gui.Tr.LcNewSubmoduleName,
return gui.WithWaitingStatus(gui.Tr.LcAddingSubmoduleStatus, func() error { initialContent: nameSuggestion,
err := gui.GitCommand.SubmoduleAdd(submoduleName, submodulePath, submoduleUrl) handleConfirm: func(submoduleName string) error {
gui.handleCredentialsPopup(err)
return gui.refreshSidePanels(refreshOptions{scope: []int{SUBMODULES}}) return gui.prompt(promptOpts{
}) title: gui.Tr.LcNewSubmodulePath,
initialContent: submoduleName,
handleConfirm: func(submodulePath string) error {
return gui.WithWaitingStatus(gui.Tr.LcAddingSubmoduleStatus, func() error {
err := gui.GitCommand.SubmoduleAdd(submoduleName, submodulePath, submoduleUrl)
gui.handleCredentialsPopup(err)
return gui.refreshSidePanels(refreshOptions{scope: []int{SUBMODULES}})
})
},
})
},
}) })
}) },
}) })
} }
func (gui *Gui) handleEditSubmoduleUrl(submodule *models.SubmoduleConfig) error { func (gui *Gui) handleEditSubmoduleUrl(submodule *models.SubmoduleConfig) error {
return gui.prompt(fmt.Sprintf(gui.Tr.LcUpdateSubmoduleUrl, submodule.Name), submodule.Url, func(newUrl string) error { return gui.prompt(promptOpts{
return gui.WithWaitingStatus(gui.Tr.LcUpdatingSubmoduleUrlStatus, func() error { title: fmt.Sprintf(gui.Tr.LcUpdateSubmoduleUrl, submodule.Name),
err := gui.GitCommand.SubmoduleUpdateUrl(submodule.Name, submodule.Path, newUrl) initialContent: submodule.Url,
gui.handleCredentialsPopup(err) handleConfirm: func(newUrl string) error {
return gui.WithWaitingStatus(gui.Tr.LcUpdatingSubmoduleUrlStatus, func() error {
err := gui.GitCommand.SubmoduleUpdateUrl(submodule.Name, submodule.Path, newUrl)
gui.handleCredentialsPopup(err)
return gui.refreshSidePanels(refreshOptions{scope: []int{SUBMODULES}}) return gui.refreshSidePanels(refreshOptions{scope: []int{SUBMODULES}})
}) })
},
}) })
} }

View File

@@ -97,36 +97,43 @@ func (gui *Gui) handlePushTag(g *gocui.Gui, v *gocui.View) error {
}, },
) )
return gui.prompt(title, "origin", func(response string) error { return gui.prompt(promptOpts{
return gui.WithWaitingStatus(gui.Tr.PushingTagStatus, func() error { title: title,
err := gui.GitCommand.PushTag(response, tag.Name, gui.promptUserForCredential) initialContent: "origin",
gui.handleCredentialsPopup(err) handleConfirm: func(response string) error {
return gui.WithWaitingStatus(gui.Tr.PushingTagStatus, func() error {
err := gui.GitCommand.PushTag(response, tag.Name, gui.promptUserForCredential)
gui.handleCredentialsPopup(err)
return nil return nil
}) })
},
}) })
} }
func (gui *Gui) handleCreateTag(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleCreateTag(g *gocui.Gui, v *gocui.View) error {
return gui.prompt(gui.Tr.CreateTagTitle, "", func(tagName string) error { return gui.prompt(promptOpts{
// leaving commit SHA blank so that we're just creating the tag for the current commit title: gui.Tr.CreateTagTitle,
if err := gui.GitCommand.CreateLightweightTag(tagName, ""); err != nil { handleConfirm: func(tagName string) error {
return gui.surfaceError(err) // leaving commit SHA blank so that we're just creating the tag for the current commit
} if err := gui.GitCommand.CreateLightweightTag(tagName, ""); err != nil {
return gui.refreshSidePanels(refreshOptions{scope: []int{COMMITS, TAGS}, then: func() { return gui.surfaceError(err)
// find the index of the tag and set that as the currently selected line
for i, tag := range gui.State.Tags {
if tag.Name == tagName {
gui.State.Panels.Tags.SelectedLineIdx = i
if err := gui.Contexts.Tags.Context.HandleRender(); err != nil {
gui.Log.Error(err)
}
return
}
} }
return gui.refreshSidePanels(refreshOptions{scope: []int{COMMITS, TAGS}, then: func() {
// find the index of the tag and set that as the currently selected line
for i, tag := range gui.State.Tags {
if tag.Name == tagName {
gui.State.Panels.Tags.SelectedLineIdx = i
if err := gui.Contexts.Tags.Context.HandleRender(); err != nil {
gui.Log.Error(err)
}
return
}
}
},
})
}, },
})
}) })
} }