1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-13 01:30:53 +02:00

Change Refresh to not return an error

Refresh is one of those functions that shouldn't require error handling (similar
to triggering a redraw of the UI, see
https://github.com/jesseduffield/lazygit/issues/3887).

As far as I see, the only reason why Refresh can currently return an error is
that the Then function returns one. The actual refresh errors, e.g. from the git
calls that are made to fetch data, are already logged and swallowed. Most of the
Then functions do only UI stuff such as selecting a list item, and always return
nil; there's only one that can return an error (updating the rebase todo file in
LocalCommitsController.startInteractiveRebaseWithEdit); it's not a critical
error if this fails, it is only used for setting rebase todo items to "edit"
when you start an interactive rebase by pressing 'e' on a range selection of
commits. We simply log this error instead of returning it.
This commit is contained in:
Stefan Haller
2025-07-02 11:58:13 +02:00
parent 2b1f150129
commit d82852a909
43 changed files with 253 additions and 217 deletions

View File

@ -93,7 +93,8 @@ func (self *BackgroundRoutineMgr) startBackgroundFilesRefresh(refreshInterval in
self.gui.waitForIntro.Wait()
self.goEvery(time.Second*time.Duration(refreshInterval), self.gui.stopChan, func() error {
return self.gui.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.FILES}})
self.gui.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.FILES}})
return nil
})
}
@ -125,7 +126,7 @@ func (self *BackgroundRoutineMgr) goEvery(interval time.Duration, stop chan stru
func (self *BackgroundRoutineMgr) backgroundFetch() (err error) {
err = self.gui.git.Sync.FetchBackground()
_ = self.gui.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.BRANCHES, types.COMMITS, types.REMOTES, types.TAGS}, Mode: types.SYNC})
self.gui.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.BRANCHES, types.COMMITS, types.REMOTES, types.TAGS}, Mode: types.SYNC})
if err == nil {
err = self.gui.helpers.BranchesHelper.AutoForwardBranches()

View File

@ -175,7 +175,8 @@ func (self *BisectController) openStartBisectMenu(info *git_commands.BisectInfo,
return err
}
return self.c.Helpers().Bisect.PostBisectCommandRefresh()
self.c.Helpers().Bisect.PostBisectCommandRefresh()
return nil
},
DisabledReason: self.require(self.singleItemSelected())(),
Key: 'b',
@ -192,7 +193,8 @@ func (self *BisectController) openStartBisectMenu(info *git_commands.BisectInfo,
return err
}
return self.c.Helpers().Bisect.PostBisectCommandRefresh()
self.c.Helpers().Bisect.PostBisectCommandRefresh()
return nil
},
DisabledReason: self.require(self.singleItemSelected())(),
Key: 'g',
@ -211,7 +213,8 @@ func (self *BisectController) openStartBisectMenu(info *git_commands.BisectInfo,
return err
}
return self.c.Helpers().Bisect.PostBisectCommandRefresh()
self.c.Helpers().Bisect.PostBisectCommandRefresh()
return nil
},
})
return nil
@ -245,7 +248,8 @@ func (self *BisectController) showBisectCompleteMessage(candidateHashes []string
return err
}
return self.c.Helpers().Bisect.PostBisectCommandRefresh()
self.c.Helpers().Bisect.PostBisectCommandRefresh()
return nil
},
})
@ -270,20 +274,21 @@ func (self *BisectController) afterMark(selectCurrent bool, waitToReselect bool)
}
func (self *BisectController) afterBisectMarkRefresh(selectCurrent bool, waitToReselect bool) error {
selectFn := func() error {
selectFn := func() {
if selectCurrent {
self.selectCurrentBisectCommit()
}
return nil
}
if waitToReselect {
return self.c.Refresh(types.RefreshOptions{Mode: types.SYNC, Scope: []types.RefreshableView{}, Then: selectFn})
self.c.Refresh(types.RefreshOptions{Mode: types.SYNC, Scope: []types.RefreshableView{}, Then: selectFn})
return nil
}
_ = selectFn()
selectFn()
return self.c.Helpers().Bisect.PostBisectCommandRefresh()
self.c.Helpers().Bisect.PostBisectCommandRefresh()
return nil
}
func (self *BisectController) selectCurrentBisectCommit() {

View File

@ -263,15 +263,13 @@ func (self *BranchesController) viewUpstreamOptions(selectedBranch *models.Branc
if err := self.c.Git().Branch.UnsetUpstream(selectedBranch.Name); err != nil {
return err
}
if err := self.c.Refresh(types.RefreshOptions{
self.c.Refresh(types.RefreshOptions{
Mode: types.SYNC,
Scope: []types.RefreshableView{
types.BRANCHES,
types.COMMITS,
},
}); err != nil {
return err
}
})
return nil
},
Key: 'u',
@ -289,15 +287,13 @@ func (self *BranchesController) viewUpstreamOptions(selectedBranch *models.Branc
if err := self.c.Git().Branch.SetUpstream(upstreamRemote, upstreamBranch, selectedBranch.Name); err != nil {
return err
}
if err := self.c.Refresh(types.RefreshOptions{
self.c.Refresh(types.RefreshOptions{
Mode: types.SYNC,
Scope: []types.RefreshableView{
types.BRANCHES,
types.COMMITS,
},
}); err != nil {
return err
}
})
return nil
})
},
@ -478,7 +474,8 @@ func (self *BranchesController) forceCheckout() error {
if err := self.c.Git().Branch.Checkout(branch.Name, git_commands.CheckoutOptions{Force: true}); err != nil {
return err
}
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
return nil
},
})
@ -526,7 +523,8 @@ func (self *BranchesController) createNewBranchWithName(newBranchName string) er
}
self.context().SetSelection(0)
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, KeepBranchSelectionIndex: true})
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, KeepBranchSelectionIndex: true})
return nil
}
func (self *BranchesController) localDelete(branches []*models.Branch) error {
@ -655,7 +653,7 @@ func (self *BranchesController) fastForward(branch *models.Branch) error {
WorktreePath: worktreePath,
},
)
_ = self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
return err
}
@ -664,7 +662,7 @@ func (self *BranchesController) fastForward(branch *models.Branch) error {
err := self.c.Git().Sync.FastForward(
task, branch.Name, branch.UpstreamRemote, branch.UpstreamBranch,
)
_ = self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.BRANCHES}})
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.BRANCHES}})
return err
})
}
@ -679,7 +677,8 @@ func (self *BranchesController) createSortMenu() error {
self.c.GetAppState().LocalBranchSortOrder = sortOrder
self.c.SaveAppStateAndLogError()
self.c.Contexts().Branches.SetSelection(0)
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.BRANCHES}})
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.BRANCHES}})
return nil
}
return nil
},
@ -702,7 +701,7 @@ func (self *BranchesController) rename(branch *models.Branch) error {
}
// need to find where the branch is now so that we can re-select it. That means we need to refetch the branches synchronously and then find our branch
_ = self.c.Refresh(types.RefreshOptions{
self.c.Refresh(types.RefreshOptions{
Mode: types.SYNC,
Scope: []types.RefreshableView{types.BRANCHES, types.WORKTREES},
})

View File

@ -289,7 +289,8 @@ func (self *CommitFilesController) checkout(node *filetree.CommitFileNode) error
return err
}
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
return nil
}
func (self *CommitFilesController) discard(selectedNodes []*filetree.CommitFileNode) error {

View File

@ -103,13 +103,13 @@ func (self *ContextLinesController) applyChange() error {
switch currentContext.GetKey() {
// we make an exception for our staging and patch building contexts because they actually need to refresh their state afterwards.
case context.PATCH_BUILDING_MAIN_CONTEXT_KEY:
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.PATCH_BUILDING}})
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.PATCH_BUILDING}})
case context.STAGING_MAIN_CONTEXT_KEY, context.STAGING_SECONDARY_CONTEXT_KEY:
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.STAGING}})
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.STAGING}})
default:
currentContext.HandleRenderToMain()
return nil
}
return nil
}
func (self *ContextLinesController) checkCanChangeContext() error {

View File

@ -275,7 +275,8 @@ func (self *CustomPatchOptionsMenuAction) handleApplyPatch(reverse bool) error {
if err := self.c.Git().Patch.ApplyCustomPatch(reverse, true); err != nil {
return err
}
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
return nil
}
func (self *CustomPatchOptionsMenuAction) copyPatchToClipboard() error {

View File

@ -23,7 +23,8 @@ func (self *DiffingMenuAction) Call() error {
OnPress: func() error {
self.c.Modes().Diffing.Ref = name
// can scope this down based on current view but too lazy right now
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
return nil
},
},
}...)
@ -38,7 +39,8 @@ func (self *DiffingMenuAction) Call() error {
FindSuggestionsFunc: self.c.Helpers().Suggestions.GetRefsSuggestionsFunc(),
HandleConfirm: func(response string) error {
self.c.Modes().Diffing.Ref = strings.TrimSpace(response)
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
return nil
},
})
@ -53,14 +55,16 @@ func (self *DiffingMenuAction) Call() error {
Label: self.c.Tr.SwapDiff,
OnPress: func() error {
self.c.Modes().Diffing.Reverse = !self.c.Modes().Diffing.Reverse
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
return nil
},
},
{
Label: self.c.Tr.ExitDiffMode,
OnPress: func() error {
self.c.Modes().Diffing = diffing.New()
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
return nil
},
},
}...)

