Skip to content

Commit 052974b

Browse files
authored
Allow pasting commits multiple times (jesseduffield#3983)
- **PR Description** After pasting commits, hide the cherry-pick status (i.e. remove the "x commits copied" status in the lower right corner, and hide the blue selection of the copied commits). However, keep the copied commits around so that it's possible to paste them again. This can be useful e.g. to backport a bugfix to multiple major version release branches. Discussed in jesseduffield#3198. - **Please check if the PR fulfills these requirements** * [x] Cheatsheets are up-to-date (run `go generate ./...`) * [x] Code has been formatted (see [here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#code-formatting)) * [x] Tests have been added/updated (see [here](https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md) for the integration test guide) * [ ] Text is internationalised (see [here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#internationalisation)) * [ ] If a new UserConfig entry was added, make sure it can be hot-reloaded (see [here](https://github.com/jesseduffield/lazygit/blob/master/docs/dev/Codebase_Guide.md#using-userconfig)) * [ ] Docs have been updated if necessary * [x] You've read through your own file changes for silly mistakes etc
2 parents 53f8249 + 8552340 commit 052974b

20 files changed

+115
-96
lines changed

pkg/gui/controllers/commits_files_controller.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ func (self *CommitFilesController) toggleForPatch(selectedNodes []*filetree.Comm
303303
self.c.Git().Patch.PatchBuilder.Reset()
304304
}
305305

306-
return self.c.PostRefreshUpdate(self.context())
306+
self.c.PostRefreshUpdate(self.context())
307+
return nil
307308
})
308309
}
309310

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

390-
if err := self.c.PostRefreshUpdate(self.context()); err != nil {
391-
self.c.Log.Error(err)
392-
}
391+
self.c.PostRefreshUpdate(self.context())
393392

394393
return nil
395394
}
@@ -398,7 +397,8 @@ func (self *CommitFilesController) handleToggleCommitFileDirCollapsed(node *file
398397
func (self *CommitFilesController) toggleTreeView() error {
399398
self.context().CommitFileTreeViewModel.ToggleShowTree()
400399

401-
return self.c.PostRefreshUpdate(self.context())
400+
self.c.PostRefreshUpdate(self.context())
401+
return nil
402402
}
403403

404404
// NOTE: these functions are identical to those in files_controller.go (except for types) and

pkg/gui/controllers/files_controller.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,7 @@ func (self *FilesController) optimisticChange(nodes []*filetree.FileNode, optimi
373373
}
374374

375375
if rerender {
376-
if err := self.c.PostRefreshUpdate(self.c.Contexts().Files); err != nil {
377-
return err
378-
}
376+
self.c.PostRefreshUpdate(self.c.Contexts().Files)
379377
}
380378

381379
return nil
@@ -710,7 +708,8 @@ func (self *FilesController) handleStatusFilterPressed() error {
710708

711709
func (self *FilesController) setStatusFiltering(filter filetree.FileTreeDisplayFilter) error {
712710
self.context().FileTreeViewModel.SetStatusFilter(filter)
713-
return self.c.PostRefreshUpdate(self.context())
711+
self.c.PostRefreshUpdate(self.context())
712+
return nil
714713
}
715714

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

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

952-
if err := self.c.PostRefreshUpdate(self.c.Contexts().Files); err != nil {
953-
self.c.Log.Error(err)
954-
}
951+
self.c.PostRefreshUpdate(self.c.Contexts().Files)
955952

956953
return nil
957954
}
958955

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

962-
return self.c.PostRefreshUpdate(self.context())
959+
self.c.PostRefreshUpdate(self.context())
960+
return nil
963961
}
964962

965963
func (self *FilesController) handleStashSave(stashFunc func(message string) error, action string) error {

pkg/gui/controllers/helpers/cherry_pick_helper.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ func (self *CherryPickHelper) CopyRange(commitsList []*models.Commit, context ty
5757
}
5858
}
5959

60-
return self.rerender()
60+
self.getData().DidPaste = false
61+
62+
self.rerender()
63+
return nil
6164
}
6265

6366
// HandlePasteCommits begins a cherry-pick rebase with the commits the user has copied.
@@ -102,7 +105,8 @@ func (self *CherryPickHelper) Paste() error {
102105
return err
103106
}
104107
if !isInRebase {
105-
return self.Reset()
108+
self.getData().DidPaste = true
109+
self.rerender()
106110
}
107111
return nil
108112
})
@@ -113,14 +117,15 @@ func (self *CherryPickHelper) Paste() error {
113117
}
114118

115119
func (self *CherryPickHelper) CanPaste() bool {
116-
return self.getData().Active()
120+
return self.getData().CanPaste()
117121
}
118122

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

123-
return self.rerender()
127+
self.rerender()
128+
return nil
124129
}
125130

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

