Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow pasting commits multiple times #3983

Merged
merged 3 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions pkg/gui/controllers/commits_files_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ func (self *CommitFilesController) toggleForPatch(selectedNodes []*filetree.Comm
self.c.Git().Patch.PatchBuilder.Reset()
}

return self.c.PostRefreshUpdate(self.context())
self.c.PostRefreshUpdate(self.context())
return nil
})
}

Expand Down Expand Up @@ -387,9 +388,7 @@ func (self *CommitFilesController) enterCommitFile(node *filetree.CommitFileNode
func (self *CommitFilesController) handleToggleCommitFileDirCollapsed(node *filetree.CommitFileNode) error {
self.context().CommitFileTreeViewModel.ToggleCollapsed(node.GetPath())

if err := self.c.PostRefreshUpdate(self.context()); err != nil {
self.c.Log.Error(err)
}
self.c.PostRefreshUpdate(self.context())

return nil
}
Expand All @@ -398,7 +397,8 @@ func (self *CommitFilesController) handleToggleCommitFileDirCollapsed(node *file
func (self *CommitFilesController) toggleTreeView() error {
self.context().CommitFileTreeViewModel.ToggleShowTree()

return self.c.PostRefreshUpdate(self.context())
self.c.PostRefreshUpdate(self.context())
return nil
}

// NOTE: these functions are identical to those in files_controller.go (except for types) and
Expand Down
14 changes: 6 additions & 8 deletions pkg/gui/controllers/files_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,7 @@ func (self *FilesController) optimisticChange(nodes []*filetree.FileNode, optimi
}

if rerender {
if err := self.c.PostRefreshUpdate(self.c.Contexts().Files); err != nil {
return err
}
self.c.PostRefreshUpdate(self.c.Contexts().Files)
}

return nil
Expand Down Expand Up @@ -710,7 +708,8 @@ func (self *FilesController) handleStatusFilterPressed() error {

func (self *FilesController) setStatusFiltering(filter filetree.FileTreeDisplayFilter) error {
self.context().FileTreeViewModel.SetStatusFilter(filter)
return self.c.PostRefreshUpdate(self.context())
self.c.PostRefreshUpdate(self.context())
return nil
}

func (self *FilesController) edit(nodes []*filetree.FileNode) error {
Expand Down Expand Up @@ -949,17 +948,16 @@ func (self *FilesController) handleToggleDirCollapsed() error {

self.context().FileTreeViewModel.ToggleCollapsed(node.GetPath())

if err := self.c.PostRefreshUpdate(self.c.Contexts().Files); err != nil {
self.c.Log.Error(err)
}
self.c.PostRefreshUpdate(self.c.Contexts().Files)

return nil
}

func (self *FilesController) toggleTreeView() error {
self.context().FileTreeViewModel.ToggleShowTree()

return self.c.PostRefreshUpdate(self.context())
self.c.PostRefreshUpdate(self.context())
return nil
}

func (self *FilesController) handleStashSave(stashFunc func(message string) error, action string) error {
Expand Down
21 changes: 11 additions & 10 deletions pkg/gui/controllers/helpers/cherry_pick_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ func (self *CherryPickHelper) CopyRange(commitsList []*models.Commit, context ty
}
}

return self.rerender()
self.getData().DidPaste = false

self.rerender()
return nil
}

// HandlePasteCommits begins a cherry-pick rebase with the commits the user has copied.
Expand Down Expand Up @@ -102,7 +105,8 @@ func (self *CherryPickHelper) Paste() error {
return err
}
if !isInRebase {
return self.Reset()
self.getData().DidPaste = true
self.rerender()
}
return nil
})
Expand All @@ -113,14 +117,15 @@ func (self *CherryPickHelper) Paste() error {
}

func (self *CherryPickHelper) CanPaste() bool {
return self.getData().Active()
return self.getData().CanPaste()
}

func (self *CherryPickHelper) Reset() error {
self.getData().ContextKey = ""
self.getData().CherryPickedCommits = nil

return self.rerender()
self.rerender()
return nil
}

// you can only copy from one context at a time, because the order and position of commits matter
Expand All @@ -136,16 +141,12 @@ func (self *CherryPickHelper) resetIfNecessary(context types.Context) error {
return nil
}

func (self *CherryPickHelper) rerender() error {
func (self *CherryPickHelper) rerender() {
for _, context := range []types.Context{
self.c.Contexts().LocalCommits,
self.c.Contexts().ReflogCommits,
self.c.Contexts().SubCommits,
} {
if err := self.c.PostRefreshUpdate(context); err != nil {
return err
}
self.c.PostRefreshUpdate(context)
}

return nil
}
3 changes: 2 additions & 1 deletion pkg/gui/controllers/helpers/merge_and_rebase_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,5 +487,6 @@ func (self *MergeAndRebaseHelper) SquashMergeCommitted(refName, checkedOutBranch

func (self *MergeAndRebaseHelper) ResetMarkedBaseCommit() error {
self.c.Modes().MarkedBaseCommit.Reset()
return self.c.PostRefreshUpdate(self.c.Contexts().LocalCommits)
self.c.PostRefreshUpdate(self.c.Contexts().LocalCommits)
return nil
}
3 changes: 2 additions & 1 deletion pkg/gui/controllers/helpers/patch_building_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ func (self *PatchBuildingHelper) Reset() error {
}

// refreshing the current context so that the secondary panel is hidden if necessary.
return self.c.PostRefreshUpdate(self.c.Context().Current())
self.c.PostRefreshUpdate(self.c.Context().Current())
return nil
}

func (self *PatchBuildingHelper) RefreshPatchBuildingPanel(opts types.OnFocusOpts) {
Expand Down
69 changes: 27 additions & 42 deletions pkg/gui/controllers/helpers/refresh_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (self *RefreshHelper) Refresh(options types.RefreshOptions) error {
}

if scopeSet.Includes(types.STASH) {
refresh("stash", func() { _ = self.refreshStashEntries() })
refresh("stash", func() { self.refreshStashEntries() })
}

if scopeSet.Includes(types.TAGS) {
Expand All @@ -169,7 +169,7 @@ func (self *RefreshHelper) Refresh(options types.RefreshOptions) error {
}

if scopeSet.Includes(types.WORKTREES) && !includeWorktreesWithBranches {
refresh("worktrees", func() { _ = self.refreshWorktrees() })
refresh("worktrees", func() { self.refreshWorktrees() })
}

if scopeSet.Includes(types.STAGING) {
Expand Down Expand Up @@ -343,7 +343,8 @@ func (self *RefreshHelper) refreshCommitsWithLimit() error {
self.c.Model().WorkingTreeStateAtLastCommitRefresh = self.c.Git().Status.WorkingTreeState()
self.c.Model().CheckedOutBranch = checkedOutBranchName

return self.refreshView(self.c.Contexts().LocalCommits)
self.refreshView(self.c.Contexts().LocalCommits)
return nil
}

func (self *RefreshHelper) refreshSubCommitsWithLimit() error {
Expand All @@ -368,7 +369,8 @@ func (self *RefreshHelper) refreshSubCommitsWithLimit() error {
self.c.Model().SubCommits = commits
self.RefreshAuthors(commits)

return self.refreshView(self.c.Contexts().SubCommits)
self.refreshView(self.c.Contexts().SubCommits)
return nil
}

func (self *RefreshHelper) RefreshAuthors(commits []*models.Commit) {
Expand Down Expand Up @@ -397,7 +399,8 @@ func (self *RefreshHelper) refreshCommitFilesContext() error {
self.c.Model().CommitFiles = files
self.c.Contexts().CommitFiles.CommitFileTreeViewModel.SetTree()

return self.refreshView(self.c.Contexts().CommitFiles)
self.refreshView(self.c.Contexts().CommitFiles)
return nil
}

func (self *RefreshHelper) refreshRebaseCommits() error {
Expand All @@ -411,7 +414,8 @@ func (self *RefreshHelper) refreshRebaseCommits() error {
self.c.Model().Commits = updatedCommits
self.c.Model().WorkingTreeStateAtLastCommitRefresh = self.c.Git().Status.WorkingTreeState()

return self.refreshView(self.c.Contexts().LocalCommits)
self.refreshView(self.c.Contexts().LocalCommits)
return nil
}

func (self *RefreshHelper) refreshTags() error {
Expand All @@ -422,7 +426,8 @@ func (self *RefreshHelper) refreshTags() error {

self.c.Model().Tags = tags

return self.refreshView(self.c.Contexts().Tags)
self.refreshView(self.c.Contexts().Tags)
return nil
}

func (self *RefreshHelper) refreshStateSubmoduleConfigs() error {
Expand Down Expand Up @@ -482,9 +487,7 @@ func (self *RefreshHelper) refreshBranches(refreshWorktrees bool, keepBranchSele

if refreshWorktrees {
self.loadWorktrees()
if err := self.refreshView(self.c.Contexts().Worktrees); err != nil {
self.c.Log.Error(err)
}
self.refreshView(self.c.Contexts().Worktrees)
}

if !keepBranchSelectionIndex && prevSelectedBranch != nil {
Expand All @@ -495,9 +498,7 @@ func (self *RefreshHelper) refreshBranches(refreshWorktrees bool, keepBranchSele
}
}

if err := self.refreshView(self.c.Contexts().Branches); err != nil {
self.c.Log.Error(err)
}
self.refreshView(self.c.Contexts().Branches)

// Need to re-render the commits view because the visualization of local
// branch heads might have changed
Expand Down Expand Up @@ -525,14 +526,8 @@ func (self *RefreshHelper) refreshFilesAndSubmodules() error {
}

self.c.OnUIThread(func() error {
if err := self.refreshView(self.c.Contexts().Submodules); err != nil {
self.c.Log.Error(err)
}

if err := self.refreshView(self.c.Contexts().Files); err != nil {
self.c.Log.Error(err)
}

self.refreshView(self.c.Contexts().Submodules)
self.refreshView(self.c.Contexts().Files)
return nil
})

Expand Down Expand Up @@ -653,7 +648,8 @@ func (self *RefreshHelper) refreshReflogCommits() error {
model.FilteredReflogCommits = model.ReflogCommits
}

return self.refreshView(self.c.Contexts().ReflogCommits)
self.refreshView(self.c.Contexts().ReflogCommits)
return nil
}

func (self *RefreshHelper) refreshRemotes() error {
Expand All @@ -677,14 +673,8 @@ func (self *RefreshHelper) refreshRemotes() error {
}
}

if err := self.refreshView(self.c.Contexts().Remotes); err != nil {
return err
}

if err := self.refreshView(self.c.Contexts().RemoteBranches); err != nil {
return err
}

self.refreshView(self.c.Contexts().Remotes)
self.refreshView(self.c.Contexts().RemoteBranches)
return nil
}

Expand All @@ -698,23 +688,20 @@ func (self *RefreshHelper) loadWorktrees() {
self.c.Model().Worktrees = worktrees
}

func (self *RefreshHelper) refreshWorktrees() error {
func (self *RefreshHelper) refreshWorktrees() {
self.loadWorktrees()

// need to refresh branches because the branches view shows worktrees against
// branches
if err := self.refreshView(self.c.Contexts().Branches); err != nil {
return err
}

return self.refreshView(self.c.Contexts().Worktrees)
self.refreshView(self.c.Contexts().Branches)
self.refreshView(self.c.Contexts().Worktrees)
}

func (self *RefreshHelper) refreshStashEntries() error {
func (self *RefreshHelper) refreshStashEntries() {
self.c.Model().StashEntries = self.c.Git().Loaders.StashLoader.
GetStashEntries(self.c.Modes().Filtering.GetPath())

return self.refreshView(self.c.Contexts().Stash)
self.refreshView(self.c.Contexts().Stash)
}

// never call this on its own, it should only be called from within refreshCommits()
Expand Down Expand Up @@ -754,12 +741,12 @@ func (self *RefreshHelper) refForLog() string {
return bisectInfo.GetStartHash()
}

func (self *RefreshHelper) refreshView(context types.Context) error {
func (self *RefreshHelper) refreshView(context types.Context) {
// Re-applying the filter must be done before re-rendering the view, so that
// the filtered list model is up to date for rendering.
self.searchHelper.ReApplyFilter(context)

err := self.c.PostRefreshUpdate(context)
self.c.PostRefreshUpdate(context)

self.c.AfterLayout(func() error {
// Re-applying the search must be done after re-rendering the view though,
Expand All @@ -773,6 +760,4 @@ func (self *RefreshHelper) refreshView(context types.Context) error {
self.searchHelper.ReApplySearch(context)
return nil
})

return err
}
4 changes: 2 additions & 2 deletions pkg/gui/controllers/helpers/search_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func (self *SearchHelper) Cancel() {
switch context := state.Context.(type) {
case types.IFilterableContext:
context.ClearFilter()
_ = self.c.PostRefreshUpdate(context)
self.c.PostRefreshUpdate(context)
case types.ISearchableContext:
context.ClearSearchString()
context.GetView().ClearSearch()
Expand All @@ -231,7 +231,7 @@ func (self *SearchHelper) OnPromptContentChanged(searchString string) {
context.SetSelection(0)
context.GetView().SetOriginY(0)
context.SetFilter(searchString, self.c.UserConfig().Gui.UseFuzzySearch())
_ = self.c.PostRefreshUpdate(context)
self.c.PostRefreshUpdate(context)
case types.ISearchableContext:
// do nothing
default:
Expand Down
5 changes: 1 addition & 4 deletions pkg/gui/controllers/helpers/sub_commits_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ func (self *SubCommitsHelper) ViewSubCommits(opts ViewSubCommitsOpts) error {
subCommitsContext.GetView().ClearSearch()
subCommitsContext.GetView().TitlePrefix = opts.Context.GetView().TitlePrefix

err = self.c.PostRefreshUpdate(self.c.Contexts().SubCommits)
if err != nil {
return err
}
self.c.PostRefreshUpdate(self.c.Contexts().SubCommits)

self.c.Context().Push(self.c.Contexts().SubCommits)
return nil
Expand Down
10 changes: 5 additions & 5 deletions pkg/gui/controllers/local_commits_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1177,10 +1177,9 @@ func (self *LocalCommitsController) handleOpenLogMenu() error {
return func() error {
self.c.GetAppState().GitLogShowGraph = value
self.c.SaveAppStateAndLogError()
if err := self.c.PostRefreshUpdate(self.c.Contexts().LocalCommits); err != nil {
return err
}
return self.c.PostRefreshUpdate(self.c.Contexts().SubCommits)
self.c.PostRefreshUpdate(self.c.Contexts().LocalCommits)
self.c.PostRefreshUpdate(self.c.Contexts().SubCommits)
return nil
}
}
return self.c.Menu(types.CreateMenuOptions{
Expand Down Expand Up @@ -1286,7 +1285,8 @@ func (self *LocalCommitsController) markAsBaseCommit(commit *models.Commit) erro
} else {
self.c.Modes().MarkedBaseCommit.SetHash(commit.Hash)
}
return self.c.PostRefreshUpdate(self.c.Contexts().LocalCommits)
self.c.PostRefreshUpdate(self.c.Contexts().LocalCommits)
return nil
}

func (self *LocalCommitsController) isHeadCommit(idx int) bool {
Expand Down
3 changes: 2 additions & 1 deletion pkg/gui/controllers/patch_building_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ func (self *PatchBuildingController) Escape() error {

if state.SelectingRange() || state.SelectingHunk() {
state.SetLineSelectMode()
return self.c.PostRefreshUpdate(context)
self.c.PostRefreshUpdate(context)
return nil
}

self.c.Helpers().PatchBuilding.Escape()
Expand Down
Loading
Loading