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
17 changes: 4 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,14 @@ function loadConfig () {

function getEnvIdFromBranch () {
try {
let branch = sh.exec('git status', { silent: true }).stdout
let branch = sh.exec('git name-rev HEAD --name-only').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')
}

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

return branch
Copy link
Contributor

Choose a reason for hiding this comment

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

no need to have the separate variable. you can return at line 63 directly

} catch (e) {
console.log('ERR: ', e)
// Do nothing
Expand Down
5 changes: 1 addition & 4 deletions test/_env.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ 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, {
length: 13,
Expand Down