139-
func (self *CherryPickHelper) rerender() error {
144+
func (self *CherryPickHelper) rerender() {
140145
for _, context := range []types.Context{
141146
self.c.Contexts().LocalCommits,
142147
self.c.Contexts().ReflogCommits,
143148
self.c.Contexts().SubCommits,
144149
} {
145-
if err := self.c.PostRefreshUpdate(context); err != nil {
146-
return err
147-
}
150+
self.c.PostRefreshUpdate(context)
148151
}
149-
150-
return nil
151152
}

pkg/gui/controllers/helpers/merge_and_rebase_helper.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,5 +487,6 @@ func (self *MergeAndRebaseHelper) SquashMergeCommitted(refName, checkedOutBranch
487487

488488
func (self *MergeAndRebaseHelper) ResetMarkedBaseCommit() error {
489489
self.c.Modes().MarkedBaseCommit.Reset()
490-
return self.c.PostRefreshUpdate(self.c.Contexts().LocalCommits)
490+
self.c.PostRefreshUpdate(self.c.Contexts().LocalCommits)
491+
return nil
491492
}

pkg/gui/controllers/helpers/patch_building_helper.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ func (self *PatchBuildingHelper) Reset() error {
5252
}
5353

5454
// refreshing the current context so that the secondary panel is hidden if necessary.
55-
return self.c.PostRefreshUpdate(self.c.Context().Current())
55+
self.c.PostRefreshUpdate(self.c.Context().Current())
56+
return nil
5657
}
5758

5859
func (self *PatchBuildingHelper) RefreshPatchBuildingPanel(opts types.OnFocusOpts) {

pkg/gui/controllers/helpers/refresh_helper.go

Lines changed: 27 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func (self *RefreshHelper) Refresh(options types.RefreshOptions) error {
157157
}
158158

159159
if scopeSet.Includes(types.STASH) {
160-
refresh("stash", func() { _ = self.refreshStashEntries() })
160+
refresh("stash", func() { self.refreshStashEntries() })
161161
}
162162

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

171171
if scopeSet.Includes(types.WORKTREES) && !includeWorktreesWithBranches {
172-
refresh("worktrees", func() { _ = self.refreshWorktrees() })
172+
refresh("worktrees", func() { self.refreshWorktrees() })
173173
}
174174

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

346-
return self.refreshView(self.c.Contexts().LocalCommits)
346+
self.refreshView(self.c.Contexts().LocalCommits)
347+
return nil
347348
}
348349

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

371-
return self.refreshView(self.c.Contexts().SubCommits)
372+
self.refreshView(self.c.Contexts().SubCommits)
373+
return nil
372374
}
373375

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

400-
return self.refreshView(self.c.Contexts().CommitFiles)
402+
self.refreshView(self.c.Contexts().CommitFiles)
403+
return nil
401404
}
402405

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

414-
return self.refreshView(self.c.Contexts().LocalCommits)
417+
self.refreshView(self.c.Contexts().LocalCommits)
418+
return nil
415419
}
416420

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

423427
self.c.Model().Tags = tags
424428

425-
return self.refreshView(self.c.Contexts().Tags)
429+
self.refreshView(self.c.Contexts().Tags)
430+
return nil
426431
}
427432

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

483488
if refreshWorktrees {
484489
self.loadWorktrees()
485-
if err := self.refreshView(self.c.Contexts().Worktrees); err != nil {
486-
self.c.Log.Error(err)
487-
}
490+
self.refreshView(self.c.Contexts().Worktrees)
488491
}
489492

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

498-
if err := self.refreshView(self.c.Contexts().Branches); err != nil {
499-
self.c.Log.Error(err)
500-
}
501+
self.refreshView(self.c.Contexts().Branches)
501502

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

527528
self.c.OnUIThread(func() error {
528-
if err := self.refreshView(self.c.Contexts().Submodules); err != nil {
529-
self.c.Log.Error(err)
530-
}
531-
532-
if err := self.refreshView(self.c.Contexts().Files); err != nil {
533-
self.c.Log.Error(err)
534-
}
535-
529+
self.refreshView(self.c.Contexts().Submodules)
530+
self.refreshView(self.c.Contexts().Files)
536531
return nil
537532
})
538533

@@ -653,7 +648,8 @@ func (self *RefreshHelper) refreshReflogCommits() error {
653648
model.FilteredReflogCommits = model.ReflogCommits
654649
}
655650

656-
return self.refreshView(self.c.Contexts().ReflogCommits)
651+
self.refreshView(self.c.Contexts().ReflogCommits)
652+
return nil
657653
}
658654

659655
func (self *RefreshHelper) refreshRemotes() error {
@@ -677,14 +673,8 @@ func (self *RefreshHelper) refreshRemotes() error {
677673
}
678674
}
679675

680-
if err := self.refreshView(self.c.Contexts().Remotes); err != nil {
681-
return err
682-
}
683-
684-
if err := self.refreshView(self.c.Contexts().RemoteBranches); err != nil {
685-
return err
686-
}
687-
676+
self.refreshView(self.c.Contexts().Remotes)
677+
self.refreshView(self.c.Contexts().RemoteBranches)
688678
return nil
689679
}
690680

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

