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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}