Skip to content

Commit b39bbde

Browse files
committed
fix(cli): don't drop body from -m args
1 parent c72bb94 commit b39bbde

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

cmd/cli.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ func mainMode(cmd *cobra.Command, args []string, cfg *config.Cfg) {
114114
message, _ := cmd.Flags().GetStringArray("message")
115115

116116
if len(message) > 0 {
117+
//> If multiple `-m` options are given, their values are concatenated as separate paragraphs.
118+
//> see https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---messageltmsggt
117119
cc, _ = parser.ParseAsMuchOfCCAsPossible(strings.Join(message, "\n\n"))
118120
} else {
119121
cc, _ = parser.ParseAsMuchOfCCAsPossible((strings.Join(args, " ")))

cmd/tui.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ type model struct {
5151
// the width of the terminal; needed for instantiating components
5252
// width int
5353
choice chan string
54+
// any body stashed during the initial parse of command-line --message args
55+
remainingBody string
5456
}
5557

5658
// returns whether the minimum requirements for a conventional commit are met.
@@ -73,17 +75,26 @@ func (m model) contextValue() string {
7375
result.WriteString(": ")
7476
return result.String()
7577
}
78+
func (m model) descriptionValue() string {
79+
return m.commit[shortDescriptionIndex]
80+
}
81+
func (m model) breakingChangeValue() string {
82+
return m.commit[breakingChangeIndex]
83+
}
7684

7785
// Returns a pretty-printed CC string. The model should be `.ready()` before you call `.value()`.
7886
func (m model) value() string {
7987
result := strings.Builder{}
8088
result.WriteString(m.contextValue())
81-
result.WriteString(m.commit[shortDescriptionIndex])
89+
result.WriteString(m.descriptionValue())
8290
result.WriteString("\n")
83-
breakingChange := m.commit[breakingChangeIndex]
84-
if breakingChange != "" {
85-
result.WriteString(fmt.Sprintf("\n\nBREAKING CHANGE: %s\n", breakingChange))
91+
if m.remainingBody != "" {
92+
result.WriteString(m.remainingBody)
93+
result.WriteString("\n")
94+
}
95+
if breakingChange := m.breakingChangeValue(); breakingChange != "" {
8696
// TODO: handle multiple breaking change footers(?)
97+
result.WriteString(fmt.Sprintf("\n\nBREAKING CHANGE: %s\n", breakingChange))
8798
}
8899
return result.String()
89100
}
@@ -134,6 +145,7 @@ func initialModel(choice chan string, cc *parser.CC, cfg *config.Cfg) model {
134145
descriptionInput: descModel,
135146
breakingChangeInput: bcModel,
136147
viewing: commitTypeIndex,
148+
remainingBody: cc.Body,
137149
}
138150
if m.shouldSkip(m.viewing) {
139151
m = m.submit().advance()

0 commit comments

Comments
 (0)