@@ -41,47 +41,51 @@ execSync('git fetch origin');
41
41
// Find the branch
42
42
const branchRefs = { } ;
43
43
for ( 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.
47
51
}
48
52
}
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 ] ) } ` ;
51
55
} ) . join ( '\n ' ) } `) ;
52
56
53
57
54
58
const output = execSync ( 'git log --format="%H %s" --no-merges' , { encoding : 'utf-8' } ) ;
55
59
56
60
if ( output . length === 0 ) {
57
61
logger . warn ( 'There are zero new commits between this HEAD and master' ) ;
58
- return ;
62
+ process . exit ( 0 ) ;
59
63
}
60
64
61
- const commitByLines = [ ] ;
65
+ const commitsByLine = [ ] ;
62
66
let branch = null ;
63
67
64
68
// 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 ( ' ' ) ;
67
71
const message = messageArray . join ( ' ' ) ;
68
72
69
- const maybeBranch = Object . keys ( branchRefs ) . find ( branchName => branchRefs [ branchName ] == hash ) ;
73
+ const maybeBranch = Object . keys ( branchRefs ) . find ( branchName => branchRefs [ branchName ] === hash ) ;
70
74
if ( maybeBranch ) {
71
75
branch = maybeBranch ;
72
76
break ;
73
77
}
74
- commitByLines . push ( message ) ;
78
+ commitsByLine . push ( message ) ;
75
79
}
76
80
77
81
if ( ! branch ) {
78
82
logger . fatal ( 'Something wrong happened.' ) ;
79
- return ;
83
+ process . exit ( 1 ) ;
80
84
}
81
85
82
86
logger . info ( `Examining ${ commitsByLine . length } commit(s) between HEAD and ${ branch } ` ) ;
83
87
84
- const someCommitsInvalid = ! commitsByLine . every ( validateCommitMessage ) ;
88
+ const someCommitsInvalid = ! commitsByLine . every ( message => validateCommitMessage ( message , branch ) ) ;
85
89
86
90
if ( someCommitsInvalid ) {
87
91
logger . error ( 'Please fix the failing commit messages before continuing...' ) ;
0 commit comments