all files / src/git/ commit.js

100% Statements 3/3
71.43% Branches 5/7
100% Functions 3/3
100% Lines 3/3
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 os from 'os';
import {exec} from 'child_process';
 
import dedent from 'dedent';
import {isString} from '../common/util';
 
export { commit };
 
function normalizeCommitMessage(message) {
  const signs = os.platform() === 'win32' ?
    /(")/g :
    /(["|`])/g;
 
  return dedent(message)
    .replace(signs, '\\$1')
    .split(/\r?\n/)
    .map(line => `-m "${line}"`)
    .join(' ');
}
 
/**
 * Asynchronously git commit at a given path with a message
 */
function commit(sh, repoPath, message, options, done) {
  let args = options.args || '';
  let commitMessage = normalizeCommitMessage(message);
 
  exec(`git commit ${commitMessage} ${args}`, {
    maxBuffer: Infinity,
    cwd: repoPath,
    stdio: options.quiet ? 'ignore' : 'inherit'
  }, function(error, stdout, stderror) {
    Iif (error) {
      return done(error);
    }
    done();
  });
}