diff --git a/pkg/commands/git_commands/commit.go b/pkg/commands/git_commands/commit.go index 9a37ddb34..16702f9be 100644 --- a/pkg/commands/git_commands/commit.go +++ b/pkg/commands/git_commands/commit.go @@ -107,14 +107,6 @@ func (self *CommitCommands) signoffFlag() string { } } -// Get the subject of the HEAD commit -func (self *CommitCommands) GetHeadCommitMessage() (string, error) { - cmdArgs := NewGitCmd("log").Arg("-1", "--pretty=%s").ToArgv() - - message, err := self.cmd.New(cmdArgs).DontLog().RunWithOutput() - return strings.TrimSpace(message), err -} - func (self *CommitCommands) GetCommitMessage(commitSha string) (string, error) { cmdArgs := NewGitCmd("rev-list"). Arg("--format=%B", "--max-count=1", commitSha). diff --git a/pkg/commands/git_commands/patch.go b/pkg/commands/git_commands/patch.go index 56747a315..dba700c3a 100644 --- a/pkg/commands/git_commands/patch.go +++ b/pkg/commands/git_commands/patch.go @@ -1,7 +1,6 @@ package git_commands import ( - "fmt" "path/filepath" "time" @@ -274,7 +273,12 @@ func (self *PatchCommands) MovePatchIntoIndex(commits []*models.Commit, commitId return self.rebase.ContinueRebase() } -func (self *PatchCommands) PullPatchIntoNewCommit(commits []*models.Commit, commitIdx int) error { +func (self *PatchCommands) PullPatchIntoNewCommit( + commits []*models.Commit, + commitIdx int, + commitSummary string, + commitDescription string, +) error { if err := self.rebase.BeginInteractiveRebaseForCommit(commits, commitIdx, false); err != nil { return err } @@ -300,9 +304,7 @@ func (self *PatchCommands) PullPatchIntoNewCommit(commits []*models.Commit, comm return err } - head_message, _ := self.commit.GetHeadCommitMessage() - new_message := fmt.Sprintf("Split from \"%s\"", head_message) - if err := self.commit.CommitCmdObj(new_message, "").Run(); err != nil { + if err := self.commit.CommitCmdObj(commitSummary, commitDescription).Run(); err != nil { return err } diff --git a/pkg/gui/controllers/custom_patch_options_menu_action.go b/pkg/gui/controllers/custom_patch_options_menu_action.go index 55793f8f5..3adedfc1b 100644 --- a/pkg/gui/controllers/custom_patch_options_menu_action.go +++ b/pkg/gui/controllers/custom_patch_options_menu_action.go @@ -5,6 +5,7 @@ import ( "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/commands/types/enums" + "github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers" "github.com/jesseduffield/lazygit/pkg/gui/types" ) @@ -182,12 +183,26 @@ func (self *CustomPatchOptionsMenuAction) handlePullPatchIntoNewCommit() error { return err } - return self.c.WithWaitingStatus(self.c.Tr.RebasingStatus, func(gocui.Task) error { - commitIndex := self.getPatchCommitIndex() - self.c.LogAction(self.c.Tr.Actions.MovePatchIntoNewCommit) - err := self.c.Git().Patch.PullPatchIntoNewCommit(self.c.Model().Commits, commitIndex) - return self.c.Helpers().MergeAndRebase.CheckMergeOrRebase(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 { diff --git a/pkg/integration/tests/patch_building/move_to_new_commit.go b/pkg/integration/tests/patch_building/move_to_new_commit.go index 44d5ac167..1df3e5dcb 100644 --- a/pkg/integration/tests/patch_building/move_to_new_commit.go +++ b/pkg/integration/tests/patch_building/move_to_new_commit.go @@ -50,11 +50,15 @@ var MoveToNewCommit = NewIntegrationTest(NewIntegrationTestArgs{ t.Common().SelectPatchOption(Contains("Move patch into new commit")) + t.ExpectPopup().CommitMessagePanel(). + InitialText(Equals("")). + Type("new commit").Confirm() + t.Views().Commits(). IsFocused(). Lines( Contains("third commit"), - Contains(`Split from "commit to move from"`).IsSelected(), + Contains("new commit").IsSelected(), Contains("commit to move from"), Contains("first commit"), ). @@ -74,7 +78,7 @@ var MoveToNewCommit = NewIntegrationTest(NewIntegrationTestArgs{ IsFocused(). Lines( Contains("third commit"), - Contains(`Split from "commit to move from"`).IsSelected(), + Contains("new commit").IsSelected(), Contains("commit to move from"), Contains("first commit"), ). diff --git a/pkg/integration/tests/patch_building/move_to_new_commit_partial_hunk.go b/pkg/integration/tests/patch_building/move_to_new_commit_partial_hunk.go index 69c7cb9de..dd0b4c3f2 100644 --- a/pkg/integration/tests/patch_building/move_to_new_commit_partial_hunk.go +++ b/pkg/integration/tests/patch_building/move_to_new_commit_partial_hunk.go @@ -47,6 +47,10 @@ var MoveToNewCommitPartialHunk = NewIntegrationTest(NewIntegrationTestArgs{ t.Common().SelectPatchOption(Contains("Move patch into new commit")) + t.ExpectPopup().CommitMessagePanel(). + InitialText(Equals("")). + Type("new commit").Confirm() + t.Views().CommitFiles(). IsFocused(). Lines( @@ -62,7 +66,7 @@ var MoveToNewCommitPartialHunk = NewIntegrationTest(NewIntegrationTestArgs{ IsFocused(). Lines( Contains("third commit"), - Contains(`Split from "commit to move from"`).IsSelected(), + Contains("new commit").IsSelected(), Contains("commit to move from"), Contains("first commit"), ).