@@ -12,7 +12,6 @@ interface Configuration {
1212 autoSync : boolean ;
1313 subjectLength : number ;
1414 showOutputChannel : 'off' | 'always' | 'onError' ;
15- quoteMessageInGitCommit : boolean ;
1615 capitalizeWindowsDriveLetter : boolean ;
1716 useGitRoot : boolean ;
1817 shell : boolean ;
@@ -45,7 +44,7 @@ export async function activate(
4544 await ccm . getBreaking ( ) ;
4645 await ccm . getFooter ( ) ;
4746 if ( ccm . complete ) {
48- await commit ( lookupPath , ccm . message . trim ( ) ) ;
47+ await commit ( lookupPath , ccm . messages ) ;
4948 }
5049 } else {
5150 channel . appendLine ( 'Lookup path not found' ) ;
@@ -76,6 +75,11 @@ interface CzConfig {
7675 footerPrefix : string ;
7776 skipQuestions ?: string [ ] ;
7877}
78+ type Messages = {
79+ main : string ;
80+ body : string ;
81+ footer : string ;
82+ } ;
7983
8084let gitRoot : string | undefined = undefined ;
8185async function findLookupPath ( ) : Promise < string | undefined > {
@@ -289,16 +293,41 @@ const DEFAULT_MESSAGES = {
289293 footer : 'List any ISSUES CLOSED by this change (optional). E.g.: #31, #34'
290294} ;
291295
292- async function commit ( cwd : string , message : string ) : Promise < void > {
293- const gitCmdArgs = getGitCmdArgs ( message , cwd ) ;
296+ const splitMessages = ( message : string ) => {
297+ const result : string [ ] = [ ] ;
298+
299+ if ( message . includes ( '|' ) ) {
300+ message . split ( '|' ) . forEach ( ( msg ) => {
301+ result . push ( '-m' , `"${ msg } "` ) ;
302+ } ) ;
303+ }
304+ return result ;
305+ } ;
306+
307+ const buildCommitArguments = ( message : Messages ) : string [ ] => {
308+ const messageArguments = [ '-m' , `"${ message . main } "` ] ;
309+
310+ if ( message . body ) {
311+ messageArguments . push ( ...splitMessages ( message . body ) ) ;
312+ }
313+
314+ if ( message . footer ) {
315+ messageArguments . push ( ...splitMessages ( message . footer ) ) ;
316+ }
317+
318+ const signArgument = getConfiguration ( ) . signCommits ? [ '-S' ] : [ ] ;
319+
320+ return [ ...messageArguments , ...signArgument ] ;
321+ } ;
322+
323+ async function commit ( cwd : string , message : Messages ) : Promise < void > {
294324
295- channel . appendLine ( `About to commit '${ gitCmdArgs . message } '` ) ;
325+ channel . appendLine ( `About to commit '${ message . main } '` ) ;
296326
297327 try {
298328 await conditionallyStageFiles ( cwd ) ;
299- const signArgument = getConfiguration ( ) . signCommits ? [ '-S' ] : [ ] ;
300- const result = await execa ( 'git' , [ 'commit' , '-m' , gitCmdArgs . message , ...signArgument ] , {
301- cwd : gitCmdArgs . cwd ,
329+ const result = await execa ( 'git' , [ 'commit' , ...buildCommitArguments ( message ) ] , {
330+ cwd : getGitCwd ( cwd ) ,
302331 preferLocal : false ,
303332 shell : getConfiguration ( ) . shell
304333 } ) ;
@@ -311,7 +340,7 @@ async function commit(cwd: string, message: string): Promise<void> {
311340 channel . show ( ) ;
312341 }
313342 }
314- } catch ( e ) {
343+ } catch ( e : any ) {
315344 vscode . window . showErrorMessage ( e . message ) ;
316345 channel . appendLine ( e . message ) ;
317346 channel . appendLine ( e . stack ) ;
@@ -359,8 +388,8 @@ class ConventionalCommitMessage {
359388 ) : czConfig is CzConfig {
360389 return Boolean (
361390 czConfig &&
362- czConfig . skipQuestions &&
363- czConfig . skipQuestions . includes ( messageType )
391+ czConfig . skipQuestions &&
392+ czConfig . skipQuestions . includes ( messageType )
364393 ) ;
365394 }
366395
@@ -376,8 +405,8 @@ class ConventionalCommitMessage {
376405 ) : czConfig is CzConfig {
377406 return Boolean (
378407 czConfig &&
379- czConfig . messages &&
380- czConfig . messages . hasOwnProperty ( messageType )
408+ czConfig . messages &&
409+ czConfig . messages . hasOwnProperty ( messageType )
381410 ) ;
382411 }
383412
@@ -494,7 +523,7 @@ class ConventionalCommitMessage {
494523 this . next = await ask (
495524 this . inputMessage ( 'body' ) ,
496525 ( input ) =>
497- ( this . body = wrap ( input . split ( '|' ) . join ( '\n' ) , 72 , { hard : true } ) )
526+ ( this . body = wrap ( input , 72 , { hard : true } ) )
498527 ) ;
499528 }
500529 }
@@ -528,24 +557,26 @@ class ConventionalCommitMessage {
528557 return this . next && Boolean ( this . type ) && Boolean ( this . subject ) ;
529558 }
530559
531- public get message ( ) : string {
532- return (
533- // tslint:disable-next-line: prefer-template
534- this . type +
535- ( typeof this . scope === 'string' && this . scope ? `(${ this . scope } )` : '' ) +
536- `: ${ this . subject } \n\n${ this . body } \n\n` +
537- ( this . breaking ? `BREAKING CHANGE: ${ this . breaking } \n` : '' ) +
538- this . messageFooter ( )
539- ) ;
560+ public get messages ( ) : Messages {
561+ const main = `${ this . type } ${ typeof this . scope === 'string' && this . scope ?
562+ `(${ this . scope } )` : ''
563+ } : ${ this . subject } `;
564+ const body = `${ this . body } ` ;
565+ const footer = `${ this . breaking ? `BREAKING CHANGE: ${ this . breaking } |` : '' } ${ this . messageFooter ( ) } ` ;
566+
567+ return {
568+ main,
569+ body,
570+ footer
571+ } ;
540572 }
541573
542574 private messageFooter ( ) : string {
543575 return this . footer
544- ? `${
545- this . czConfig && this . czConfig . footerPrefix
546- ? this . czConfig . footerPrefix
547- : 'Closes '
548- } ${ this . footer } `
576+ ? `${ this . czConfig && this . czConfig . footerPrefix
577+ ? this . czConfig . footerPrefix
578+ : 'Closes '
579+ } ${ this . footer } `
549580 : '' ;
550581 }
551582
@@ -569,25 +600,12 @@ function capitalizeWindowsDriveLetter(path: string): string {
569600 } ) ;
570601}
571602
572- function getGitCmdArgs ( message : string , cwd : string ) : GitCmdArgs {
573- let messageForGit = message ;
574-
575- if ( getConfiguration ( ) . quoteMessageInGitCommit ) {
576- messageForGit = `"${ message } "` ;
577- }
603+ function getGitCwd ( cwd : string ) : string {
578604 let cwdForGit = cwd ;
579605
580606 if ( getConfiguration ( ) . capitalizeWindowsDriveLetter ) {
581607 cwdForGit = capitalizeWindowsDriveLetter ( cwd ) ;
582608 }
583609
584- return {
585- message : messageForGit ,
586- cwd : cwdForGit
587- } ;
588- }
589-
590- interface GitCmdArgs {
591- message : string ;
592- cwd : string ;
610+ return cwdForGit ;
593611}
0 commit comments