chore: move getCurrentBranch to a util file (#15921)

* chore: move getCurrentBranch to a util file

* fix import
This commit is contained in:
Shelley Vohr 2018-12-03 13:28:10 -08:00 committed by GitHub
parent a1a431eb87
commit d3c58ea48c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 53 deletions

View file

@ -1,7 +1,12 @@
const OUT_DIR = process.env.ELECTRON_OUT_DIR || 'Debug'
const { GitProcess } = require('dugite')
const path = require('path')
require('colors')
const pass = '\u2713'.green
const fail = '\u2717'.red
function getElectronExec () {
switch (process.platform) {
case 'darwin':
@ -19,7 +24,22 @@ function getAbsoluteElectronExec () {
return path.resolve(__dirname, '../../..', getElectronExec())
}
async function getCurrentBranch (gitDir) {
const gitArgs = ['rev-parse', '--abbrev-ref', 'HEAD']
const branchDetails = await GitProcess.exec(gitArgs, gitDir)
if (branchDetails.exitCode === 0) {
const currentBranch = branchDetails.stdout.trim()
console.log(`${pass} current git branch is: ${currentBranch}`)
return currentBranch
} else {
const error = GitProcess.parseError(branchDetails.stderr)
console.log(`${fail} couldn't get details current branch: `, error)
process.exit(1)
}
}
module.exports = {
getCurrentBranch,
getElectronExec,
getAbsoluteElectronExec,
OUT_DIR