forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit.ts
More file actions
37 lines (33 loc) · 1022 Bytes
/
git.ts
File metadata and controls
37 lines (33 loc) · 1022 Bytes
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
import {git, silentGit} from './process';
export function gitClean() {
console.log(' Cleaning git...');
return silentGit('clean', '-df')
.then(() => silentGit('reset', '--hard'))
.then(() => {
// Checkout missing files
return silentGit('status', '--porcelain')
.then(({ stdout }) => stdout
.split(/[\n\r]+/g)
.filter(line => line.match(/^ D/))
.map(line => line.replace(/^\s*\S+\s+/, '')))
.then(files => silentGit('checkout', ...files));
})
.then(() => expectGitToBeClean());
}
export function expectGitToBeClean() {
return silentGit('status', '--porcelain')
.then(({ stdout }) => {
if (stdout != '') {
throw new Error('Git repo is not clean...\n' + stdout);
}
});
}
export function gitCommit(message: string) {
return git('add', '-A')
.then(() => silentGit('status', '--porcelain'))
.then(({ stdout }) => {
if (stdout != '') {
return git('commit', '-am', message);
}
});
}