1 | const bump = require('../lifecycles/bump')
|
2 | const checkpoint = require('../checkpoint')
|
3 | const formatCommitMessage = require('../format-commit-message')
|
4 | const path = require('path')
|
5 | const runExec = require('../run-exec')
|
6 | const runLifecycleScript = require('../run-lifecycle-script')
|
7 |
|
8 | module.exports = function (args, newVersion) {
|
9 | if (args.skip.commit) return Promise.resolve()
|
10 | return runLifecycleScript(args, 'precommit')
|
11 | .then((message) => {
|
12 | if (message && message.length) args.message = message
|
13 | return execCommit(args, newVersion)
|
14 | })
|
15 | .then(() => {
|
16 | return runLifecycleScript(args, 'postcommit')
|
17 | })
|
18 | }
|
19 |
|
20 | function execCommit (args, newVersion) {
|
21 | let msg = 'committing %s'
|
22 | let paths = [args.infile]
|
23 | let verify = args.verify === false || args.n ? '--no-verify ' : ''
|
24 | let toAdd = ''
|
25 |
|
26 |
|
27 | Object.keys(bump.getUpdatedConfigs()).forEach(function (p) {
|
28 | if (bump.getUpdatedConfigs()[p]) {
|
29 | msg += ' and %s'
|
30 | paths.unshift(path.basename(p))
|
31 | toAdd += ' ' + path.relative(process.cwd(), p)
|
32 | }
|
33 | })
|
34 |
|
35 | if (args.commitAll) {
|
36 | msg += ' and %s'
|
37 | paths.push('all staged files')
|
38 | }
|
39 |
|
40 | checkpoint(args, msg, paths)
|
41 | return runExec(args, 'git add' + toAdd + ' ' + args.infile)
|
42 | .then(() => {
|
43 | return runExec(args, 'git commit ' + verify + (args.sign ? '-S ' : '') + (args.commitAll ? '' : (args.infile + toAdd)) + ' -m "' + formatCommitMessage(args.message, newVersion) + '"')
|
44 | })
|
45 | }
|