UNPKG

572 BJavaScriptView Raw
1var la = require('lazy-ass')
2var check = require('check-more-types')
3var exec = require('./exec')
4
5/*
6 Returns the branch name
7*/
8function branchName () {
9 var cmd = 'git rev-parse --abbrev-ref HEAD'
10 return exec(cmd).then(function cleanOutput (str) {
11 la(check.unemptyString(str), 'expected branch name string', str)
12 return str.trim()
13 })
14}
15
16module.exports = branchName
17
18if (!module.parent) {
19 ;(function tryBranchName () {
20 branchName()
21 .then(function (name) {
22 console.log('Current branch name is "%s"', name)
23 })
24 .done()
25 })()
26}