mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-17 12:06:38 +02:00
Prompt for commit message when moving a custom patch to a new commit
This commit is contained in:
parent
1b05ba252c
commit
c21633b1be
@ -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) {
|
func (self *CommitCommands) GetCommitMessage(commitSha string) (string, error) {
|
||||||
cmdArgs := NewGitCmd("rev-list").
|
cmdArgs := NewGitCmd("rev-list").
|
||||||
Arg("--format=%B", "--max-count=1", commitSha).
|
Arg("--format=%B", "--max-count=1", commitSha).
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package git_commands
|
package git_commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -274,7 +273,12 @@ func (self *PatchCommands) MovePatchIntoIndex(commits []*models.Commit, commitId
|
|||||||
return self.rebase.ContinueRebase()
|
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 {
|
if err := self.rebase.BeginInteractiveRebaseForCommit(commits, commitIdx, false); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -300,9 +304,7 @@ func (self *PatchCommands) PullPatchIntoNewCommit(commits []*models.Commit, comm
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
head_message, _ := self.commit.GetHeadCommitMessage()
|
if err := self.commit.CommitCmdObj(commitSummary, commitDescription).Run(); err != nil {
|
||||||
new_message := fmt.Sprintf("Split from \"%s\"", head_message)
|
|
||||||
if err := self.commit.CommitCmdObj(new_message, "").Run(); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
|
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
|
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -182,12 +183,26 @@ func (self *CustomPatchOptionsMenuAction) handlePullPatchIntoNewCommit() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return self.c.WithWaitingStatus(self.c.Tr.RebasingStatus, func(gocui.Task) error {
|
|
||||||
commitIndex := self.getPatchCommitIndex()
|
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)
|
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)
|
return self.c.Helpers().MergeAndRebase.CheckMergeOrRebase(err)
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *CustomPatchOptionsMenuAction) handleApplyPatch(reverse bool) error {
|
func (self *CustomPatchOptionsMenuAction) handleApplyPatch(reverse bool) error {
|
||||||
|
@ -50,11 +50,15 @@ var MoveToNewCommit = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
|
|
||||||
t.Common().SelectPatchOption(Contains("Move patch into new commit"))
|
t.Common().SelectPatchOption(Contains("Move patch into new commit"))
|
||||||
|
|
||||||
|
t.ExpectPopup().CommitMessagePanel().
|
||||||
|
InitialText(Equals("")).
|
||||||
|
Type("new commit").Confirm()
|
||||||
|
|
||||||
t.Views().Commits().
|
t.Views().Commits().
|
||||||
IsFocused().
|
IsFocused().
|
||||||
Lines(
|
Lines(
|
||||||
Contains("third commit"),
|
Contains("third commit"),
|
||||||
Contains(`Split from "commit to move from"`).IsSelected(),
|
Contains("new commit").IsSelected(),
|
||||||
Contains("commit to move from"),
|
Contains("commit to move from"),
|
||||||
Contains("first commit"),
|
Contains("first commit"),
|
||||||
).
|
).
|
||||||
@ -74,7 +78,7 @@ var MoveToNewCommit = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
IsFocused().
|
IsFocused().
|
||||||
Lines(
|
Lines(
|
||||||
Contains("third commit"),
|
Contains("third commit"),
|
||||||
Contains(`Split from "commit to move from"`).IsSelected(),
|
Contains("new commit").IsSelected(),
|
||||||
Contains("commit to move from"),
|
Contains("commit to move from"),
|
||||||
Contains("first commit"),
|
Contains("first commit"),
|
||||||
).
|
).
|
||||||
|
@ -47,6 +47,10 @@ var MoveToNewCommitPartialHunk = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
|
|
||||||
t.Common().SelectPatchOption(Contains("Move patch into new commit"))
|
t.Common().SelectPatchOption(Contains("Move patch into new commit"))
|
||||||
|
|
||||||
|
t.ExpectPopup().CommitMessagePanel().
|
||||||
|
InitialText(Equals("")).
|
||||||
|
Type("new commit").Confirm()
|
||||||
|
|
||||||
t.Views().CommitFiles().
|
t.Views().CommitFiles().
|
||||||
IsFocused().
|
IsFocused().
|
||||||
Lines(
|
Lines(
|
||||||
@ -62,7 +66,7 @@ var MoveToNewCommitPartialHunk = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
IsFocused().
|
IsFocused().
|
||||||
Lines(
|
Lines(
|
||||||
Contains("third commit"),
|
Contains("third commit"),
|
||||||
Contains(`Split from "commit to move from"`).IsSelected(),
|
Contains("new commit").IsSelected(),
|
||||||
Contains("commit to move from"),
|
Contains("commit to move from"),
|
||||||
Contains("first commit"),
|
Contains("first commit"),
|
||||||
).
|
).
|
||||||
|
Loading…
x
Reference in New Issue
Block a user