View File

@ -486,9 +486,7 @@ func (self *FilesController) press(nodes []*filetree.FileNode) error {
return err
}
if err := self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.FILES}, Mode: types.ASYNC}); err != nil {
return err
}
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.FILES}, Mode: types.ASYNC})
self.context().HandleFocus(types.OnFocusOpts{})
return nil
@ -566,7 +564,8 @@ func (self *FilesController) handleNonInlineConflict(file *models.File) error {
if err := command(file.GetPath()); err != nil {
return err
}
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.FILES}})
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.FILES}})
return nil
}
keepItem := &types.MenuItem{
Label: self.c.Tr.MergeConflictKeepFile,
@ -611,9 +610,7 @@ func (self *FilesController) toggleStagedAll() error {
return err
}
if err := self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.FILES}, Mode: types.ASYNC}); err != nil {
return err
}
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.FILES}, Mode: types.ASYNC})
self.context().HandleFocus(types.OnFocusOpts{})
return nil
@ -683,7 +680,8 @@ func (self *FilesController) ignoreOrExcludeTracked(node *filetree.FileNode, trA
return err
}
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.FILES}})
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.FILES}})
return nil
}
func (self *FilesController) ignoreOrExcludeUntracked(node *filetree.FileNode, trAction string, f func(string) error) error {
@ -693,7 +691,8 @@ func (self *FilesController) ignoreOrExcludeUntracked(node *filetree.FileNode, t
return err
}
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.FILES}})
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.FILES}})
return nil
}
func (self *FilesController) ignoreOrExcludeFile(node *filetree.FileNode, trText string, trPrompt string, trAction string, f func(string) error) error {
@ -755,7 +754,8 @@ func (self *FilesController) ignoreOrExcludeMenu(node *filetree.FileNode) error
}
func (self *FilesController) refresh() error {
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.FILES}})
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.FILES}})
return nil
}
func (self *FilesController) handleAmendCommitPress() error {
@ -900,10 +900,10 @@ func (self *FilesController) setStatusFiltering(filter filetree.FileTreeDisplayF
// Whenever we switch between untracked and other filters, we need to refresh the files view
// because the untracked files filter applies when running `git status`.
if previousFilter != filter && (previousFilter == filetree.DisplayUntracked || filter == filetree.DisplayUntracked) {
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.FILES}, Mode: types.ASYNC})
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.FILES}, Mode: types.ASYNC})
} else {
self.c.PostRefreshUpdate(self.context())
}
self.c.PostRefreshUpdate(self.context())
return nil
}
@ -1177,7 +1177,8 @@ func (self *FilesController) handleStashSave(stashFunc func(message string) erro
if err := stashFunc(stashComment); err != nil {
return err
}
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.STASH, types.FILES}})
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.STASH, types.FILES}})
return nil
},
})
@ -1197,7 +1198,7 @@ func (self *FilesController) fetch() error {
return errors.New(self.c.Tr.PassUnameWrong)
}
_ = self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.BRANCHES, types.COMMITS, types.REMOTES, types.TAGS}, Mode: types.SYNC})
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.BRANCHES, types.COMMITS, types.REMOTES, types.TAGS}, Mode: types.SYNC})
if err == nil {
err = self.c.Helpers().BranchesHelper.AutoForwardBranches()
@ -1322,7 +1323,8 @@ func (self *FilesController) remove(selectedNodes []*filetree.FileNode) error {
}
}
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES, types.WORKTREES}})
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES, types.WORKTREES}})
return nil
},
Key: self.c.KeybindingsOpts().GetKey(self.c.UserConfig().Keybinding.Files.ConfirmDiscard),
Tooltip: utils.ResolvePlaceholderString(
@ -1348,7 +1350,8 @@ func (self *FilesController) remove(selectedNodes []*filetree.FileNode) error {
}
}
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES, types.WORKTREES}})
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES, types.WORKTREES}})
return nil
},
Key: 'u',
Tooltip: utils.ResolvePlaceholderString(
@ -1389,7 +1392,8 @@ func (self *FilesController) ResetSubmodule(submodule *models.SubmoduleConfig) e
return err
}
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES, types.SUBMODULES}})
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES, types.SUBMODULES}})
return nil
})
}

