all files / heroku-git/lib/ git.js

95.45% Statements 21/22
75% Branches 3/4
90.91% Functions 10/11
100% Lines 21/21
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                                                 
'use strict'
 
let child_process = require('child_process')
 
module.exports = function (context) {
  function exec (args) {
    return new Promise(function (resolve, reject) {
      child_process.execFile('git', args, function (error, stdout) {
        Iif (error) return reject(error)
        resolve(stdout.trim())
      })
    })
  }
 
  function spawn (args) {
    return new Promise(function (resolve, reject) {
      let s = child_process.spawn('git', args, {stdio: [0, 1, 2]})
      s.on('error', reject)
      s.on('close', resolve)
    })
  }
 
  function remoteFromGitConfig () {
    return exec(['config', 'heroku.remote']).catch(function () {})
  }
 
  function sshGitUrl (app) {
    return `git@${context.gitHost}:${app}.git`
  }
 
  function httpGitUrl (app) {
    return `https://${context.httpGitHost}/${app}.git`
  }
 
  function url (app, ssh) {
    return ssh ? sshGitUrl(app) : httpGitUrl(app)
  }
 
  return {
    exec,
    spawn,
    remoteFromGitConfig,
    url
  }
}