-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-get-commit-id.ts
29 lines (24 loc) · 1014 Bytes
/
git-get-commit-id.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
import child_process = require('child_process');
import git = require('./git-get-commit-id.d');
export function getGitStatus(done: (error: Error, result: {is_clean: boolean, stdout: string, stderr: string}) => void): void {
var cmd = 'git status --porcelain'
child_process.exec(cmd, (error, stdout, stderr) => {
if (error) {
error.message = `FAILED ${cmd}\n${error.message}`
}
var is_clean = !((stdout.length > 0) || (stderr.length > 0))
done(error, {stdout, stderr, is_clean})
})
}
export function getGitCommitID(done: (error: Error, result: {id?: string, stdout: string, stderr: string}) => void): void {
var cmd = 'git rev-parse HEAD'
child_process.exec(cmd, (error, stdout, stderr) => {
if (stdout) {
var id = stdout.toString().trim()
}
if (error) {
error.message = `FAILED ${cmd}\n${error.message}`
}
done(error, {stdout, stderr, id})
})
}