View File

@ -122,9 +122,10 @@ func (self *FilteringMenuAction) setFiltering() error {
self.c.Context().Push(self.c.Contexts().LocalCommits, types.OnFocusOpts{})
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.COMMITS}, Then: func() error {
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.COMMITS}, Then: func() {
self.c.Contexts().LocalCommits.SetSelection(0)
self.c.Contexts().LocalCommits.FocusLine()
return nil
}})
return nil
}

View File

@ -143,7 +143,8 @@ func (self *GlobalController) createCustomPatchOptionsMenu() error {
}
func (self *GlobalController) refresh() error {
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
return nil
}
func (self *GlobalController) nextScreenMode() error {

View File

@ -22,13 +22,14 @@ func (self *BisectHelper) Reset() error {
return err
}
return self.PostBisectCommandRefresh()
self.PostBisectCommandRefresh()
return nil
},
})
return nil
}
func (self *BisectHelper) PostBisectCommandRefresh() error {
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{}})
func (self *BisectHelper) PostBisectCommandRefresh() {
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{}})
}

View File

@ -49,7 +49,8 @@ func (self *BranchesHelper) ConfirmLocalDelete(branches []*models.Branch) error
}
selectionStart, _ := self.c.Contexts().Branches.GetSelectionRange()
self.c.Contexts().Branches.SetSelectedLineIdx(selectionStart)
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.BRANCHES}})
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.BRANCHES}})
return nil
})
}
@ -113,7 +114,8 @@ func (self *BranchesHelper) ConfirmDeleteRemote(remoteBranches []*models.RemoteB
if err := self.deleteRemoteBranches(remoteBranches, task); err != nil {
return err
}
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.BRANCHES, types.REMOTES}})
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.BRANCHES, types.REMOTES}})
return nil
})
},
})
@ -181,7 +183,8 @@ func (self *BranchesHelper) ConfirmLocalAndRemoteDelete(branches []*models.Branc
selectionStart, _ := self.c.Contexts().Branches.GetSelectionRange()
self.c.Contexts().Branches.SetSelectedLineIdx(selectionStart)
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.BRANCHES, types.REMOTES}})
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.BRANCHES, types.REMOTES}})
return nil
})
},
})
@ -295,7 +298,7 @@ func (self *BranchesHelper) AutoForwardBranches() error {
self.c.LogCommand(strings.TrimRight(updateCommands, "\n"), false)
err := self.c.Git().Branch.UpdateBranchRefs(updateCommands)
_ = self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.BRANCHES}, Mode: types.SYNC})
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.BRANCHES}, Mode: types.SYNC})
return err
}

View File

@ -33,7 +33,8 @@ func (self *CredentialsHelper) PromptUserForCredential(passOrUname oscommands.Cr
HandleConfirm: func(input string) error {
ch <- input + "\n"
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
return nil
},
HandleClose: func() error {
ch <- "\n"

View File

@ -72,7 +72,8 @@ func (self *DiffHelper) GetUpdateTaskForRenderingCommitsDiff(commit *models.Comm
func (self *DiffHelper) ExitDiffMode() error {
self.c.Modes().Diffing = diffing.New()
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
return nil
}
func (self *DiffHelper) RenderDiff() {

View File

@ -133,7 +133,7 @@ func (self *FixupHelper) HandleFindBaseCommitForFixupPress() error {
if err := self.c.Git().WorkingTree.StageAll(); err != nil {
return err
}
_ = self.c.Refresh(types.RefreshOptions{Mode: types.SYNC, Scope: []types.RefreshableView{types.FILES}})
self.c.Refresh(types.RefreshOptions{Mode: types.SYNC, Scope: []types.RefreshableView{types.FILES}})
}
self.c.Contexts().LocalCommits.SetSelection(index)

View File

@ -32,9 +32,7 @@ func (self *GpgHelper) WithGpgHandling(cmdObj *oscommands.CmdObj, configKey git_
return err
}
}
if err := self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: refreshScope}); err != nil {
return err
}
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: refreshScope})
return err
}
@ -45,7 +43,7 @@ func (self *GpgHelper) WithGpgHandling(cmdObj *oscommands.CmdObj, configKey git_
func (self *GpgHelper) runAndStream(cmdObj *oscommands.CmdObj, waitingStatus string, onSuccess func() error, refreshScope []types.RefreshableView) error {
return self.c.WithWaitingStatus(waitingStatus, func(gocui.Task) error {
if err := cmdObj.StreamOutput().Run(); err != nil {
_ = self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: refreshScope})
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: refreshScope})
return fmt.Errorf(
self.c.Tr.GitCommandFailed, self.c.UserConfig().Keybinding.Universal.ExtrasMenu,
)
@ -57,6 +55,7 @@ func (self *GpgHelper) runAndStream(cmdObj *oscommands.CmdObj, waitingStatus str
}
}
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: refreshScope})
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: refreshScope})
return nil
})
}

View File

