/
git-commit.ts
39 lines (32 loc) · 1.01 KB
/
git-commit.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
import { EOL } from 'os';
import log from 'npmlog';
import tempWrite from 'temp-write';
import { exec } from '@ws-conventional-version-roller/core';
/**
* @param {string} message
* @param {{ amend: boolean; commitHooks: boolean; signGitCommit: boolean; }} gitOpts
* @param {import('@lerna/child-process').ExecOpts} opts
*/
export function gitCommit(message, { amend, commitHooks, signGitCommit, signoffGitCommit }, opts, gitDryRun = false) {
log.silly('gitCommit', message);
const args = ['commit'];
if (commitHooks === false) {
args.push('--no-verify');
}
if (signGitCommit) {
args.push('--gpg-sign');
}
if (signoffGitCommit) {
args.push('--signoff');
}
if (amend) {
args.push('--amend', '--no-edit');
} else if (message.indexOf(EOL) > -1) {
// Use tempfile to allow multi\nline strings.
args.push('-F', tempWrite.sync(message, 'lerna-commit.txt'));
} else {
args.push('-m', message);
}
log.verbose('git', args.join(' '));
return exec('git', args, opts, gitDryRun);
}