701-
func (self *RefreshHelper) refreshWorktrees() error {
691+
func (self *RefreshHelper) refreshWorktrees() {
702692
self.loadWorktrees()
703693

704694
// need to refresh branches because the branches view shows worktrees against
705695
// branches
706-
if err := self.refreshView(self.c.Contexts().Branches); err != nil {
707-
return err
708-
}
709-
710-
return self.refreshView(self.c.Contexts().Worktrees)
696+
self.refreshView(self.c.Contexts().Branches)
697+
self.refreshView(self.c.Contexts().Worktrees)
711698
}
712699

713-
func (self *RefreshHelper) refreshStashEntries() error {
700+
func (self *RefreshHelper) refreshStashEntries() {
714701
self.c.Model().StashEntries = self.c.Git().Loaders.StashLoader.
715702
GetStashEntries(self.c.Modes().Filtering.GetPath())
716703

717-
return self.refreshView(self.c.Contexts().Stash)
704+
self.refreshView(self.c.Contexts().Stash)
718705
}
719706

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

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

762-
err := self.c.PostRefreshUpdate(context)
749+
self.c.PostRefreshUpdate(context)
763750

764751
self.c.AfterLayout(func() error {
765752
// Re-applying the search must be done after re-rendering the view though,
@@ -773,6 +760,4 @@ func (self *RefreshHelper) refreshView(context types.Context) error {
773760
self.searchHelper.ReApplySearch(context)
774761
return nil
775762
})
776-
777-
return err
778763
}

pkg/gui/controllers/helpers/search_helper.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ func (self *SearchHelper) Cancel() {
213213
switch context := state.Context.(type) {
214214
case types.IFilterableContext:
215215
context.ClearFilter()
216-
_ = self.c.PostRefreshUpdate(context)
216+
self.c.PostRefreshUpdate(context)
217217
case types.ISearchableContext:
218218
context.ClearSearchString()
219219
context.GetView().ClearSearch()
@@ -231,7 +231,7 @@ func (self *SearchHelper) OnPromptContentChanged(searchString string) {
231231
context.SetSelection(0)
232232
context.GetView().SetOriginY(0)
233233
context.SetFilter(searchString, self.c.UserConfig().Gui.UseFuzzySearch())
234-
_ = self.c.PostRefreshUpdate(context)
234+
self.c.PostRefreshUpdate(context)
235235
case types.ISearchableContext:
236236
// do nothing
237237
default:

pkg/gui/controllers/helpers/sub_commits_helper.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,7 @@ func (self *SubCommitsHelper) ViewSubCommits(opts ViewSubCommitsOpts) error {
6767
subCommitsContext.GetView().ClearSearch()
6868
subCommitsContext.GetView().TitlePrefix = opts.Context.GetView().TitlePrefix
6969

70-
err = self.c.PostRefreshUpdate(self.c.Contexts().SubCommits)
71-
if err != nil {
72-
return err
73-
}
70+
self.c.PostRefreshUpdate(self.c.Contexts().SubCommits)
7471

7572
self.c.Context().Push(self.c.Contexts().SubCommits)
7673
return nil

pkg/gui/controllers/local_commits_controller.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,10 +1177,9 @@ func (self *LocalCommitsController) handleOpenLogMenu() error {
11771177
return func() error {
11781178
self.c.GetAppState().GitLogShowGraph = value
11791179
self.c.SaveAppStateAndLogError()
1180-
if err := self.c.PostRefreshUpdate(self.c.Contexts().LocalCommits); err != nil {
1181-
return err
1182-
}
1183-
return self.c.PostRefreshUpdate(self.c.Contexts().SubCommits)
1180+
self.c.PostRefreshUpdate(self.c.Contexts().LocalCommits)
1181+
self.c.PostRefreshUpdate(self.c.Contexts().SubCommits)
1182+
return nil
11841183
}
11851184
}
11861185
return self.c.Menu(types.CreateMenuOptions{
@@ -1286,7 +1285,8 @@ func (self *LocalCommitsController) markAsBaseCommit(commit *models.Commit) erro
12861285
} else {
12871286
self.c.Modes().MarkedBaseCommit.SetHash(commit.Hash)
12881287
}
1289-
return self.c.PostRefreshUpdate(self.c.Contexts().LocalCommits)
1288+
self.c.PostRefreshUpdate(self.c.Contexts().LocalCommits)
1289+
return nil
12901290
}
12911291

12921292
func (self *LocalCommitsController) isHeadCommit(idx int) bool {

pkg/gui/controllers/patch_building_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ func (self *PatchBuildingController) Escape() error {
160160

161161
if state.SelectingRange() || state.SelectingHunk() {
162162
state.SetLineSelectMode()
163-
return self.c.PostRefreshUpdate(context)
163+
self.c.PostRefreshUpdate(context)
164+
return nil
164165
}
165166

166167
self.c.Helpers().PatchBuilding.Escape()

0 commit comments

Comments
 (0)