@ -150,9 +150,8 @@ func isMergeConflictErr(errStr string) bool {
}
func (self *MergeAndRebaseHelper) CheckMergeOrRebaseWithRefreshOptions(result error, refreshOptions types.RefreshOptions) error {
if err := self.c.Refresh(refreshOptions); err != nil {
return err
}
self.c.Refresh(refreshOptions)
if result == nil {
return nil
} else if strings.Contains(result.Error(), "No changes - did you forget to use") {
@ -234,11 +233,9 @@ func (self *MergeAndRebaseHelper) PromptToContinueRebase() error {
// Need to refresh the files to be really sure if this is the case.
// We would otherwise be relying on lazygit's auto-refresh on focus,
// but this is not supported by all terminals or on all platforms.
if err := self.c.Refresh(types.RefreshOptions{
self.c.Refresh(types.RefreshOptions{
Mode: types.SYNC, Scope: []types.RefreshableView{types.FILES},
}); err != nil {
return err
}
})
root := self.c.Contexts().Files.FileTreeViewModel.GetRoot()
if root.GetHasUnstagedChanges() {
@ -457,7 +454,8 @@ func (self *MergeAndRebaseHelper) SquashMergeCommitted(refName, checkedOutBranch
if err != nil {
return err
}
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
return nil
}
}

View File

@ -167,9 +167,9 @@ func (self *ModeHelper) ClearFiltering() error {
self.c.State().GetRepoState().SetScreenMode(types.SCREEN_NORMAL)
}
return self.c.Refresh(types.RefreshOptions{
self.c.Refresh(types.RefreshOptions{
Scope: []types.RefreshableView{types.COMMITS},
Then: func() error {
Then: func() {
// Find the commit that was last selected in filtering mode, and select it again after refreshing
if !self.c.Contexts().LocalCommits.SelectCommitByHash(selectedCommitHash) {
// If we couldn't find it (either because no commit was selected
@ -178,9 +178,9 @@ func (self *ModeHelper) ClearFiltering() error {
// before we entered filtering
self.c.Contexts().LocalCommits.SelectCommitByHash(self.c.Modes().Filtering.GetSelectedCommitHash())
}
return nil
},
})
return nil
}
func (self *ModeHelper) SetSuppressRebasingMode(value bool) {

View File

@ -40,11 +40,9 @@ func (self *PatchBuildingHelper) Reset() error {
self.Escape()
}
if err := self.c.Refresh(types.RefreshOptions{
self.c.Refresh(types.RefreshOptions{
Scope: []types.RefreshableView{types.COMMIT_FILES},
}); err != nil {
return err
}
})
// refreshing the current context so that the secondary panel is hidden if necessary.
self.c.PostRefreshUpdate(self.c.Context().Current())

View File

@ -51,7 +51,7 @@ func NewRefreshHelper(
}
}
func (self *RefreshHelper) Refresh(options types.RefreshOptions) error {
func (self *RefreshHelper) Refresh(options types.RefreshOptions) {
if options.Mode == types.ASYNC && options.Then != nil {
panic("RefreshOptions.Then doesn't work with mode ASYNC")
}
@ -74,7 +74,7 @@ func (self *RefreshHelper) Refresh(options types.RefreshOptions) error {
)
}
f := func() error {
f := func() {
var scopeSet *set.Set[types.RefreshableView]
if len(options.Scope) == 0 {
// not refreshing staging/patch-building unless explicitly requested because we only need
@ -191,22 +191,19 @@ func (self *RefreshHelper) Refresh(options types.RefreshOptions) error {
wg.Wait()
if options.Then != nil {
if err := options.Then(); err != nil {
return err
}
options.Then()
}
return nil
}
if options.Mode == types.BLOCK_UI {
self.c.OnUIThread(func() error {
return f()
f()
return nil
})
return nil
return
}
return f()
f()
}
func getScopeNames(scopes []types.RefreshableView) []string {

View File

@ -46,7 +46,7 @@ func (self *RefsHelper) CheckoutRef(ref string, options types.CheckoutRefOptions
// loading a heap of commits is slow so we limit them whenever doing a reset
self.c.Contexts().LocalCommits.SetLimitCommits(true)
_ = self.c.Refresh(types.RefreshOptions{Mode: types.BLOCK_UI, KeepBranchSelectionIndex: true})
self.c.Refresh(types.RefreshOptions{Mode: types.BLOCK_UI, KeepBranchSelectionIndex: true})
}
localBranch, found := lo.Find(self.c.Model().Branches, func(branch *models.Branch) bool {
@ -145,12 +145,10 @@ func (self *RefsHelper) CheckoutRemoteBranch(fullBranchName string, localBranchN
}
// Do a sync refresh to make sure the new branch is visible,
// so that we see an inline status when checking it out
if err := self.c.Refresh(types.RefreshOptions{
self.c.Refresh(types.RefreshOptions{
Mode: types.SYNC,
Scope: []types.RefreshableView{types.BRANCHES},
}); err != nil {
return err
}
})
return checkout(localBranchName)
},
},
@ -183,9 +181,7 @@ func (self *RefsHelper) ResetToRef(ref string, strength string, envVars []string
// loading a heap of commits is slow so we limit them whenever doing a reset
self.c.Contexts().LocalCommits.SetLimitCommits(true)
if err := self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.FILES, types.BRANCHES, types.REFLOG, types.COMMITS}}); err != nil {
return err
}
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.FILES, types.BRANCHES, types.REFLOG, types.COMMITS}})
return nil
}
@ -331,7 +327,7 @@ func (self *RefsHelper) NewBranch(from string, fromFormattedName string, suggest
}
}
refresh := func() error {
refresh := func() {
if self.c.Context().Current() != self.c.Contexts().Branches {
self.c.Context().Push(self.c.Contexts().Branches, types.OnFocusOpts{})
}
@ -339,7 +335,7 @@ func (self *RefsHelper) NewBranch(from string, fromFormattedName string, suggest
self.c.Contexts().LocalCommits.SetSelection(0)
self.c.Contexts().Branches.SetSelection(0)
return self.c.Refresh(types.RefreshOptions{Mode: types.BLOCK_UI, KeepBranchSelectionIndex: true})
self.c.Refresh(types.RefreshOptions{Mode: types.BLOCK_UI, KeepBranchSelectionIndex: true})
}
self.c.Prompt(types.PromptOpts{
@ -365,14 +361,10 @@ func (self *RefsHelper) NewBranch(from string, fromFormattedName string, suggest
if err := newBranchFunc(newBranchName, from); err != nil {
return err
}
popErr := self.c.Git().Stash.Pop(0)
err := self.c.Git().Stash.Pop(0)
// Branch switch successful so re-render the UI even if the pop operation failed (e.g. conflict).
refreshError := refresh()
if popErr != nil {
// An error from pop is the more important one to report to the user
return popErr
}
return refreshError
refresh()
return err
},
})
@ -382,7 +374,8 @@ func (self *RefsHelper) NewBranch(from string, fromFormattedName string, suggest
return err
}
return refresh()
refresh()
return nil
},
})
@ -498,7 +491,8 @@ func (self *RefsHelper) moveCommitsToNewBranchStackedOnCurrentBranch(currentBran
self.c.Contexts().LocalCommits.SetSelection(0)
self.c.Contexts().Branches.SetSelection(0)
return self.c.Refresh(types.RefreshOptions{Mode: types.BLOCK_UI, KeepBranchSelectionIndex: true})
self.c.Refresh(types.RefreshOptions{Mode: types.BLOCK_UI, KeepBranchSelectionIndex: true})
return nil
}
func (self *RefsHelper) moveCommitsToNewBranchOffOfMainBranch(currentBranch string, newBranchName string, baseBranchRef string) error {
@ -536,7 +530,8 @@ func (self *RefsHelper) moveCommitsToNewBranchOffOfMainBranch(currentBranch stri
self.c.Contexts().LocalCommits.SetSelection(0)
self.c.Contexts().Branches.SetSelection(0)
return self.c.Refresh(types.RefreshOptions{Mode: types.BLOCK_UI, KeepBranchSelectionIndex: true})
self.c.Refresh(types.RefreshOptions{Mode: types.BLOCK_UI, KeepBranchSelectionIndex: true})
return nil
}
func (self *RefsHelper) CanMoveCommitsToNewBranch() *types.DisabledReason {

View File

@ -210,9 +210,7 @@ func (self *WorkingTreeHelper) promptToStageAllAndRetry(retry func() error) erro
if err := self.c.Git().WorkingTree.StageAll(); err != nil {
return err
}
if err := self.syncRefresh(); err != nil {
return err
}
self.syncRefresh()
return retry()
},
@ -222,8 +220,8 @@ func (self *WorkingTreeHelper) promptToStageAllAndRetry(retry func() error) erro
}
// for when you need to refetch files before continuing an action. Runs synchronously.
func (self *WorkingTreeHelper) syncRefresh() error {
return self.c.Refresh(types.RefreshOptions{Mode: types.SYNC, Scope: []types.RefreshableView{types.FILES}})
func (self *WorkingTreeHelper) syncRefresh() {
self.c.Refresh(types.RefreshOptions{Mode: types.SYNC, Scope: []types.RefreshableView{types.FILES}})
}
func (self *WorkingTreeHelper) prepareFilesForCommit() error {
@ -235,7 +233,7 @@ func (self *WorkingTreeHelper) prepareFilesForCommit() error {
return err
}
return self.syncRefresh()
self.syncRefresh()
}
return nil

View File

@ -198,7 +198,8 @@ func (self *WorktreeHelper) Remove(worktree *models.Worktree, force bool) error
}
return err
}
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.WORKTREES, types.BRANCHES, types.FILES}})
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.WORKTREES, types.BRANCHES, types.FILES}})
return nil
})
},
})
@ -214,7 +215,8 @@ func (self *WorktreeHelper) Detach(worktree *models.Worktree) error {
if err != nil {
return err
}
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.WORKTREES, types.BRANCHES, types.FILES}})
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.WORKTREES, types.BRANCHES, types.FILES}})
return nil
})
}

