-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommit.ts
41 lines (36 loc) · 966 Bytes
/
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
40
import exec from './exec'
export default function commit(msg) {
const args = prepareMessageArgs(msg)
args.unshift(
'--allow-empty',
'--no-gpg-sign',
'--no-verify'
)
return exec(`git commit ${args.join(' ')}`)
}
function prepareMessageArgs(msg) {
const args = []
if (Array.isArray(msg)) {
if (msg.length > 0) {
for (const m of msg) {
args.push('-m', fixMessage(m))
}
} else {
args.push('-m', fixMessage())
}
} else {
args.push('-m', fixMessage(msg))
}
return args
}
function fixMessage(msg?: string) {
if (!msg || typeof msg !== 'string') {
msg = 'Test commit'
}
// we need to escape backtick for bash but not for windows
// probably this should be done in git-dummy-commit or shelljs
if (process.platform !== 'win32') {
msg = msg.replace(/`/g, '\\`')
}
return `"${msg}"`
}