forked from commitizen/cz-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommit.js
More file actions
45 lines (37 loc) · 1.05 KB
/
Copy pathcommit.js
File metadata and controls
45 lines (37 loc) · 1.05 KB
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
45
import os from 'os';
import {spawn} from 'child_process';
import dedent from 'dedent';
import {isString} from '../common/util';
export { commit };
/**
* Asynchronously git commit at a given path with a message
*/
function commit (sh, repoPath, message, options, done) {
let called = false;
let args = ['commit', '-m', dedent(message), ...(options.args || [])];
let child = spawn('git', args, {
cwd: repoPath,
stdio: options.quiet ? 'ignore' : 'inherit'
});
child.on('error', function (err) {
if (called) return;
called = true;
done(err);
});
child.on('exit', function (code, signal) {
if (called) return;
called = true;
if (code) {
if (code === 128) {
console.warn(`
Git exited with code 128. Did you forget to run:
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
`)
}
done(Object.assign(new Error(`git exited with error code ${code}`), { code, signal }));
} else {
done(null);
}
});
}