View File

@ -392,7 +392,8 @@ func (self *LocalCommitsController) switchFromCommitMessagePanelToEditor(filepat
return err
}
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
return nil
}
func (self *LocalCommitsController) handleReword(summary string, description string) error {
@ -408,7 +409,8 @@ func (self *LocalCommitsController) handleReword(summary string, description str
if err != nil {
return err
}
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
return nil
})
}
@ -519,9 +521,8 @@ func (self *LocalCommitsController) edit(selectedCommits []*models.Commit, start
return self.c.Helpers().MergeAndRebase.CheckMergeOrRebaseWithRefreshOptions(
err,
types.RefreshOptions{
Mode: types.BLOCK_UI, Then: func() error {
Mode: types.BLOCK_UI, Then: func() {
self.restoreSelectionRangeAndMode(selectionRangeAndMode)
return nil
},
})
}
@ -547,7 +548,7 @@ func (self *LocalCommitsController) startInteractiveRebaseWithEdit(
err := self.c.Git().Rebase.EditRebase(commitsToEdit[len(commitsToEdit)-1].Hash())
return self.c.Helpers().MergeAndRebase.CheckMergeOrRebaseWithRefreshOptions(
err,
types.RefreshOptions{Mode: types.BLOCK_UI, Then: func() error {
types.RefreshOptions{Mode: types.BLOCK_UI, Then: func() {
todos := make([]*models.Commit, 0, len(commitsToEdit)-1)
for _, c := range commitsToEdit[:len(commitsToEdit)-1] {
// Merge commits can't be set to "edit", so just skip them
@ -558,12 +559,11 @@ func (self *LocalCommitsController) startInteractiveRebaseWithEdit(
if len(todos) > 0 {
err := self.updateTodos(todo.Edit, todos)
if err != nil {
return err
self.c.Log.Errorf("error when updating todos: %v", err)
}
}
self.restoreSelectionRangeAndMode(selectionRangeAndMode)
return nil
}})
})
}
@ -642,9 +642,11 @@ func (self *LocalCommitsController) updateTodos(action todo.TodoCommand, selecte
return err
}
return self.c.Refresh(types.RefreshOptions{
self.c.Refresh(types.RefreshOptions{
Mode: types.SYNC, Scope: []types.RefreshableView{types.REBASE_COMMITS},
})
return nil
}
func (self *LocalCommitsController) rewordEnabled(commit *models.Commit) *types.DisabledReason {
@ -681,9 +683,10 @@ func (self *LocalCommitsController) moveDown(selectedCommits []*models.Commit, s
}
self.context().MoveSelection(1)
return self.c.Refresh(types.RefreshOptions{
self.c.Refresh(types.RefreshOptions{
Mode: types.SYNC, Scope: []types.RefreshableView{types.REBASE_COMMITS},
})
return nil
}
return self.c.WithWaitingStatusSync(self.c.Tr.MovingStatus, func() error {
@ -704,9 +707,10 @@ func (self *LocalCommitsController) moveUp(selectedCommits []*models.Commit, sta
}
self.context().MoveSelection(-1)
return self.c.Refresh(types.RefreshOptions{
self.c.Refresh(types.RefreshOptions{
Mode: types.SYNC, Scope: []types.RefreshableView{types.REBASE_COMMITS},
})
return nil
}
return self.c.WithWaitingStatusSync(self.c.Tr.MovingStatus, func() error {
@ -729,7 +733,8 @@ func (self *LocalCommitsController) amendTo(commit *models.Commit) error {
if err := self.c.Helpers().AmendHelper.AmendHead(); err != nil {
return err
}
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
return nil
})
}
} else {
@ -804,7 +809,8 @@ func (self *LocalCommitsController) resetAuthor(start, end int) error {
return err
}
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
return nil
})
}
@ -819,7 +825,8 @@ func (self *LocalCommitsController) setAuthor(start, end int) error {
return err
}
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
return nil
})
},
})
@ -837,7 +844,8 @@ func (self *LocalCommitsController) addCoAuthor(start, end int) error {
if err := self.c.Git().Rebase.AddCommitCoAuthor(self.c.Model().Commits, start, end, value); err != nil {
return err
}
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
return nil
})
},
})
@ -870,9 +878,10 @@ func (self *LocalCommitsController) revert(commits []*models.Commit, start, end
return err
}
self.context().MoveSelection(len(commits))
return self.c.Refresh(types.RefreshOptions{
self.c.Refresh(types.RefreshOptions{
Mode: types.SYNC, Scope: []types.RefreshableView{types.COMMITS, types.BRANCHES},
})
return nil
})
},
})
@ -908,7 +917,8 @@ func (self *LocalCommitsController) createFixupCommit(commit *models.Commit) err
}
self.context().MoveSelectedLine(1)
return self.c.Refresh(types.RefreshOptions{Mode: types.SYNC})
self.c.Refresh(types.RefreshOptions{Mode: types.SYNC})
return nil
})
})
},
@ -1008,7 +1018,8 @@ func (self *LocalCommitsController) createAmendCommit(commit *models.Commit, inc
}
self.context().MoveSelectedLine(1)
return self.c.Refresh(types.RefreshOptions{Mode: types.SYNC})
self.c.Refresh(types.RefreshOptions{Mode: types.SYNC})
return nil
})
},
OnSwitchToEditor: nil,
@ -1134,9 +1145,7 @@ func (self *LocalCommitsController) openSearch() error {
// we usually lazyload these commits but now that we're searching we need to load them now
if self.context().GetLimitCommits() {
self.context().SetLimitCommits(false)
if err := self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.COMMITS}}); err != nil {
return err
}
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.COMMITS}})
}
return self.c.Helpers().Search.OpenSearchPrompt(self.context())
@ -1156,9 +1165,10 @@ func (self *LocalCommitsController) handleOpenLogMenu() error {
}
return self.c.WithWaitingStatus(self.c.Tr.LoadingCommits, func(gocui.Task) error {
return self.c.Refresh(
self.c.Refresh(
types.RefreshOptions{Mode: types.SYNC, Scope: []types.RefreshableView{types.COMMITS}},
)
return nil
})
},
},
@ -1208,12 +1218,13 @@ func (self *LocalCommitsController) handleOpenLogMenu() error {
self.c.GetAppState().GitLogOrder = value
self.c.SaveAppStateAndLogError()
return self.c.WithWaitingStatus(self.c.Tr.LoadingCommits, func(gocui.Task) error {
return self.c.Refresh(
self.c.Refresh(
types.RefreshOptions{
Mode: types.SYNC,
Scope: []types.RefreshableView{types.COMMITS},
},
)
return nil
})
}
}
@ -1255,7 +1266,8 @@ func (self *LocalCommitsController) GetOnFocus() func(types.OnFocusOpts) {
if context.GetSelectedLineIdx() > COMMIT_THRESHOLD && context.GetLimitCommits() {
context.SetLimitCommits(false)
self.c.OnWorker(func(_ gocui.Task) error {
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.COMMITS}})
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.COMMITS}})
return nil
})
}
}

