/
commit.js
56 lines (49 loc) · 1.75 KB
/
commit.js
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
46
47
48
49
50
51
52
53
54
55
56
const bump = require('../lifecycles/bump')
const checkpoint = require('../checkpoint')
const formatCommitMessage = require('../format-commit-message')
const path = require('path')
const runExec = require('../run-exec')
const runLifecycleScript = require('../run-lifecycle-script')
module.exports = function (args, newVersion) {
if (args.skip.commit) return Promise.resolve()
return runLifecycleScript(args, 'precommit')
.then((message) => {
if (message && message.length) args.message = message
return execCommit(args, newVersion)
})
.then(() => {
return runLifecycleScript(args, 'postcommit')
})
}
function execCommit (args, newVersion) {
var msg = 'committing %s'
var paths = []
var toAdd = ''
// only start with a pre-populated paths list when CHANGELOG processing is not skipped
if (!args.skip.changelog) {
paths = [args.infile]
toAdd += args.infile
}
var verify = args.verify === false || args.n ? '--no-verify ' : ''
// commit any of the config files that we've updated
// the version # for.
Object.keys(bump.getUpdatedConfigs()).forEach(function (p) {
if (bump.getUpdatedConfigs()[p]) {
paths.unshift(path.basename(p))
toAdd += ' ' + path.relative(process.cwd(), p)
// account for multiple files in the output message
if (paths.length > 1) {
msg += ' and %s'
}
}
})
checkpoint(args, msg, paths)
if (args.skip.changelog && args.skip.bump && toAdd.length === 0) {
// nothing to do
return Promise.resolve()
}
return runExec(args, 'git add' + toAdd)
.then(() => {
return runExec(args, 'git commit ' + verify + (args.sign ? '-S ' : '') + (args.commitAll ? '' : (toAdd)) + ' -m "' + formatCommitMessage(args.message, newVersion) + '"')
})
}