Repository: jesseduffield/lazygit
File: pkg/gui/controllers/helpers/cherry_pick_helper.go (Go)

Code before:
			self.getData().Add(commit, commitsList)
		}
	}

	return self.rerender()
}

// HandlePasteCommits begins a cherry-pick rebase with the commits the user has copied.
// Only to be called from the branch commits controller
func (self *CherryPickHelper) Paste() error {
	return self.c.Confirm(types.ConfirmOpts{
		Title:  self.c.Tr.CherryPick,
		Prompt: self.c.Tr.SureCherryPick,
		HandleConfirm: func() error {
			isInRebase, err := self.c.Git().Status.IsInInteractiveRebase()
			if err != nil {
				return err
			}
			if isInRebase {
				if err := self.c.Git().Rebase.CherryPickCommitsDuringRebase(self.getData().CherryPickedCommits); err != nil {
					return err
				}
				err = self.c.Refresh(types.RefreshOptions{
					Mode: types.SYNC, Scope: []types.RefreshableView{types.REBASE_COMMITS},
				})
				if err == nil {
					err = self.Reset()
				}
				return err
			}

			return self.c.WithWaitingStatus(self.c.Tr.CherryPickingStatus, func(gocui.Task) error {
				self.c.LogAction(self.c.Tr.Actions.CherryPick)
				err := self.c.Git().Rebase.CherryPickCommits(self.getData().CherryPickedCommits)
				err = self.rebaseHelper.CheckMergeOrRebase(err)
				if err == nil {
					// If we're in an interactive rebase at this point, it must
					// be because there were conflicts. Don't clear the copied
					// commits in this case, since we might want to abort and
					// try pasting them again.
					isInRebase, err = self.c.Git().Status.IsInInteractiveRebase()
					if err == nil && !isInRebase {
						err = self.Reset()
					}
				}
				return err
			})
		},
	})
}


Review comment (suggestion):
More idiomatic way of writing the same thing:
```go
if err != nil {
	return err
}
return self.Reset()
```

Code after:
			self.getData().Add(commit, commitsList)
		}
	}

	return self.rerender()
}

// HandlePasteCommits begins a cherry-pick rebase with the commits the user has copied.
// Only to be called from the branch commits controller
func (self *CherryPickHelper) Paste() error {
	return self.c.Confirm(types.ConfirmOpts{
		Title:  self.c.Tr.CherryPick,
		Prompt: self.c.Tr.SureCherryPick,
		HandleConfirm: func() error {
			isInRebase, err := self.c.Git().Status.IsInInteractiveRebase()
			if err != nil {
				return err
			}
			if isInRebase {
				if err := self.c.Git().Rebase.CherryPickCommitsDuringRebase(self.getData().CherryPickedCommits); err != nil {
					return err
				}
				err = self.c.Refresh(types.RefreshOptions{
					Mode: types.SYNC, Scope: []types.RefreshableView{types.REBASE_COMMITS},
				})
				if err != nil {
					return err
				}

				return self.Reset()
			}

			return self.c.WithWaitingStatus(self.c.Tr.CherryPickingStatus, func(gocui.Task) error {
				self.c.LogAction(self.c.Tr.Actions.CherryPick)
				err := self.c.Git().Rebase.CherryPickCommits(self.getData().CherryPickedCommits)
				err = self.rebaseHelper.CheckMergeOrRebase(err)
				if err != nil {
					return err
				}

				// If we're in an interactive rebase at this point, it must
				// be because there were conflicts. Don't clear the copied
				// commits in this case, since we might want to abort and
				// try pasting them again.
				isInRebase, err = self.c.Git().Status.IsInInteractiveRebase()
				if err != nil {
					return err
				}
				if !isInRebase {
					return self.Reset()
				}