View File

@ -277,7 +277,7 @@ func (self *MergeConflictsController) pickSelection(selection mergeconflicts.Sel
}
if self.context().GetState().AllConflictsResolved() {
return self.onLastConflictResolved()
self.onLastConflictResolved()
}
return nil
@ -314,10 +314,10 @@ func (self *MergeConflictsController) resolveConflict(selection mergeconflicts.S
return true, os.WriteFile(state.GetPath(), []byte(content), 0o644)
}
func (self *MergeConflictsController) onLastConflictResolved() error {
func (self *MergeConflictsController) onLastConflictResolved() {
// as part of refreshing files, we handle the situation where a file has had
// its merge conflicts resolved.
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}})
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}})
}
func (self *MergeConflictsController) withRenderAndFocus(f func() error) func() error {

View File

@ -116,9 +116,10 @@ func (self *PatchBuildingController) ToggleSelectionAndRefresh() error {
return err
}
return self.c.Refresh(types.RefreshOptions{
self.c.Refresh(types.RefreshOptions{
Scope: []types.RefreshableView{types.PATCH_BUILDING, types.COMMIT_FILES},
})
return nil
}
func (self *PatchBuildingController) toggleSelection() error {

View File

@ -150,7 +150,7 @@ func (self *RemoteBranchesController) createSortMenu() error {
self.c.GetAppState().RemoteBranchSortOrder = sortOrder
self.c.SaveAppStateAndLogError()
self.c.Contexts().RemoteBranches.SetSelection(0)
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.REMOTES}})
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.REMOTES}})
}
return nil
},
@ -181,7 +181,8 @@ func (self *RemoteBranchesController) setAsUpstream(selectedBranch *models.Remot
return err
}
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.BRANCHES, types.REMOTES}})
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.BRANCHES, types.REMOTES}})
return nil
},
})

View File

@ -148,12 +148,10 @@ func (self *RemotesController) add() error {
// Do a sync refresh of the remotes so that we can select
// the new one. Loading remotes is not expensive, so we can
// afford it.
if err := self.c.Refresh(types.RefreshOptions{
self.c.Refresh(types.RefreshOptions{
Scope: []types.RefreshableView{types.REMOTES},
Mode: types.SYNC,
}); err != nil {
return err
}
})
// Select the new remote
for idx, remote := range self.c.Model().Remotes {
@ -185,7 +183,8 @@ func (self *RemotesController) remove(remote *models.Remote) error {
return err
}
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.BRANCHES, types.REMOTES}})
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.BRANCHES, types.REMOTES}})
return nil
},
})
@ -232,7 +231,8 @@ func (self *RemotesController) edit(remote *models.Remote) error {
if err := self.c.Git().Remote.UpdateRemoteUrl(updatedRemoteName, updatedRemoteUrl); err != nil {
return err
}
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.BRANCHES, types.REMOTES}})
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.BRANCHES, types.REMOTES}})
return nil
},
})
@ -250,9 +250,10 @@ func (self *RemotesController) fetch(remote *models.Remote) error {
return err
}
return self.c.Refresh(types.RefreshOptions{
self.c.Refresh(types.RefreshOptions{
Scope: []types.RefreshableView{types.BRANCHES, types.REMOTES},
Mode: types.ASYNC,
})
return nil
})
}

