branch-name
Advanced tools
Comparing version 0.1.4 to 0.1.5
47
index.js
'use strict'; | ||
const | ||
execa = require('execa'), | ||
noBranchErrors = [ | ||
'Not a git repository', | ||
'ref HEAD is not a symbolic ref' | ||
]; | ||
const { exec } = require('child_process'); | ||
function getBranch() { | ||
return execa.shell('git symbolic-ref --short HEAD').then((data) => { | ||
return data.stdout; | ||
const get = () => { | ||
return new Promise((resolve, reject) => { | ||
exec('git symbolic-ref --short HEAD', (err, stdout, stderr) => { | ||
if (err) { | ||
err.stderr = stderr; | ||
reject(err); | ||
return; | ||
} | ||
resolve(stdout.trimRight()); | ||
}); | ||
}); | ||
} | ||
}; | ||
// Get the current branch name, unless one is not available, in which case | ||
// return the provided branch as a fallback. | ||
function assume(branchName) { | ||
return getBranch().catch((err) => { | ||
const assume = (assumedName) => { | ||
return get().catch((err) => { | ||
const problem = err.stderr.substring('fatal; '.length); | ||
// Strip off common "fatal: " prefix. | ||
const problem = err.stderr.substring(7); | ||
const noBranchErrors = [ | ||
'Not a git repository', | ||
'ref HEAD is not a symbolic ref' | ||
]; | ||
function matchProblem(scenario) { | ||
const matchProblem = (scenario) => { | ||
return problem.startsWith(scenario); | ||
} | ||
}; | ||
if (noBranchErrors.some(matchProblem)) { | ||
return branchName; | ||
return assumedName; | ||
} | ||
@@ -34,14 +39,14 @@ | ||
}); | ||
} | ||
}; | ||
// Master is a nice fallback assumption because it is | ||
// the default branch name in git. | ||
function assumeMaster() { | ||
const assumeMaster = () => { | ||
return assume('master'); | ||
} | ||
}; | ||
module.exports = { | ||
get : getBranch, | ||
get, | ||
assume, | ||
assumeMaster | ||
}; |
{ | ||
"name": "branch-name", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "Get the current branch name.", | ||
@@ -13,3 +13,3 @@ "homepage": "https://github.com/sholladay/branch-name", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "xo" | ||
}, | ||
@@ -24,2 +24,5 @@ "repository": { | ||
}, | ||
"engines": { | ||
"node": ">=6" | ||
}, | ||
"license": "MPL-2.0", | ||
@@ -29,4 +32,5 @@ "files": [ | ||
], | ||
"dependencies": { | ||
"execa": "0.2.2" | ||
"devDependencies": { | ||
"eslint-config-tidy": "0.3.0", | ||
"xo": "0.16.0" | ||
}, | ||
@@ -39,3 +43,6 @@ "keywords": [ | ||
"version" | ||
] | ||
], | ||
"xo": { | ||
"extend": "tidy" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
19968
0
4
42
1
0
65
2
1
- Removedexeca@0.2.2
- Removedcross-spawn-async@2.2.5(transitive)
- Removedexeca@0.2.2(transitive)
- Removedisexe@2.0.0(transitive)
- Removedlru-cache@4.1.5(transitive)
- Removednpm-run-path@1.0.0(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedpath-key@1.0.0(transitive)
- Removedpseudomap@1.0.2(transitive)
- Removedstrip-eof@1.0.0(transitive)
- Removedwhich@1.3.1(transitive)
- Removedyallist@2.1.2(transitive)