Gathering detailed insights and metrics for git-branch-is
Gathering detailed insights and metrics for git-branch-is
Gathering detailed insights and metrics for git-branch-is
Gathering detailed insights and metrics for git-branch-is
npm install git-branch-is
Typescript
Module System
Min. Node Version
Node Version
NPM Version
98
Supply Chain
100
Quality
75.5
Maintenance
100
Vulnerability
100
License
JavaScript (89.78%)
HTML (6.04%)
Shell (4.18%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
7,482,894
Last Day
6,104
Last Week
32,314
Last Month
133,183
Last Year
1,599,114
MIT License
96 Stars
558 Commits
9 Forks
2 Watchers
7 Branches
2 Contributors
Updated on Nov 02, 2024
Minified
Minified + Gzipped
Latest Version
4.0.0
Package Id
git-branch-is@4.0.0
Unpacked Size
23.60 kB
Size
7.72 kB
File Count
6
NPM Version
6.14.7
Node Version
10.21.0
Cumulative downloads
Total Downloads
Last Day
3.5%
6,104
Compared to previous day
Last Week
15.4%
32,314
Compared to previous week
Last Month
22.7%
133,183
Compared to previous month
Last Year
-1.9%
1,599,114
Compared to previous year
git-branch-is
Assert that the name of the current branch of a git repository has a particular value.
To check that the current branch is named release
and print an error if not,
run the following command:
$ git-branch-is release
Error: Current branch is "master", not "release".
$ echo $?
1
This can be useful as part of a preversion
script in package.json
:
1{ 2 "name": "super-cool-package", 3 "version": "1.2.3", 4 "scripts": { 5 "preversion": "git-branch-is release && echo Preversion checks passed." 6 } 7}
This package can be installed using npm, either globally or locally, by running:
1npm install git-branch-is
The command options are intended to be similar to git
and are documented in
the --help
output:
Usage: git-branch-is [options] <branch name>
Options:
-C <path> run as if started in <path>
--git-arg <arg> additional argument to git (can be repeated) (default: [])
--git-dir <dir> set the path to the repository
--git-path <path> set the path to the git binary
-i, --ignore-case compare/match branch name case-insensitively
-I, --invert-match inverts/negates comparison
--not inverts/negates comparison (same as --invert-match)
-q, --quiet suppress warning message if branch differs
-r, --regex match <branch name> as a regular expression
-v, --verbose print a message if the branch matches
-V, --version output the version number
-h, --help output usage information
To check that the current branch starts with release/
using a regular
expression:
$ git-branch-is -r "^release/"
Error: Current branch "master" does not match "^release/".
$ echo $?
1
Note: Be careful to quote patterns to avoid shell expansion or special
handling (e.g. POSIX shells expand *
and cmd.exe
treats ^
specially).
To check that the current branch starts with release/
case-insensitively
using a regular expression:
$ git-branch-is -i -r "^release/"
Error: Current branch "master" does not match "^release/".
$ echo $?
1
To check that the current branch is not master
, use -I
, --invert-match
,
or --not
(all functionally equivalent, use whichever you prefer):
$ git-branch-is --not master
Error: Current branch is "master".
$ echo $?
1
To use the API with a callback function:
1var gitBranchIs = require('git-branch-is'); 2gitBranchIs('master', function(err, result) { 3 if (err) console.error(err); 4 else console.log(result ? 'On master' : 'Not on master'); 5});
Alternatively, if a callback is not provided, gitBranchIs
will return a
Promise
:
1var gitBranchIs = require('git-branch-is'); 2gitBranchIs('master').then( 3 function(result) { console.log(result ? 'On master' : 'Not on master'); }, 4 function(err) { console.error(err); } 5);
Additionally, instead of a string, a checking function can be passed to perform arbitrary checking against the branch name:
1var gitBranchIs = require('git-branch-is'); 2gitBranchIs(function(branchName) { /^master$/.test(branchName); }).then( 3 function(result) { console.log(result ? 'On master' : 'Not on master'); }, 4 function(err) { console.error(err); } 5);
To use this module as a library, see the API Documentation.
What's the value of this command over scripting with git
directly? Good
question. The Introductory Example could instead be
approximated with the following:
1{ 2 "name": "super-cool-package", 3 "version": "1.2.3", 4 "scripts": { 5 "preversion": "if [ \"$(git symbolic-ref HEAD)\" = release ] ; then echo Preversion checks passed. ; else echo Error: Not on branch release. ; exit 1 ; fi" 6 } 7}
For packages which are only targeting POSIX systems, this may be a preferable
solution. However, it doesn't work on systems which don't support the POSIX
shell language (e.g. Windows, which runs scripts in cmd.exe
). To support
these systems it is necessary to either introduce a dependency on Bash, to
use this script, or code up something else.
Contributions are appreciated. Contributors agree to abide by the Contributor Covenant Code of Conduct. If this is your first time contributing to a Free and Open Source Software project, consider reading How to Contribute to Open Source in the Open Source Guides.
If the desired change is large, complex, backwards-incompatible, can have significantly differing implementations, or may not be in scope for this project, opening an issue before writing the code can avoid frustration and save a lot of time and effort.
This project is available under the terms of the MIT License. See the summary at TLDRLegal.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/21 approved changesets -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-02-10
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More