View File

@ -88,11 +88,11 @@ func (self *RenameSimilarityThresholdController) applyChange() error {
switch currentContext.GetKey() {
// we make an exception for our files context, because it actually need to refresh its state afterwards.
case context.FILES_CONTEXT_KEY:
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.FILES}})
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.FILES}})
default:
currentContext.HandleRenderToMain()
return nil
}
return nil
}
func (self *RenameSimilarityThresholdController) isShowingRenames() bool {

View File

@ -221,7 +221,8 @@ func (self *StagingController) applySelectionAndRefresh(reverse bool) error {
return err
}
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.FILES, types.STAGING}})
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.FILES, types.STAGING}})
return nil
}
func (self *StagingController) applySelection(reverse bool) error {
@ -275,7 +276,8 @@ func (self *StagingController) EditHunkAndRefresh() error {
return err
}
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.FILES, types.STAGING}})
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.FILES, types.STAGING}})
return nil
}
func (self *StagingController) editHunk() error {

View File

@ -107,7 +107,7 @@ func (self *StashController) handleStashApply(stashEntry *models.StashEntry) err
apply := func() error {
self.c.LogAction(self.c.Tr.Actions.Stash)
err := self.c.Git().Stash.Apply(stashEntry.Index)
_ = self.postStashRefresh()
self.postStashRefresh()
if err != nil {
return err
}
@ -136,7 +136,7 @@ func (self *StashController) handleStashPop(stashEntry *models.StashEntry) error
pop := func() error {
self.c.LogAction(self.c.Tr.Actions.Stash)
err := self.c.Git().Stash.Pop(stashEntry.Index)
_ = self.postStashRefresh()
self.postStashRefresh()
if err != nil {
return err
}
@ -170,7 +170,7 @@ func (self *StashController) handleStashDrop(stashEntries []*models.StashEntry)
startIndex := stashEntries[0].Index
for range stashEntries {
err := self.c.Git().Stash.Drop(startIndex)
_ = self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.STASH}})
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.STASH}})
if err != nil {
return err
}
@ -182,8 +182,8 @@ func (self *StashController) handleStashDrop(stashEntries []*models.StashEntry)
return nil
}
func (self *StashController) postStashRefresh() error {
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.STASH, types.FILES}})
func (self *StashController) postStashRefresh() {
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.STASH, types.FILES}})
}
func (self *StashController) handleNewBranchOffStashEntry(stashEntry *models.StashEntry) error {
@ -205,12 +205,13 @@ func (self *StashController) handleRenameStashEntry(stashEntry *models.StashEntr
self.c.LogAction(self.c.Tr.Actions.RenameStash)
err := self.c.Git().Stash.Rename(stashEntry.Index, response)
if err != nil {
_ = self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.STASH}})
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.STASH}})
return err
}
self.context().SetSelection(0) // Select the renamed stash
self.context().FocusLine()
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.STASH}})
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.STASH}})
return nil
},
})

View File

@ -68,7 +68,8 @@ func (self *SubCommitsController) GetOnFocus() func(types.OnFocusOpts) {
if context.GetSelectedLineIdx() > COMMIT_THRESHOLD && context.GetLimitCommits() {
context.SetLimitCommits(false)
self.c.OnWorker(func(_ gocui.Task) error {
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.SUB_COMMITS}})
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.SUB_COMMITS}})
return nil
})
}
}

View File

@ -166,7 +166,8 @@ func (self *SubmodulesController) add() error {
return err
}
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.SUBMODULES}})
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.SUBMODULES}})
return nil
})
},
})
@ -194,7 +195,8 @@ func (self *SubmodulesController) editURL(submodule *models.SubmoduleConfig) err
return err
}
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.SUBMODULES}})
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.SUBMODULES}})
return nil
})
},
})
@ -210,7 +212,8 @@ func (self *SubmodulesController) init(submodule *models.SubmoduleConfig) error
return err
}
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.SUBMODULES}})
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.SUBMODULES}})
return nil
})
}
@ -228,7 +231,8 @@ func (self *SubmodulesController) openBulkActionsMenu() error {
return err
}
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.SUBMODULES}})
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.SUBMODULES}})
return nil
})
},
Key: 'i',
@ -242,7 +246,8 @@ func (self *SubmodulesController) openBulkActionsMenu() error {
return err
}
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.SUBMODULES}})
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.SUBMODULES}})
return nil
})
},
Key: 'u',
@ -256,7 +261,8 @@ func (self *SubmodulesController) openBulkActionsMenu() error {
return err
}
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.SUBMODULES}})
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.SUBMODULES}})
return nil
})
},
Key: 'r',
@ -270,7 +276,8 @@ func (self *SubmodulesController) openBulkActionsMenu() error {
return err
}
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.SUBMODULES}})
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.SUBMODULES}})
return nil
})
},
Key: 'd',
@ -287,7 +294,8 @@ func (self *SubmodulesController) update(submodule *models.SubmoduleConfig) erro
return err
}
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.SUBMODULES}})
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.SUBMODULES}})
return nil
})
}
@ -301,7 +309,8 @@ func (self *SubmodulesController) remove(submodule *models.SubmoduleConfig) erro
return err
}
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.SUBMODULES, types.FILES}})
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.SUBMODULES, types.FILES}})
return nil
},
})

View File

@ -85,11 +85,9 @@ func (self *SwitchToDiffFilesController) enter() error {
commitFilesContext.ClearSearchString()
commitFilesContext.GetView().TitlePrefix = self.context.GetView().TitlePrefix
if err := self.c.Refresh(types.RefreshOptions{
self.c.Refresh(types.RefreshOptions{
Scope: []types.RefreshableView{types.COMMIT_FILES},
}); err != nil {
return err
}
})
self.c.Context().Push(commitFilesContext, types.OnFocusOpts{})
return nil

View File

@ -229,7 +229,8 @@ func (self *SyncController) pushAux(currentBranch *models.Branch, opts pushOpts)
}
return err
}
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
return nil
})
}

