diff options
-rw-r--r-- | pkg/commands/git_test.go | 69 | ||||
-rw-r--r-- | pkg/gui/app_status_manager.go | 2 | ||||
-rw-r--r-- | pkg/gui/branches_panel.go | 46 | ||||
-rw-r--r-- | pkg/gui/commit_files_panel.go | 4 | ||||
-rw-r--r-- | pkg/gui/commit_message_panel.go | 4 | ||||
-rw-r--r-- | pkg/gui/commits_panel.go | 38 | ||||
-rw-r--r-- | pkg/gui/confirmation_panel.go | 8 | ||||
-rw-r--r-- | pkg/gui/files_panel.go | 36 | ||||
-rw-r--r-- | pkg/gui/git_flow.go | 4 | ||||
-rw-r--r-- | pkg/gui/gui.go | 2 | ||||
-rw-r--r-- | pkg/gui/patch_options_panel.go | 6 | ||||
-rw-r--r-- | pkg/gui/rebase_options_panel.go | 4 | ||||
-rw-r--r-- | pkg/gui/reflog_panel.go | 2 | ||||
-rw-r--r-- | pkg/gui/remotes_panel.go | 6 | ||||
-rw-r--r-- | pkg/gui/reset_menu_panel.go | 2 | ||||
-rw-r--r-- | pkg/gui/staging_panel.go | 2 | ||||
-rw-r--r-- | pkg/gui/stash_panel.go | 8 | ||||
-rw-r--r-- | pkg/gui/tags_panel.go | 10 | ||||
-rw-r--r-- | pkg/gui/undoing.go | 10 | ||||
-rw-r--r-- | pkg/gui/updates.go | 6 | ||||
-rw-r--r-- | pkg/gui/workspace_reset_options_panel.go | 12 |
21 files changed, 108 insertions, 173 deletions
diff --git a/pkg/commands/git_test.go b/pkg/commands/git_test.go index 8d9bdef40..56e2923cd 100644 --- a/pkg/commands/git_test.go +++ b/pkg/commands/git_test.go @@ -1097,75 +1097,6 @@ func TestGitCommandUnstageFile(t *testing.T) { } } -// TestGitCommandIsInMergeState is a function. -func TestGitCommandIsInMergeState(t *testing.T) { - type scenario struct { - testName string - command func(string, ...string) *exec.Cmd - test func(bool, error) - } - - scenarios := []scenario{ - { - "An error occurred when running status command", - func(cmd string, args ...string) *exec.Cmd { - assert.EqualValues(t, "git", cmd) - assert.EqualValues(t, []string{"status", "--untracked-files=all"}, args) - - return exec.Command("test") - }, - func(isInMergeState bool, err error) { - assert.Error(t, err) - assert.False(t, isInMergeState) - }, - }, - { - "Is not in merge state", - func(cmd string, args ...string) *exec.Cmd { - assert.EqualValues(t, "git", cmd) - assert.EqualValues(t, []string{"status", "--untracked-files=all"}, args) - return exec.Command("echo") - }, - func(isInMergeState bool, err error) { - assert.False(t, isInMergeState) - assert.NoError(t, err) - }, - }, - { - "Command output contains conclude merge", - func(cmd string, args ...string) *exec.Cmd { - assert.EqualValues(t, "git", cmd) - assert.EqualValues(t, []string{"status", "--untracked-files=all"}, args) - return exec.Command("echo", "'conclude merge'") - }, - func(isInMergeState bool, err error) { - assert.True(t, isInMergeState) - assert.NoError(t, err) - }, - }, - { - "Command output contains unmerged paths", - func(cmd string, args ...string) *exec.Cmd { - assert.EqualValues(t, "git", cmd) - assert.EqualValues(t, []string{"status", "--untracked-files=all"}, args) - return exec.Command("echo", "'unmerged paths'") - }, - func(isInMergeState bool, err error) { - assert.True(t, isInMergeState) - assert.NoError(t, err) - }, - }, - } - - for _, s := range scenarios { - t.Run(s.testName, func(t *testing.T) { - gitCmd := NewDummyGitCommand() - gitCmd.OSCommand.command = s.command - s.test(gitCmd.IsInMergeState()) - }) - } -} - // TestGitCommandDiscardAllFileChanges is a function. func TestGitCommandDiscardAllFileChanges(t *testing.T) { type scenario struct { diff --git a/pkg/gui/app_status_manager.go b/pkg/gui/app_status_manager.go index ed8f0c935..54393c443 100644 --- a/pkg/gui/app_status_manager.go +++ b/pkg/gui/app_status_manager.go @@ -72,7 +72,7 @@ func (gui *Gui) WithWaitingStatus(name string, f func() error) error { if err := f(); err != nil { gui.g.Update(func(g *gocui.Gui) error { - return gui.createErrorPanel(gui.g, err.Error()) + return gui.surfaceError(err) }) } }() diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go index 45b86a546..72eab93f0 100644 --- a/pkg/gui/branches_panel.go +++ b/pkg/gui/branches_panel.go @@ -56,13 +56,13 @@ func (gui *Gui) handleBranchSelect(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) refreshBranches() { builder, err := commands.NewBranchListBuilder(gui.Log, gui.GitCommand, gui.State.ReflogCommits) if err != nil { - _ = gui.createErrorPanel(gui.g, err.Error()) + _ = gui.surfaceError(err) } gui.State.Branches = builder.Build() // TODO: if we're in the remotes view and we've just deleted a remote we need to refresh accordingly if gui.getBranchesView().Context == "local-branches" { - gui.renderLocalBranchesWithSelection() + _ = gui.renderLocalBranchesWithSelection() } gui.refreshStatus() @@ -76,7 +76,7 @@ func (gui *Gui) renderLocalBranchesWithSelection() error { gui.renderDisplayStrings(branchesView, displayStrings) if gui.g.CurrentView() == branchesView { if err := gui.handleBranchSelect(gui.g, branchesView); err != nil { - return err + return gui.surfaceError(err) } } @@ -90,7 +90,7 @@ func (gui *Gui) handleBranchPress(g *gocui.Gui, v *gocui.View) error { return nil } if gui.State.Panels.Branches.SelectedLine == 0 { - return gui.createErrorPanel(g, gui.Tr.SLocalize("AlreadyCheckedOutBranch")) + return gui.createErrorPanel(gui.Tr.SLocalize("AlreadyCheckedOutBranch")) } branch := gui.getSelectedBranch() return gui.handleCheckoutRef(branch.Name, handleCheckoutRefOptions{}) @@ -101,7 +101,7 @@ func (gui *Gui) handleCreatePullRequestPress(g *gocui.Gui, v *gocui.View) error branch := gui.getSelectedBranch() if err := pullRequest.Create(branch); err != nil { - return gui.createErrorPanel(g, err.Error()) + return gui.surfaceError(err) } return nil @@ -124,7 +124,7 @@ func (gui *Gui) handleForceCheckout(g *gocui.Gui, v *gocui.View) error { title := gui.Tr.SLocalize("ForceCheckoutBranch") return gui.createConfirmationPanel(g, v, true, title, message, func(g *gocui.Gui, v *gocui.View) error { if err := gui.GitCommand.Checkout(branch.Name, commands.CheckoutOptions{Force: true}); err != nil { - _ = gui.createErrorPanel(g, err.Error()) + _ = gui.surfaceError(err) } return gui.refreshSidePanels(refreshOptions{mode: ASYNC}) }, nil) @@ -159,10 +159,10 @@ func (gui *Gui) handleCheckoutRef(ref string, options handleCheckoutRefOptions) return gui.createConfirmationPanel(gui.g, gui.getBranchesView(), true, gui.Tr.SLocalize("AutoStashTitle"), gui.Tr.SLocalize("AutoStashPrompt"), func(g *gocui.Gui, v *gocui.View) error { if err := gui.GitCommand.StashSave(gui.Tr.SLocalize("StashPrefix") + ref); err != nil { - return gui.createErrorPanel(g, err.Error()) + return gui.surfaceError(err) } if err := gui.GitCommand.Checkout(ref, cmdOptions); err != nil { - return gui.createErrorPanel(g, err.Error()) + return gui.surfaceError(err) } onSuccess() @@ -170,13 +170,13 @@ func (gui *Gui) handleCheckoutRef(ref string, options handleCheckoutRefOptions) if err := gui.refreshSidePanels(refreshOptions{mode: BLOCK_UI}); err != nil { return err } - return gui.createErrorPanel(g, err.Error()) + return gui.surfaceError(err) } return gui.refreshSidePanels(refreshOptions{mode: BLOCK_UI}) }, nil) } - if err := gui.createErrorPanel(gui.g, err.Error()); err != nil { + if err := gui.surfaceError(err); err != nil { return err } } @@ -213,7 +213,7 @@ func (gui *Gui) handleNewBranch(g *gocui.Gui, v *gocui.View) error { ) return gui.createPromptPanel(g, v, message, "", func(g *gocui.Gui, v *gocui.View) error { if err := gui.GitCommand.NewBranch(gui.trimmedContent(v), branch.Name); err != nil { - return gui.createErrorPanel(g, err.Error()) + return gui.surfaceError(err) } gui.State.Panels.Branches.SelectedLine = 0 return gui.refreshSidePanels(refreshOptions{mode: ASYNC}) @@ -231,7 +231,7 @@ func (gui *Gui) deleteBranch(g *gocui.Gui, v *gocui.View, force bool) error { } checkedOutBranch := gui.getCheckedOutBranch() if checkedOutBranch.Name == selectedBranch.Name { - return gui.createErrorPanel(g, gui.Tr.SLocalize("CantDeleteCheckOutBranch")) + return gui.createErrorPanel(gui.Tr.SLocalize("CantDeleteCheckOutBranch")) } return gui.deleteNamedBranch(g, v, selectedBranch, force) } @@ -256,7 +256,7 @@ func (gui *Gui) deleteNamedBranch(g *gocui.Gui, v *gocui.View, selectedBranch *c if !force && strings.Contains(errMessage, "is not fully merged") { return gui.deleteNamedBranch(g, v, selectedBranch, true) } - return gui.createErrorPanel(g, errMessage) + return gui.createErrorPanel(errMessage) } return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []int{BRANCHES}}) }, nil) @@ -264,11 +264,11 @@ func (gui *Gui) deleteNamedBranch(g *gocui.Gui, v *gocui.View, selectedBranch *c func (gui *Gui) mergeBranchIntoCheckedOutBranch(branchName string) error { if gui.GitCommand.IsHeadDetached() { - return gui.createErrorPanel(gui.g, "Cannot merge branch in detached head state. You might have checked out a commit directly or a remote branch, in which case you should checkout the local branch you want to be on") + return gui.createErrorPanel("Cannot merge branch in detached head state. You might have checked out a commit directly or a remote branch, in which case you should checkout the local branch you want to be on") } checkedOutBranchName := gui.getCheckedOutBranch().Name if checkedOutBranchName == branchName { - return gui.createErrorPanel(gui.g, gui.Tr.SLocalize("CantMergeBranchIntoItself")) + return gui.createErrorPanel(gui.Tr.SLocalize("CantMergeBranchIntoItself")) } prompt := gui.Tr.TemplateLocalize( "ConfirmMerge", @@ -298,7 +298,7 @@ func (gui *Gui) handleRebaseOntoLocalBranch(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleRebaseOntoBranch(selectedBranchName string) error { checkedOutBranch := gui.getCheckedOutBranch().Name if selectedBranchName == checkedOutBranch { - return gui.createErrorPanel(gui.g, gui.Tr.SLocalize("CantRebaseOntoSelf")) + return gui.createErrorPanel(gui.Tr.SLocalize("CantRebaseOntoSelf")) } prompt := gui.Tr.TemplateLocalize( "ConfirmRebase", @@ -323,15 +323,15 @@ func (gui *Gui) handleFastForward(g *gocui.Gui, v *gocui.View) error { return nil } if branch.Pushables == "?" { - return gui.createErrorPanel(gui.g, gui.Tr.SLocalize("FwdNoUpstream")) + return gui.createErrorPanel(gui.Tr.SLocalize("FwdNoUpstream")) } if branch.Pushables != "0" { - return gui.createErrorPanel(gui.g, gui.Tr.SLocalize("FwdCommitsToPush")) + return gui.createErrorPanel(gui.Tr.SLocalize("FwdCommitsToPush")) } upstream, err := gui.GitCommand.GetUpstreamForBranch(branch.Name) if err != nil { - return gui.createErrorPanel(gui.g, err.Error()) + return gui.surfaceError(err) } split := strings.Split(upstream, "/") @@ -350,12 +350,12 @@ func (gui *Gui) handleFastForward(g *gocui.Gui, v *gocui.View) error { if gui.State.Panels.Branches.SelectedLine == 0 { if err := gui.GitCommand.PullWithoutPasswordCheck("--ff-only"); err != nil { - _ = gui.createErrorPanel(gui.g, err.Error()) + _ = gui.surfaceError(err) } _ = gui.refreshSidePanels(refreshOptions{mode: ASYNC}) } else { if err := gui.GitCommand.FastForward(branch.Name, remoteName, remoteBranchName); err != nil { - _ = gui.createErrorPanel(gui.g, err.Error()) + _ = gui.surfaceError(err) } _ = gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []int{BRANCHES}}) } @@ -459,12 +459,12 @@ func (gui *Gui) handleRenameBranch(g *gocui.Gui, v *gocui.View) error { return gui.createPromptPanel(g, v, gui.Tr.SLocalize("NewBranchNamePrompt")+" "+branch.Name+":", "", func(g *gocui.Gui, v *gocui.View) error { newName := gui.trimmedContent(v) if err := gui.GitCommand.RenameBranch(branch.Name, newName); err != nil { - return gui.createErrorPanel(gui.g, err.Error()) + return gui.surfaceError(err) } // need to checkout so that the branch shows up in our reflog and therefore // doesn't get lost among all the other branches when we switch to something else if err := gui.GitCommand.Checkout(newName, commands.CheckoutOptions{Force: false}); err != nil { - return gui.createErrorPanel(gui.g, err.Error()) + return gui.surfaceError(err) } return gui.refreshSidePanels(refreshOptions{mode: ASYNC}) diff --git a/pkg/gui/commit_files_panel.go b/pkg/gui/commit_files_panel.go index 899b3137f..7431bf464 100644 --- a/pkg/gui/commit_files_panel.go +++ b/pkg/gui/commit_files_panel.go @@ -64,7 +64,7 @@ func (gui *Gui) handleCheckoutCommitFile(g *gocui.Gui, v *gocui.View) error { file := gui.State.CommitFiles[gui.State.Panels.CommitFiles.SelectedLine] if err := gui.GitCommand.CheckoutFile(file.Sha, file.Name); err != nil { - return gui.createErrorPanel(gui.g, err.Error()) + return gui.surfaceError(err) } return gui.refreshSidePanels(refreshOptions{mode: ASYNC}) @@ -106,7 +106,7 @@ func (gui *Gui) refreshCommitFilesView() error { files, err := gui.GitCommand.GetCommitFiles(commit.Sha, gui.GitCommand.PatchManager) if err != nil { - return gui.createErrorPanel(gui.g, err.Error()) + return gui.surfaceError(err) } gui.State.CommitFiles = files diff --git a/pkg/gui/commit_message_panel.go b/pkg/gui/commit_message_panel.go index 8c11e5a83..9ada7634e 100644 --- a/pkg/gui/commit_message_panel.go +++ b/pkg/gui/commit_message_panel.go @@ -15,7 +15,7 @@ import ( func (gui *Gui) runSyncOrAsyncCommand(sub *exec.Cmd, err error) (bool, error) { if err != nil { if err != gui.Errors.ErrSubProcess { - return false, gui.createErrorPanel(gui.g, err.Error()) + return false, gui.surfaceError(err) } } if sub != nil { @@ -28,7 +28,7 @@ func (gui *Gui) runSyncOrAsyncCommand(sub *exec.Cmd, err error) (bool, error) { func (gui *Gui) handleCommitConfirm(g *gocui.Gui, v *gocui.View) error { message := gui.trimmedContent(v) if message == "" { - return gui.createErrorPanel(g, gui.Tr.SLocalize("CommitWithoutMessageErr")) + return gui.createErrorPanel(gui.Tr.SLocalize("CommitWithoutMessageErr")) } flags := "" skipHookPrefix := gui.Config.GetUserConfig().GetString("git.skipHookPrefix") diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go index 7876a1a51..b19e0c5d0 100644 --- a/pkg/gui/commits_panel.go +++ b/pkg/gui/commits_panel.go @@ -40,7 +40,7 @@ func (gui *Gui) handleCommitSelect(g *gocui.Gui, v *gocui.View) error { state.LimitCommits = false go func() { if err := gui.refreshCommitsWithLimit(); err != nil { - _ = gui.createErrorPanel(gui.g, err.Error()) + _ = gui.surfaceError(err) } }() } @@ -79,13 +79,13 @@ func (gui *Gui) refreshReflogCommitsConsideringStartup() { switch gui.State.StartupStage { case INITIAL: go func() { - gui.refreshReflogCommits() + _ = gui.refreshReflogCommits() gui.refreshBranches() gui.State.StartupStage = COMPLETE }() case COMPLETE: - gui.refreshReflogCommits() + _ = gui.refreshReflogCommits() } } @@ -104,9 +104,9 @@ func (gui *Gui) refreshCommits() error { }() go func() { - gui.refreshCommitsWithLimit() + _ = gui.refreshCommitsWithLimit() if gui.g.CurrentView() == gui.getCommitFilesView() || (gui.g.CurrentView() == gui.getMainView() && gui.State.MainContext == "patch-building") { - gui.refreshCommitFilesView() + _ = gui.refreshCommitFilesView() } wg.Done() }() @@ -141,7 +141,7 @@ func (gui *Gui) refreshCommitsWithLimit() error { func (gui *Gui) handleCommitSquashDown(g *gocui.Gui, v *gocui.View) error { if len(gui.State.Commits) <= 1 { - return gui.createErrorPanel(g, gui.Tr.SLocalize("YouNoCommitsToSquash")) + return gui.createErrorPanel(gui.Tr.SLocalize("YouNoCommitsToSquash")) } applied, err := gui.handleMidRebaseCommand("squash") @@ -162,7 +162,7 @@ func (gui *Gui) handleCommitSquashDown(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleCommitFixup(g *gocui.Gui, v *gocui.View) error { if len(gui.State.Commits) <= 1 { - return gui.createErrorPanel(g, gui.Tr.SLocalize("YouNoCommitsToSquash")) + return gui.createErrorPanel(gui.Tr.SLocalize("YouNoCommitsToSquash")) } applied, err := gui.handleMidRebaseCommand("fixup") @@ -191,11 +191,11 @@ func (gui *Gui) handleRenameCommit(g *gocui.Gui, v *gocui.View) error { } if gui.State.Panels.Commits.SelectedLine != 0 { - return gui.createErrorPanel(g, gui.Tr.SLocalize("OnlyRenameTopCommit")) + return gui.createErrorPanel(gui.Tr.SLocalize("OnlyRenameTopCommit")) } return gui.createPromptPanel(g, v, gui.Tr.SLocalize("renameCommit"), "", func(g *gocui.Gui, v *gocui.View) error { if err := gui.GitCommand.RenameCommit(v.Buffer()); err != nil { - return gui.createErrorPanel(g, err.Error()) + return gui.surfaceError(err) } return gui.refreshSidePanels(refreshOptions{mode: ASYNC}) @@ -213,7 +213,7 @@ func (gui *Gui) handleRenameCommitEditor(g *gocui.Gui, v *gocui.View) error { subProcess, err := gui.GitCommand.RewordCommit(gui.State.Commits, gui.State.Panels.Commits.SelectedLine) if err != nil { - return gui.createErrorPanel(gui.g, err.Error()) + return gui.surfaceError(err) } if subProcess != nil { gui.SubProcess = subProcess @@ -237,11 +237,11 @@ func (gui *Gui) handleMidRebaseCommand(action string) (bool, error) { // our input or we set a lazygit client as the EDITOR env variable and have it // request us to edit the commit message when prompted. if action == "reword" { - return true, gui.createErrorPanel(gui.g, gui.Tr.SLocalize("rewordNotSupported")) + return true, gui.createErrorPanel(gui.Tr.SLocalize("rewordNotSupported")) } if err := gui.GitCommand.EditRebaseTodo(gui.State.Panels.Commits.SelectedLine, action); err != nil { - return false, gui.createErrorPanel(gui.g, err.Error()) + return false, gui.surfaceError(err) } // TODO: consider doing this in a way that is less expensive. We don't actually // need to reload all the commits, just the TODO commits. @@ -273,7 +273,7 @@ func (gui *Gui) handleCommitMoveDown(g *gocui.Gui, v *gocui.View) error { return nil } if err := gui.GitCommand.MoveTodoDown(index); err != nil { - return gui.createErrorPanel(gui.g, err.Error()) + return gui.surfaceError(err) } gui.State.Panels.Commits.SelectedLine++ return gui.refreshSidePanels(refreshOptions{mode: BLOCK_UI, scope: []int{COMMITS, BRANCHES}}) @@ -296,7 +296,7 @@ func (gui *Gui) handleCommitMoveUp(g *gocui.Gui, v *gocui.View) error { selectedCommit := gui.State.Commits[index] if selectedCommit.Status == "rebasing" { if err := gui.GitCommand.MoveTodoDown(index - 1); err != nil { - return gui.createErrorPanel(gui.g, err.Error()) + return gui.surfaceError(err) } gui.State.Panels.Commits.SelectedLine-- return gui.refreshSidePanels(refreshOptions{mode: BLOCK_UI, scope: []int{COMMITS, BRANCHES}}) @@ -351,7 +351,7 @@ func (gui *Gui) handleCommitPick(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleCommitRevert(g *gocui.Gui, v *gocui.View) error { if err := gui.GitCommand.Revert(gui.State.Commits[gui.State.Panels.Commits.SelectedLine].Sha); err != nil { - return gui.createErrorPanel(gui.g, err.Error()) + return gui.surfaceError(err) } gui.State.Panels.Commits.SelectedLine++ return gui.refreshSidePanels(refreshOptions{mode: BLOCK_UI, scope: []int{COMMITS, BRANCHES}}) @@ -462,7 +462,7 @@ func (gui *Gui) handleToggleDiffCommit(g *gocui.Gui, v *gocui.View) error { commitText, err := gui.GitCommand.DiffCommits(gui.State.DiffEntries[0].Sha, gui.State.DiffEntries[1].Sha) if err != nil { - return gui.createErrorPanel(gui.g, err.Error()) + return gui.surfaceError(err) } gui.newStringTask("main", commitText) @@ -507,7 +507,7 @@ func (gui *Gui) handleCreateFixupCommit(g *gocui.Gui, v *gocui.View) error { }, ), func(g *gocui.Gui, v *gocui.View) error { if err := gui.GitCommand.CreateFixupCommit(commit.Sha); err != nil { - return gui.createErrorPanel(g, err.Error()) + return gui.surfaceError(err) } return gui.refreshSidePanels(refreshOptions{mode: ASYNC}) @@ -548,7 +548,7 @@ func (gui *Gui) handleTagCommit(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleCreateLightweightTag(commitSha string) error { return gui.createPromptPanel(gui.g, gui.getCommitsView(), gui.Tr.SLocalize("TagNameTitle"), "", func(g *gocui.Gui, v *gocui.View) error { if err := gui.GitCommand.CreateLightweightTag(v.Buffer(), commitSha); err != nil { - return gui.createErrorPanel(g, err.Error()) + return gui.surfaceError(err) } return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []int{COMMITS, TAGS}}) }) @@ -633,7 +633,7 @@ func (gui *Gui) handlePrevCommitsTab(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleCreateCommitResetMenu(g *gocui.Gui, v *gocui.View) error { commit := gui.getSelectedCommit(g) if commit == nil { - return gui.createErrorPanel(gui.g, gui.Tr.SLocalize("NoCommitsThisBranch")) + return gui.createErrorPanel(gui.Tr.SLocalize("NoCommitsThisBranch")) } return gui.createResetMenu(commit.Sha) diff --git a/pkg/gui/confirmation_panel.go b/pkg/gui/confirmation_panel.go index 112f4769a..0e0a3ac63 100644 --- a/pkg/gui/confirmation_panel.go +++ b/pkg/gui/confirmation_panel.go @@ -182,6 +182,10 @@ func (gui *Gui) createSpecificErrorPanel(message string, nextView *gocui.View, w return gui.createConfirmationPanel(gui.g, nextView, true, gui.Tr.SLocalize("Error"), coloredMessage, nil, nil) } -func (gui *Gui) createErrorPanel(g *gocui.Gui, message string) error { - return gui.createSpecificErrorPanel(message, g.CurrentView(), true) +func (gui *Gui) createErrorPanel(message string) error { + return gui.createSpecificErrorPanel(message, gui.g.CurrentView(), true) +} + +func (gui *Gui) surfaceError(err error) error { + return gui.createErrorPanel(err.Error()) } diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index 21195957e..b78d1b752 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -163,7 +163,7 @@ func (gui *Gui) enterFile(forceSecondaryFocused bool, selectedLineIdx int) error return gui.handleSwitchToMerge(gui.g, gui.getFilesView()) } if file.HasMergeConflicts { - return gui.createErrorPanel(gui.g, gui.Tr.SLocalize("FileStagingRequirements")) + return gui.createErrorPanel(gui.Tr.SLocalize("FileStagingRequirements")) } gui.changeMainViewsContext("staging") if err := gui.switchFocus(gui.g, gui.getFilesView(), gui.getMainView()); err != nil { @@ -191,7 +191,7 @@ func (gui *Gui) handleFilePress(g *gocui.Gui, v *gocui.View) error { err = gui.GitCommand.UnStageFile(file.Name, file.Tracked) } if err != nil { - return gui.createErrorPanel(gui.g, err.Error()) + return gui.surfaceError(err) } if err := gui.refreshSidePanels(refreshOptions{scope: []int{FILES}}); err != nil { @@ -226,7 +226,7 @@ func (gui *Gui) handleStageAll(g *gocui.Gui, v *gocui.View) error { err = gui.GitCommand.StageAll() } if err != nil { - _ = gui.createErrorPanel(g, err.Error()) + _ = gui.surfaceError(err) } if err := gui.refreshSidePanels(refreshOptions{scope: []int{FILES}}); err != nil { @@ -239,7 +239,7 @@ func (gui *Gui) handleStageAll(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleIgnoreFile(g *gocui.Gui, v *gocui.View) error { file, err := gui.getSelectedFile(gui.g) if err != nil { - return gui.createErrorPanel(gui.g, err.Error()) + return gui.surfaceError(err) } if file.Tracked { @@ -257,7 +257,7 @@ func (gui *Gui) handleIgnoreFile(g *gocui.Gui, v *gocui.View) error { } if err := gui.GitCommand.Ignore(file.Name); err != nil { - return gui.createErrorPanel(gui.g, err.Error()) + return gui.surfaceError(err) } return gui.refreshSidePanels(refreshOptions{scope: []int{FILES}}) @@ -266,7 +266,7 @@ func (gui *Gui) handleIgnoreFile(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleWIPCommitPress(g *gocui.Gui, filesView *gocui.View) error { skipHookPreifx := gui.Config.GetUserConfig().GetString("git.skipHookPrefix") if skipHookPreifx == "" { - return gui.createErrorPanel(gui.g, gui.Tr.SLocalize("SkipHookPrefixNotConfigured")) + return gui.createErrorPanel(gui.Tr.SLocalize("SkipHookPrefixNotConfigured")) } gui.renderString(g, "commitMessage", skipHookPreifx) @@ -279,7 +279,7 @@ func (gui *Gui) handleWIPCommitPress(g *gocui.Gui, filesView *gocui.View) error func (gui *Gui) handleCommitPress(g *gocui.Gui, filesView *gocui.View) error { if len(gui.stagedFiles()) == 0 && gui.workingTreeState() == "normal" { - return gui.createErrorPanel(g, gui.Tr.SLocalize("NoStagedFilesToCommit")) + return gui.createErrorPanel(gui.Tr.SLocalize("NoStagedFilesToCommit")) } commitMessageView := gui.getCommitMessageView() g.Update(func(g *gocui.Gui) error { @@ -299,10 +299,10 @@ func (gui *Gui) handleCommitPress(g *gocui.Gui, filesView *gocui.View) error { func (gui *Gui) handleAmendCommitPress(g *gocui.Gui, filesView *gocui.View) error { if len(gui.stagedFiles()) == 0 && gui.workingTreeState() == "normal" { - return gui.createErrorPanel(g, gui.Tr.SLocalize("NoStagedFilesToCommit")) + return gui.createErrorPanel(gui.Tr.SLocalize("NoStagedFilesToCommit")) } if len(gui.State.Commits) == 0 { - return gui.createErrorPanel(g, gui.Tr.SLocalize("NoCommitToAmend")) + return gui.createErrorPanel(gui.Tr.SLocalize("NoCommitToAmend")) } title := strings.Title(gui.Tr.SLocalize("AmendLastCommit")) @@ -325,7 +325,7 @@ func (gui *Gui) handleAmendCommitPress(g *gocui.Gui, filesView *gocui.View) erro // their editor rather than via the popup panel func (gui *Gui) handleCommitEditorPress(g *gocui.Gui, filesView *gocui.View) error { if len(gui.stagedFiles()) == 0 && gui.workingTreeState() == "normal" { - return gui.createErrorPanel(g, gui.Tr.SLocalize("NoStagedFilesToCommit")) + return gui.createErrorPanel(gui.Tr.SLocalize("NoStagedFilesToCommit")) } gui.PrepareSubProcess(g, "git", "commit") return nil @@ -347,7 +347,7 @@ func (gui *Gui) editFile(filename string) error { func (gui *Gui) handleFileEdit(g *gocui.Gui, v *gocui.View) error { file, err := gui.getSelectedFile(g) if err != nil { - return gui.createErrorPanel(gui.g, err.Error()) + return gui.surfaceError(err) } return gui.editFile(file.Name) @@ -356,7 +356,7 @@ func (gui *Gui) handleFileEdit(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleFileOpen(g *gocui.Gui, v *gocui.View) error { file, err := gui.getSelectedFile(g) if err != nil { - return gui.createErrorPanel(gui.g, err.Error()) + return gui.surfaceError(err) } return gui.openFile(file.Name) } @@ -404,7 +404,7 @@ func (gui *Gui) handlePullFiles(g *gocui.Gui, v *gocui.View) error { // see if we have this branch in our config with an upstream conf, err := gui.GitCommand.Repo.Config() if err != nil { - return gui.createErrorPanel(gui.g, err.Error()) + return gui.surfaceError(err) } for branchName, branch := range conf.Branches { if branchName == currentBranch.Name { @@ -419,7 +419,7 @@ func (gui *Gui) handlePullFiles(g *gocui.Gui, v *gocui.View) 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(gui.g, errorMessage) + return gui.createErrorPanel(errorMessage) } return gui.pullFiles(v, "") }) @@ -469,7 +469,7 @@ func (gui *Gui) pushFiles(g *gocui.Gui, v *gocui.View) error { // see if we have this branch in our config with an upstream conf, err := gui.GitCommand.Repo.Config() if err != nil { - return gui.createErrorPanel(gui.g, err.Error()) + return gui.surfaceError(err) } for branchName, branch := range conf.Branches { if branchName == currentBranch.Name { @@ -492,12 +492,12 @@ func (gui *Gui) handleSwitchToMerge(g *gocui.Gui, v *gocui.View) error { file, err := gui.getSelectedFile(g) if err != nil { if err != gui.Errors.ErrNoFiles { - return gui.createErrorPanel(gui.g, err.Error()) + return gui.surfaceError(err) } return nil } if !file.HasInlineMergeConflicts { - return gui.createErrorPanel(g, gui.Tr.SLocalize("FileNoMergeCons")) + return gui.createErrorPanel(gui.Tr.SLocalize("FileNoMergeCons")) } gui.changeMainViewsContext("merging") if err := gui.switchFocus(g, v, gui.getMainView()); err != nil { @@ -508,7 +508,7 @@ func (gui *Gui) handleSwitchToMerge(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) openFile(filename string) error { if err := gui.OSCommand.OpenFile(filename); err != nil { - return gui.createErrorPanel(gui.g, err.Error()) + return gui.surfaceError(err) } return nil } diff --git a/pkg/gui/git_flow.go b/pkg/gui/git_flow.go index f265c9ccd..ce460edd6 100644 --- a/pkg/gui/git_flow.go +++ b/pkg/gui/git_flow.go @@ -28,7 +28,7 @@ func (gui *Gui) gitFlowFinishBranch(gitFlowConfig string, branchName string) err } if branchType == "" { - return gui.createErrorPanel(gui.g, gui.Tr.SLocalize("NotAGitFlowBranch")) + return gui.createErrorPanel(gui.Tr.SLocalize("NotAGitFlowBranch")) } subProcess := gui.OSCommand.PrepareSubProcess("git", "flow", branchType, "finish", suffix) @@ -45,7 +45,7 @@ func (gui *Gui) handleCreateGitFlowMenu(g *gocui.Gui, v *gocui.View) error { // get config gitFlowConfig, err := gui.OSCommand.RunCommandWithOutput("git config --local --get-regexp gitflow") if err != nil { - return gui.createErrorPanel(gui.g, "You need to install git-flow and enable it in this repo to use git-flow features") + return gui.createErrorPanel("You need to install git-flow and enable it in this repo to use git-flow features") } startHandler := func(branchType string) func() error { diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 7f7e040f0..624cf2b5f 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -885,7 +885,7 @@ func (gui *Gui) showInitialPopups(tasks []func(chan struct{}) error) { for _, task := range tasks { go func() { if err := task(done); err != nil { - _ = gui.createErrorPanel(gui.g, err.Error()) + _ = gui.surfaceError(err) } }() diff --git a/pkg/gui/patch_options_panel.go b/pkg/gui/patch_options_panel.go index c47374889..2fa274f7c 100644 --- a/ |