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

Code before:
		return self.c.Confirm(types.ConfirmOpts{
			Title:  self.c.Tr.MustStashTitle,
			Prompt: self.c.Tr.MustStashWarning,
			HandleConfirm: func() error {
				return pull(true)
			},
		})
	} else {
		return pull(false)
	}
}

func (self *CustomPatchOptionsMenuAction) handlePullPatchIntoNewCommit() error {
	if ok, err := self.validateNormalWorkingTreeState(); !ok {
		return err
	}

	if err := self.returnFocusFromPatchExplorerIfNecessary(); err != nil {
		return err
	}

	commitIndex := self.getPatchCommitIndex()
	return self.c.Helpers().Commits.OpenCommitMessagePanel(
		&helpers.OpenCommitMessagePanelOpts{
			CommitIndex:     commitIndex,
			InitialMessage:  "",
			Title:           self.c.Tr.CommitSummary,
			PreserveMessage: false,
			OnConfirm: func(message string) error {
				return self.c.WithWaitingStatus(self.c.Tr.RebasingStatus, func(gocui.Task) error {
					_ = self.c.Helpers().Commits.PopCommitMessageContexts()
					self.c.LogAction(self.c.Tr.Actions.MovePatchIntoNewCommit)
					err := self.c.Git().Patch.PullPatchIntoNewCommit(self.c.Model().Commits, commitIndex, message)
					return self.c.Helpers().MergeAndRebase.CheckMergeOrRebase(err)
				})
			},
		},
	)
}

func (self *CustomPatchOptionsMenuAction) handleApplyPatch(reverse bool) error {
	if err := self.returnFocusFromPatchExplorerIfNecessary(); err != nil {
		return err
	}

	action := self.c.Tr.Actions.ApplyPatch
	if reverse {
		action = "Apply patch in reverse"
	}
	self.c.LogAction(action)
	if err := self.c.Git().Patch.ApplyCustomPatch(reverse); err != nil {

Review comment (suggestion):
In the original PR (#2436) this was initialized to `Split from "<original message>"`, which I don't think is useful. You always have to delete that text before typing your own.

I briefly considered initializing this to the original message, which would be useful in the case that you want to keep the message in the second commit, and then reword the first commit afterwards (which, for me, happens in roughly 50% of the cases). However, it would be inconvenient in the other 50%; and since you can get the message of the previous commit by pressing down and up arrow, it's probably best to start with an empty panel.

Code after:
		return self.c.Confirm(types.ConfirmOpts{
			Title:  self.c.Tr.MustStashTitle,
			Prompt: self.c.Tr.MustStashWarning,
			HandleConfirm: func() error {
				return pull(true)
			},
		})
	} else {
		return pull(false)
	}
}

func (self *CustomPatchOptionsMenuAction) handlePullPatchIntoNewCommit() error {
	if ok, err := self.validateNormalWorkingTreeState(); !ok {
		return err
	}

	if err := self.returnFocusFromPatchExplorerIfNecessary(); err != nil {
		return err
	}

	commitIndex := self.getPatchCommitIndex()
	return self.c.Helpers().Commits.OpenCommitMessagePanel(
		&helpers.OpenCommitMessagePanelOpts{
			// Pass a commit index of one less than the moved-from commit, so that
			// you can press up arrow once to recall the original commit message:
			CommitIndex:      commitIndex - 1,
			InitialMessage:   "",
			SummaryTitle:     self.c.Tr.CommitSummaryTitle,
			DescriptionTitle: self.c.Tr.CommitDescriptionTitle,
			PreserveMessage:  false,
			OnConfirm: func(summary string, description string) error {
				return self.c.WithWaitingStatus(self.c.Tr.RebasingStatus, func(gocui.Task) error {
					_ = self.c.Helpers().Commits.PopCommitMessageContexts()
					self.c.LogAction(self.c.Tr.Actions.MovePatchIntoNewCommit)
					err := self.c.Git().Patch.PullPatchIntoNewCommit(self.c.Model().Commits, commitIndex, summary, description)
					return self.c.Helpers().MergeAndRebase.CheckMergeOrRebase(err)
				})
			},
		},
	)
}

func (self *CustomPatchOptionsMenuAction) handleApplyPatch(reverse bool) error {
	if err := self.returnFocusFromPatchExplorerIfNecessary(); err != nil {
		return err
	}

	action := self.c.Tr.Actions.ApplyPatch
	if reverse {
		action = "Apply patch in reverse"