Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

branch-name

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

branch-name - npm Package Compare versions

Comparing version 0.1.4 to 0.1.5

README.md

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"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc