forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpre-push.ts
44 lines (36 loc) · 1.13 KB
/
pre-push.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
// tslint:disable:no-any
// tslint:disable:no-implicit-dependencies
import { logging } from '@angular-devkit/core';
import * as readline from 'readline';
import validateCommits from '../validate-commits';
const emptySha = '0'.repeat(40);
export default function (_: {}, logger: logging.Logger) {
let validateCommitResult = 0;
// Work on POSIX and Windows
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false,
});
rl.on('line', line => {
const [, localSha, , remoteSha] = line.split(/\s+/);
if (localSha == emptySha) {
// Deleted branch.
return;
}
if (remoteSha == emptySha) {
// New branch.
validateCommitResult = validateCommits({ base: localSha }, logger);
} else {
validateCommitResult = validateCommits({ base: remoteSha, head: localSha }, logger);
}
});
rl.on('end', () => process.exit(validateCommitResult));
}