@@ -41,47 +41,51 @@ execSync('git fetch origin');
4141// Find the branch
4242const branchRefs = { } ;
4343for ( const name of config [ 'branches' ] ) {
44- const output = execSync ( `git show-ref --hash ${ name } ` , { encoding : 'utf-8' } ) ;
45- if ( output ) {
46- branchRefs [ name ] = output ;
44+ try {
45+ const output = execSync ( `git show-ref --hash ${ name } ` , { encoding : 'utf-8' } ) ;
46+ if ( output ) {
47+ branchRefs [ name ] = output . replace ( / \n / g, '' ) . trim ( ) ;
48+ }
49+ } catch ( e ) {
50+ // Ignore.
4751 }
4852}
49- logger . info ( `Found refs for branches:\n ${ Object . entries ( branchRefs ) . forEach ( ( [ key , value ] ) => {
50- return `${ key } => ${ value } ` ;
53+ logger . info ( `Found refs for branches:\n ${ Object . keys ( branchRefs ) . map ( key => {
54+ return `${ key } => ${ JSON . stringify ( branchRefs [ key ] ) } ` ;
5155} ) . join ( '\n ' ) } `) ;
5256
5357
5458const output = execSync ( 'git log --format="%H %s" --no-merges' , { encoding : 'utf-8' } ) ;
5559
5660if ( output . length === 0 ) {
5761 logger . warn ( 'There are zero new commits between this HEAD and master' ) ;
58- return ;
62+ process . exit ( 0 ) ;
5963}
6064
61- const commitByLines = [ ] ;
65+ const commitsByLine = [ ] ;
6266let branch = null ;
6367
6468// Finding the closest branch marker.
65- for ( const line of output . split ( / n / ) ) {
66- const [ hash , ...messageArray ] = line . split ( / / ) ;
69+ for ( const line of output . split ( / \ n/ ) ) {
70+ const [ hash , ...messageArray ] = line . split ( ' ' ) ;
6771 const message = messageArray . join ( ' ' ) ;
6872
69- const maybeBranch = Object . keys ( branchRefs ) . find ( branchName => branchRefs [ branchName ] == hash ) ;
73+ const maybeBranch = Object . keys ( branchRefs ) . find ( branchName => branchRefs [ branchName ] === hash ) ;
7074 if ( maybeBranch ) {
7175 branch = maybeBranch ;
7276 break ;
7377 }
74- commitByLines . push ( message ) ;
78+ commitsByLine . push ( message ) ;
7579}
7680
7781if ( ! branch ) {
7882 logger . fatal ( 'Something wrong happened.' ) ;
79- return ;
83+ process . exit ( 1 ) ;
8084}
8185
8286logger . info ( `Examining ${ commitsByLine . length } commit(s) between HEAD and ${ branch } ` ) ;
8387
84- const someCommitsInvalid = ! commitsByLine . every ( validateCommitMessage ) ;
88+ const someCommitsInvalid = ! commitsByLine . every ( message => validateCommitMessage ( message , branch ) ) ;
8589
8690if ( someCommitsInvalid ) {
8791 logger . error ( 'Please fix the failing commit messages before continuing...' ) ;
0 commit comments