1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-04 10:34:55 +02:00

Prompt for commit message when moving a custom patch to a new commit

This commit is contained in:
Stefan Haller 2023-07-20 11:17:01 +02:00
parent 1b05ba252c
commit c21633b1be
5 changed files with 39 additions and 22 deletions

View File

@ -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).

View File

@ -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
}

View File

@ -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()
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)
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 {

View File

@ -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"),
).

View File

@ -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"),
).