Simple CLI utility to test git output and return exit 1 if a test fails
npm install -g git-test-cli
[master] > git-test -b master && echo on master || echo not on master
on master
[master] > git checkout feature
[feature] > git-test -b master && echo on master || echo not on master
not on master
The intended use is as a scripting helper, e.g. to perform certain actions during automated processes (such as builds) based on the current git branch. For example, using husky, the following will run tests before pushing code to master:
{
"scripts": {
"prepush": "git-test -b master && npm test || git-test -x -b master"
}
}
The -x
option inverts the result of the test, e.g. tests that the branch is not master. The negative test following the || is needed to ensure the logic following the initial test is atomic. That is, every logical test that starts with the assertion "if I'm on this branch" should end with an "or" condition of "if I'm not on this branch".
Right now it's only feature is to test which branch is active. If I need more... I will add it.
Test that the current git repo is on [branch-name]
Invert the result of every other test
Show help
Just output the status info I obtained from git as JSON (for diagnostics)