Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix detached #8

Merged
merged 11 commits into from
Jun 19, 2018
Merged
9 changes: 7 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function loadConfig () {

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be let not var


if (!branch || _.includes(branch, 'fatal:')) {
return
Expand All @@ -71,10 +71,15 @@ function getEnvIdFromBranch () {
branch = branch.replace(new RegExp(_.trim(config.branchRegex)), '$1')
}

return _.trimEnd(_.truncate(branch, {
branch = _.trimEnd(_.truncate(branch, {
length: 13,
omission: ''
}), '-')

var hash = sh.exec('git rev-parse HEAD').stdout
hash = hash.substring(0, 5)

return (branch.includes(' ')) ? hash : branch
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the branch includes spaces, I would prefer to replace them with dashes than to use the hash. the hash is not user friendly

} catch (e) {
console.log('ERR: ', e)
// Do nothing
Expand Down
5 changes: 4 additions & 1 deletion test/_env.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ module.exports = function (regex) {
omission: ''
}) : undefined

return env
var hash = sh.exec('git rev-parse HEAD').stdout
hash = hash.substring(0, 5)

return (env.includes(' ')) ? hash : env
}