Skip to content

Commit eddce1f

Browse files
stefanhallerjesseduffield
authored andcommitted
Prompt for commit message when moving a custom patch to a new commit
1 parent c595833 commit eddce1f

File tree

5 files changed

+37
-22
lines changed

5 files changed

+37
-22
lines changed

pkg/commands/git_commands/commit.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,6 @@ func (self *CommitCommands) signoffFlag() string {
107107
}
108108
}
109109

110-
// Get the subject of the HEAD commit
111-
func (self *CommitCommands) GetHeadCommitMessage() (string, error) {
112-
cmdArgs := NewGitCmd("log").Arg("-1", "--pretty=%s").ToArgv()
113-
114-
message, err := self.cmd.New(cmdArgs).DontLog().RunWithOutput()
115-
return strings.TrimSpace(message), err
116-
}
117-
118110
func (self *CommitCommands) GetCommitMessage(commitSha string) (string, error) {
119111
cmdArgs := NewGitCmd("rev-list").
120112
Arg("--format=%B", "--max-count=1", commitSha).

pkg/commands/git_commands/patch.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package git_commands
22

33
import (
4-
"fmt"
54
"path/filepath"
65
"time"
76

@@ -274,7 +273,12 @@ func (self *PatchCommands) MovePatchIntoIndex(commits []*models.Commit, commitId
274273
return self.rebase.ContinueRebase()
275274
}
276275

277-
func (self *PatchCommands) PullPatchIntoNewCommit(commits []*models.Commit, commitIdx int) error {
276+
func (self *PatchCommands) PullPatchIntoNewCommit(
277+
commits []*models.Commit,
278+
commitIdx int,
279+
commitSummary string,
280+
commitDescription string,
281+
) error {
278282
if err := self.rebase.BeginInteractiveRebaseForCommit(commits, commitIdx, false); err != nil {
279283
return err
280284
}
@@ -300,9 +304,7 @@ func (self *PatchCommands) PullPatchIntoNewCommit(commits []*models.Commit, comm
300304
return err
301305
}
302306

303-
head_message, _ := self.commit.GetHeadCommitMessage()
304-
new_message := fmt.Sprintf("Split from \"%s\"", head_message)
305-
if err := self.commit.CommitCmdObj(new_message, "").Run(); err != nil {
307+
if err := self.commit.CommitCmdObj(commitSummary, commitDescription).Run(); err != nil {
306308
return err
307309
}
308310

pkg/gui/controllers/custom_patch_options_menu_action.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/jesseduffield/gocui"
77
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
8+
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
89
"github.com/jesseduffield/lazygit/pkg/gui/types"
910
)
1011

@@ -182,12 +183,24 @@ func (self *CustomPatchOptionsMenuAction) handlePullPatchIntoNewCommit() error {
182183
return err
183184
}
184185

185-
return self.c.WithWaitingStatus(self.c.Tr.RebasingStatus, func(gocui.Task) error {
186-
commitIndex := self.getPatchCommitIndex()
187-
self.c.LogAction(self.c.Tr.Actions.MovePatchIntoNewCommit)
188-
err := self.c.Git().Patch.PullPatchIntoNewCommit(self.c.Model().Commits, commitIndex)
189-
return self.c.Helpers().MergeAndRebase.CheckMergeOrRebase(err)
190-
})
186+
commitIndex := self.getPatchCommitIndex()
187+
return self.c.Helpers().Commits.OpenCommitMessagePanel(
188+
&helpers.OpenCommitMessagePanelOpts{
189+
CommitIndex: commitIndex,
190+
InitialMessage: "",
191+
SummaryTitle: self.c.Tr.CommitSummaryTitle,
192+
DescriptionTitle: self.c.Tr.CommitDescriptionTitle,
193+
PreserveMessage: false,
194+
OnConfirm: func(summary string, description string) error {
195+
return self.c.WithWaitingStatus(self.c.Tr.RebasingStatus, func(gocui.Task) error {
196+
_ = self.c.Helpers().Commits.PopCommitMessageContexts()
197+
self.c.LogAction(self.c.Tr.Actions.MovePatchIntoNewCommit)
198+
err := self.c.Git().Patch.PullPatchIntoNewCommit(self.c.Model().Commits, commitIndex, summary, description)
199+
return self.c.Helpers().MergeAndRebase.CheckMergeOrRebase(err)
200+
})
201+
},
202+
},
203+
)
191204
}
192205

193206
func (self *CustomPatchOptionsMenuAction) handleApplyPatch(reverse bool) error {

pkg/integration/tests/patch_building/move_to_new_commit.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,15 @@ var MoveToNewCommit = NewIntegrationTest(NewIntegrationTestArgs{
5050

5151
t.Common().SelectPatchOption(Contains("Move patch into new commit"))
5252

53+
t.ExpectPopup().CommitMessagePanel().
54+
InitialText(Equals("")).
55+
Type("new commit").Confirm()
56+
5357
t.Views().Commits().
5458
IsFocused().
5559
Lines(
5660
Contains("third commit"),
57-
Contains(`Split from "commit to move from"`).IsSelected(),
61+
Contains("new commit").IsSelected(),
5862
Contains("commit to move from"),
5963
Contains("first commit"),
6064
).
@@ -74,7 +78,7 @@ var MoveToNewCommit = NewIntegrationTest(NewIntegrationTestArgs{
7478
IsFocused().
7579
Lines(
7680
Contains("third commit"),
77-
Contains(`Split from "commit to move from"`).IsSelected(),
81+
Contains("new commit").IsSelected(),
7882
Contains("commit to move from"),
7983
Contains("first commit"),
8084
).

pkg/integration/tests/patch_building/move_to_new_commit_partial_hunk.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ var MoveToNewCommitPartialHunk = NewIntegrationTest(NewIntegrationTestArgs{
4747

4848
t.Common().SelectPatchOption(Contains("Move patch into new commit"))
4949

50+
t.ExpectPopup().CommitMessagePanel().
51+
InitialText(Equals("")).
52+
Type("new commit").Confirm()
53+
5054
t.Views().CommitFiles().
5155
IsFocused().
5256
Lines(
@@ -62,7 +66,7 @@ var MoveToNewCommitPartialHunk = NewIntegrationTest(NewIntegrationTestArgs{
6266
IsFocused().
6367
Lines(
6468
Contains("third commit"),
65-
Contains(`Split from "commit to move from"`).IsSelected(),
69+
Contains("new commit").IsSelected(),
6670
Contains("commit to move from"),
6771
Contains("first commit"),
6872
).

0 commit comments

Comments
 (0)