Skip to content

Commit

Permalink
Fix detached (#8)
Browse files Browse the repository at this point in the history
* Fixing it so that detached head displays the hash instead

* fixing ternary operator

* formatting

* destroy last semicolon

* attach head, please use hash

* get test to reflect the hash changes

* changing var to let

* Changing method of retrieving branch name to git name-rev HEAD --name-only

* getting test to reflect envid changes

* removing trailing space

* returning directly
  • Loading branch information
jollyromp authored and andyday committed Jun 19, 2018
1 parent 6773e2d commit 4bfeb91
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 19 deletions.
13 changes: 1 addition & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,7 @@ function loadConfig () {

function getEnvIdFromBranch () {
try {
let branch = sh.exec('git status', { silent: true }).stdout

if (!branch || _.includes(branch, 'fatal:')) {
return
}

branch = branch.split('\n')[0]
branch = branch.replace(/^#?\s?On branch ((\w|-|_|\/|.)+)/, '$1')

if (config.branchRegex) {
branch = branch.replace(new RegExp(_.trim(config.branchRegex)), '$1')
}
let branch = sh.exec('git name-rev HEAD --name-only').stdout

return _.trimEnd(_.truncate(branch, {
length: 13,
Expand Down
9 changes: 2 additions & 7 deletions test/_env.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,10 @@ const _ = require('lodash')
const sh = require('shelljs')

module.exports = function (regex) {
var env = sh.exec('git status', { silent: true }).stdout
env = env.split('\n')[0]
env = env.replace(/^#?\s?On branch ([\w-_/.]+)/, '$1')
env = regex ? env.replace(/\w(\w+)\w/, '$1') : env
var env = sh.exec('git name-rev HEAD --name-only').stdout

env = env ? _.truncate(env, {
return env ? _.truncate(env, {
length: 13,
omission: ''
}) : undefined

return env
}

0 comments on commit 4bfeb91

Please sign in to comment.