View File

@ -158,7 +158,7 @@ func (self *TagsController) localDelete(tag *models.Tag) error {
return self.c.WithWaitingStatus(self.c.Tr.DeletingStatus, func(gocui.Task) error {
self.c.LogAction(self.c.Tr.Actions.DeleteLocalTag)
err := self.c.Git().Tag.LocalDelete(tag.Name)
_ = self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.COMMITS, types.TAGS}})
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.COMMITS, types.TAGS}})
return err
})
}
@ -200,7 +200,8 @@ func (self *TagsController) remoteDelete(tag *models.Tag) error {
return err
}
self.c.Toast(self.c.Tr.RemoteTagDeletedMessage)
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.COMMITS, types.TAGS}})
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.COMMITS, types.TAGS}})
return nil
})
},
})
@ -253,7 +254,8 @@ func (self *TagsController) localAndRemoteDelete(tag *models.Tag) error {
if err := self.c.Git().Tag.LocalDelete(tag.Name); err != nil {
return err
}
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.COMMITS, types.TAGS}})
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.COMMITS, types.TAGS}})
return nil
})
},
})

View File

@ -271,7 +271,8 @@ func (self *UndoController) hardResetWithAutoStash(commitHash string, options ha
if err != nil {
return err
}
return self.c.Refresh(types.RefreshOptions{})
self.c.Refresh(types.RefreshOptions{})
return nil
})
}

View File

@ -39,9 +39,10 @@ func (self *FilesController) createResetMenu() error {
self.animateExplosion()
}
return self.c.Refresh(
self.c.Refresh(
types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}},
)
return nil
},
Key: 'x',
Tooltip: self.c.Tr.NukeDescription,
@ -57,9 +58,10 @@ func (self *FilesController) createResetMenu() error {
return err
}
return self.c.Refresh(
self.c.Refresh(
types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}},
)
return nil
},
Key: 'u',
},
@ -74,9 +76,10 @@ func (self *FilesController) createResetMenu() error {
return err
}
return self.c.Refresh(
self.c.Refresh(
types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}},
)
return nil
},
Key: 'c',
},
@ -98,9 +101,10 @@ func (self *FilesController) createResetMenu() error {
return err
}
return self.c.Refresh(
self.c.Refresh(
types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}},
)
return nil
},
Key: 'S',
},
@ -115,9 +119,10 @@ func (self *FilesController) createResetMenu() error {
return err
}
return self.c.Refresh(
self.c.Refresh(
types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}},
)
return nil
},
Key: 's',
},
@ -132,9 +137,10 @@ func (self *FilesController) createResetMenu() error {
return err
}
return self.c.Refresh(
self.c.Refresh(
types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}},
)
return nil
},
Key: 'm',
},
@ -149,9 +155,10 @@ func (self *FilesController) createResetMenu() error {
return err
}
return self.c.Refresh(
self.c.Refresh(
types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}},
)
return nil
},
Key: 'h',
},

View File

@ -349,13 +349,8 @@ func (gui *Gui) onNewRepo(startArgs appTypes.StartArgs, contextKey types.Context
}
gui.c.Log.Info("Receiving focus - refreshing")
refreshErr := gui.helpers.Refresh.Refresh(types.RefreshOptions{Mode: types.ASYNC})
if reloadErr != nil {
// An error from reloading the config is the more important one
// to report to the user
return reloadErr
}
return refreshErr
gui.helpers.Refresh.Refresh(types.RefreshOptions{Mode: types.ASYNC})
return reloadErr
}
return nil
@ -693,7 +688,7 @@ func NewGui(
func(ctx goContext.Context, opts types.CreatePopupPanelOpts) {
gui.helpers.Confirmation.CreatePopupPanel(ctx, opts)
},
func() error { return gui.c.Refresh(types.RefreshOptions{Mode: types.ASYNC}) },
func() error { gui.c.Refresh(types.RefreshOptions{Mode: types.ASYNC}); return nil },
func() { gui.State.ContextMgr.Pop() },
func() types.Context { return gui.State.ContextMgr.Current() },
gui.createMenu,
@ -932,9 +927,7 @@ func (gui *Gui) runSubprocessWithSuspenseAndRefresh(subprocess *oscommands.CmdOb
return err
}
if err := gui.c.Refresh(types.RefreshOptions{Mode: types.ASYNC}); err != nil {
return err
}
gui.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
return nil
}
@ -996,9 +989,7 @@ func (gui *Gui) loadNewRepo() error {
return err
}
if err := gui.c.Refresh(types.RefreshOptions{Mode: types.ASYNC}); err != nil {
return err
}
gui.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
if err := gui.os.UpdateWindowTitle(); err != nil {
return err

View File

@ -26,8 +26,8 @@ func (self *guiCommon) LogCommand(cmdStr string, isCommandLine bool) {
self.gui.LogCommand(cmdStr, isCommandLine)
}
func (self *guiCommon) Refresh(opts types.RefreshOptions) error {
return self.gui.helpers.Refresh.Refresh(opts)
func (self *guiCommon) Refresh(opts types.RefreshOptions) {
self.gui.helpers.Refresh.Refresh(opts)
}
func (self *guiCommon) PostRefreshUpdate(context types.Context) {

View File

@ -282,9 +282,7 @@ func (self *HandlerCreator) finalHandler(customCommand config.CustomCommand, ses
}
output, err := cmdObj.RunWithOutput()
if refreshErr := self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC}); err != nil {
self.c.Log.Error(refreshErr)
}
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
if err != nil {
if customCommand.After != nil && customCommand.After.CheckForConflicts {

View File

@ -29,7 +29,7 @@ type IGuiCommon interface {
LogAction(action string)
LogCommand(cmdStr string, isCommandLine bool)
// we call this when we want to refetch some models and render the result. Internally calls PostRefreshUpdate
Refresh(RefreshOptions) error
Refresh(RefreshOptions)
// we call this when we've changed something in the view model but not the actual model,
// e.g. expanding or collapsing a folder in a file view. Calling 'Refresh' in this
// case would be overkill, although refresh will internally call 'PostRefreshUpdate'

View File

@ -33,7 +33,7 @@ const (
)
type RefreshOptions struct {
Then func() error
Then func()
Scope []RefreshableView // e.g. []RefreshableView{COMMITS, BRANCHES}. Leave empty to refresh everything
Mode RefreshMode // one of SYNC (default), ASYNC, and BLOCK_UI