Skip to content

Commit 0e06240

Browse files
committed
Better tag creation UX
Previously we used a single-line prompt for a tag annotation. Now we're using the commit message prompt. I've had to update other uses of that prompt to allow the summary and description labels to be passed in
1 parent b284970 commit 0e06240

24 files changed

+162
-174
lines changed

pkg/cheatsheet/generate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func localisedTitle(tr *i18n.TranslationSet, str string) string {
101101
"reflogCommits": tr.ReflogCommitsTitle,
102102
"tags": tr.TagsTitle,
103103
"commitFiles": tr.CommitFilesTitle,
104-
"commitMessage": tr.CommitMessageTitle,
104+
"commitMessage": tr.CommitSummaryTitle,
105105
"commitDescription": tr.CommitDescriptionTitle,
106106
"commits": tr.CommitsTitle,
107107
"confirmation": tr.ConfirmationTitle,

pkg/commands/git_commands/commit.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ func (self *CommitCommands) ResetToCommit(sha string, strength string, envVars [
5050
Run()
5151
}
5252

53-
func (self *CommitCommands) CommitCmdObj(message string) oscommands.ICmdObj {
54-
messageArgs := self.commitMessageArgs(message)
53+
func (self *CommitCommands) CommitCmdObj(summary string, description string) oscommands.ICmdObj {
54+
messageArgs := self.commitMessageArgs(summary, description)
5555

5656
skipHookPrefix := self.UserConfig.Git.SkipHookPrefix
5757

5858
cmdArgs := NewGitCmd("commit").
59-
ArgIf(skipHookPrefix != "" && strings.HasPrefix(message, skipHookPrefix), "--no-verify").
59+
ArgIf(skipHookPrefix != "" && strings.HasPrefix(summary, skipHookPrefix), "--no-verify").
6060
ArgIf(self.signoffFlag() != "", self.signoffFlag()).
6161
Arg(messageArgs...).
6262
ToArgv()
@@ -69,8 +69,8 @@ func (self *CommitCommands) RewordLastCommitInEditorCmdObj() oscommands.ICmdObj
6969
}
7070

7171
// RewordLastCommit rewords the topmost commit with the given message
72-
func (self *CommitCommands) RewordLastCommit(message string) error {
73-
messageArgs := self.commitMessageArgs(message)
72+
func (self *CommitCommands) RewordLastCommit(summary string, description string) error {
73+
messageArgs := self.commitMessageArgs(summary, description)
7474

7575
cmdArgs := NewGitCmd("commit").
7676
Arg("--allow-empty", "--amend", "--only").
@@ -80,9 +80,8 @@ func (self *CommitCommands) RewordLastCommit(message string) error {
8080
return self.cmd.New(cmdArgs).Run()
8181
}
8282

83-
func (self *CommitCommands) commitMessageArgs(message string) []string {
84-
msg, description, _ := strings.Cut(message, "\n")
85-
args := []string{"-m", msg}
83+
func (self *CommitCommands) commitMessageArgs(summary string, description string) []string {
84+
args := []string{"-m", summary}
8685

8786
if description != "" {
8887
args = append(args, "-m", description)

pkg/commands/git_commands/commit_test.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,31 @@ import (
1010

1111
func TestCommitRewordCommit(t *testing.T) {
1212
type scenario struct {
13-
testName string
14-
runner *oscommands.FakeCmdObjRunner
15-
input string
13+
testName string
14+
runner *oscommands.FakeCmdObjRunner
15+
summary string
16+
description string
1617
}
1718
scenarios := []scenario{
1819
{
1920
"Single line reword",
2021
oscommands.NewFakeRunner(t).ExpectGitArgs([]string{"commit", "--allow-empty", "--amend", "--only", "-m", "test"}, "", nil),
2122
"test",
23+
"",
2224
},
2325
{
2426
"Multi line reword",
2527
oscommands.NewFakeRunner(t).ExpectGitArgs([]string{"commit", "--allow-empty", "--amend", "--only", "-m", "test", "-m", "line 2\nline 3"}, "", nil),
26-
"test\nline 2\nline 3",
28+
"test",
29+
"line 2\nline 3",
2730
},
2831
}
2932
for _, s := range scenarios {
3033
s := s
3134
t.Run(s.testName, func(t *testing.T) {
3235
instance := buildCommitCommands(commonDeps{runner: s.runner})
3336

34-
assert.NoError(t, instance.RewordLastCommit(s.input))
37+
assert.NoError(t, instance.RewordLastCommit(s.summary, s.description))
3538
s.runner.CheckForMissingCalls()
3639
})
3740
}
@@ -50,7 +53,8 @@ func TestCommitResetToCommit(t *testing.T) {
5053
func TestCommitCommitCmdObj(t *testing.T) {
5154
type scenario struct {
5255
testName string
53-
message string
56+
summary string
57+
description string
5458
configSignoff bool
5559
configSkipHookPrefix string
5660
expectedArgs []string
@@ -59,35 +63,36 @@ func TestCommitCommitCmdObj(t *testing.T) {
5963
scenarios := []scenario{
6064
{
6165
testName: "Commit",
62-
message: "test",
66+
summary: "test",
6367
configSignoff: false,
6468
configSkipHookPrefix: "",
6569
expectedArgs: []string{"commit", "-m", "test"},
6670
},
6771
{
6872
testName: "Commit with --no-verify flag",
69-
message: "WIP: test",
73+
summary: "WIP: test",
7074
configSignoff: false,
7175
configSkipHookPrefix: "WIP",
7276
expectedArgs: []string{"commit", "--no-verify", "-m", "WIP: test"},
7377
},
7478
{
7579
testName: "Commit with multiline message",
76-
message: "line1\nline2",
80+
summary: "line1",
81+
description: "line2",
7782
configSignoff: false,
7883
configSkipHookPrefix: "",
7984
expectedArgs: []string{"commit", "-m", "line1", "-m", "line2"},
8085
},
8186
{
8287
testName: "Commit with signoff",
83-
message: "test",
88+
summary: "test",
8489
configSignoff: true,
8590
configSkipHookPrefix: "",
8691
expectedArgs: []string{"commit", "--signoff", "-m", "test"},
8792
},
8893
{
8994
testName: "Commit with signoff and no-verify",
90-
message: "WIP: test",
95+
summary: "WIP: test",
9196
configSignoff: true,
9297
configSkipHookPrefix: "WIP",
9398
expectedArgs: []string{"commit", "--no-verify", "--signoff", "-m", "WIP: test"},
@@ -104,7 +109,7 @@ func TestCommitCommitCmdObj(t *testing.T) {
104109
runner := oscommands.NewFakeRunner(t).ExpectGitArgs(s.expectedArgs, "", nil)
105110
instance := buildCommitCommands(commonDeps{userConfig: userConfig, runner: runner})
106111

107-
assert.NoError(t, instance.CommitCmdObj(s.message).Run())
112+
assert.NoError(t, instance.CommitCmdObj(s.summary, s.description).Run())
108113
runner.CheckForMissingCalls()
109114
})
110115
}

pkg/commands/git_commands/patch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ func (self *PatchCommands) PullPatchIntoNewCommit(commits []*models.Commit, comm
302302

303303
head_message, _ := self.commit.GetHeadCommitMessage()
304304
new_message := fmt.Sprintf("Split from \"%s\"", head_message)
305-
if err := self.commit.CommitCmdObj(new_message).Run(); err != nil {
305+
if err := self.commit.CommitCmdObj(new_message, "").Run(); err != nil {
306306
return err
307307
}
308308

pkg/commands/git_commands/rebase.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ func NewRebaseCommands(
3535
}
3636
}
3737

38-
func (self *RebaseCommands) RewordCommit(commits []*models.Commit, index int, message string) error {
38+
func (self *RebaseCommands) RewordCommit(commits []*models.Commit, index int, summary string, description string) error {
3939
if models.IsHeadCommit(commits, index) {
4040
// we've selected the top commit so no rebase is required
41-
return self.commit.RewordLastCommit(message)
41+
return self.commit.RewordLastCommit(summary, description)
4242
}
4343

4444
err := self.BeginInteractiveRebaseForCommit(commits, index, false)
@@ -47,7 +47,7 @@ func (self *RebaseCommands) RewordCommit(commits []*models.Commit, index int, me
4747
}
4848

4949
// now the selected commit should be our head so we'll amend it with the new message
50-
err = self.commit.RewordLastCommit(message)
50+
err = self.commit.RewordLastCommit(summary, description)
5151
if err != nil {
5252
return err
5353
}

pkg/gui/context/commit_message_context.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type CommitMessageViewModel struct {
3131
// the full preserved message (combined summary and description)
3232
preservedMessage string
3333
// invoked when pressing enter in the commit message panel
34-
onConfirm func(string) error
34+
onConfirm func(string, string) error
3535

3636
// The message typed in before cycling through history
3737
// We store this separately to 'preservedMessage' because 'preservedMessage'
@@ -88,15 +88,22 @@ func (self *CommitMessageContext) SetHistoryMessage(message string) {
8888
self.viewModel.historyMessage = message
8989
}
9090

91-
func (self *CommitMessageContext) OnConfirm(message string) error {
92-
return self.viewModel.onConfirm(message)
91+
func (self *CommitMessageContext) OnConfirm(summary string, description string) error {
92+
return self.viewModel.onConfirm(summary, description)
9393
}
9494

95-
func (self *CommitMessageContext) SetPanelState(index int, title string, preserveMessage bool, onConfirm func(string) error) {
95+
func (self *CommitMessageContext) SetPanelState(
96+
index int,
97+
summaryTitle string,
98+
descriptionTitle string,
99+
preserveMessage bool,
100+
onConfirm func(string, string) error,
101+
) {
96102
self.viewModel.selectedindex = index
97103
self.viewModel.preserveMessage = preserveMessage
98104
self.viewModel.onConfirm = onConfirm
99-
self.GetView().Title = title
105+
self.GetView().Title = summaryTitle
106+
self.c.Views().CommitDescription.Title = descriptionTitle
100107
}
101108

102109
func (self *CommitMessageContext) RenderCommitLength() {

pkg/gui/controllers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (gui *Gui) resetHelpersAndControllers() {
7474
Suggestions: suggestionsHelper,
7575
Files: helpers.NewFilesHelper(helperCommon),
7676
WorkingTree: helpers.NewWorkingTreeHelper(helperCommon, refsHelper, commitsHelper, gpgHelper),
77-
Tags: helpers.NewTagsHelper(helperCommon),
77+
Tags: helpers.NewTagsHelper(helperCommon, commitsHelper),
7878
GPG: helpers.NewGpgHelper(helperCommon),
7979
MergeAndRebase: rebaseHelper,
8080
MergeConflicts: mergeConflictsHelper,

pkg/gui/controllers/branches_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ func (self *BranchesController) fastForward(branch *models.Branch) error {
395395
}
396396

397397
func (self *BranchesController) createTag(branch *models.Branch) error {
398-
return self.c.Helpers().Tags.CreateTagMenu(branch.FullRefName(), func() {})
398+
return self.c.Helpers().Tags.OpenCreateTagPrompt(branch.FullRefName(), func() {})
399399
}
400400

401401
func (self *BranchesController) createResetMenu(selectedBranch *models.Branch) error {

pkg/gui/controllers/helpers/commits_helper.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,29 @@ func (self *CommitsHelper) UpdateCommitPanelView(message string) {
7777
}
7878

7979
type OpenCommitMessagePanelOpts struct {
80-
CommitIndex int
81-
Title string
82-
PreserveMessage bool
83-
OnConfirm func(string) error
84-
InitialMessage string
80+
CommitIndex int
81+
SummaryTitle string
82+
DescriptionTitle string
83+
PreserveMessage bool
84+
OnConfirm func(summary string, description string) error
85+
InitialMessage string
8586
}
8687

8788
func (self *CommitsHelper) OpenCommitMessagePanel(opts *OpenCommitMessagePanelOpts) error {
89+
onConfirm := func(summary string, description string) error {
90+
if err := self.CloseCommitMessagePanel(); err != nil {
91+
return err
92+
}
93+
94+
return opts.OnConfirm(summary, description)
95+
}
96+
8897
self.c.Contexts().CommitMessage.SetPanelState(
8998
opts.CommitIndex,
90-
opts.Title,
99+
opts.SummaryTitle,
100+
opts.DescriptionTitle,
91101
opts.PreserveMessage,
92-
opts.OnConfirm,
102+
onConfirm,
93103
)
94104

95105
self.UpdateCommitPanelView(opts.InitialMessage)
@@ -102,17 +112,16 @@ func (self *CommitsHelper) OnCommitSuccess() {
102112
if self.c.Contexts().CommitMessage.GetPreserveMessage() {
103113
self.c.Contexts().CommitMessage.SetPreservedMessage("")
104114
}
105-
self.SetMessageAndDescriptionInView("")
106115
}
107116

108117
func (self *CommitsHelper) HandleCommitConfirm() error {
109-
fullMessage := self.JoinCommitMessageAndDescription()
118+
summary, description := self.getCommitSummary(), self.getCommitDescription()
110119

111-
if fullMessage == "" {
120+
if summary == "" {
112121
return self.c.ErrorMsg(self.c.Tr.CommitWithoutMessageErr)
113122
}
114123

115-
err := self.c.Contexts().CommitMessage.OnConfirm(fullMessage)
124+
err := self.c.Contexts().CommitMessage.OnConfirm(summary, description)
116125
if err != nil {
117126
return err
118127
}

0 commit comments

Comments
 (0)