{"size": 2064, "ext": "js", "max_stars_repo_path": "lib/lifecycles/commit.js", "max_stars_repo_name": "runnerway/standard-version", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lib/lifecycles/commit.js", "max_issues_repo_name": "runnerway/standard-version", "max_issues_repo_issues_event_min_datetime": "2021-08-17T07:47:42.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-17T07:47:42.000Z", "max_forks_repo_path": "node_modules/standard-version/lib/lifecycles/commit.js", "max_forks_repo_name": "yarovojigor1988/custom-cjeckout-js", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 27.1578947368, "max_line_length": 88, "alphanum_fraction": 0.605620155}
const bump = require('../lifecycles/bump')
const checkpoint = require('../checkpoint')
const formatCommitMessage = require('../format-commit-message')
const path = require('path')
const runExecFile = require('../run-execFile')
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.releaseCommitMessageFormat = message
      return execCommit(args, newVersion)
    })
    .then(() => {
      return runLifecycleScript(args, 'postcommit')
    })
}

function execCommit (args, newVersion) {
  let msg = 'committing %s'
  let paths = []
  const verify = args.verify === false || args.n ? ['--no-verify'] : []
  const sign = args.sign ? ['-S'] : []
  const toAdd = []

  // only start with a pre-populated paths list when CHANGELOG processing is not skipped
  if (!args.skip.changelog) {
    paths = [args.infile]
    toAdd.push(args.infile)
  }

  // commit any of the config files that we've updated
  // the version # for.
  Object.keys(bump.getUpdatedConfigs()).forEach(function (p) {
    paths.unshift(p)
    toAdd.push(path.relative(process.cwd(), p))

    // account for multiple files in the output message
    if (paths.length > 1) {
      msg += ' and %s'
    }
  })

  if (args.commitAll) {
    msg += ' and %s'
    paths.push('all staged files')
  }

  checkpoint(args, msg, paths)

  // nothing to do, exit without commit anything
  if (args.skip.changelog && args.skip.bump && toAdd.length === 0) {
    return Promise.resolve()
  }

  return runExecFile(args, 'git', ['add'].concat(toAdd))
    .then(() => {
      return runExecFile(
        args,
        'git',
        [
          'commit'
        ].concat(
          verify,
          sign,
          args.commitAll ? [] : toAdd,
          [
            '-m',
            `"${formatCommitMessage(args.releaseCommitMessageFormat, newVersion)}"`
          ]
        )
      )
    })
}
