Skip to content

Commit e53ccef

Browse files
committed
Add resource to check the current git state before versioning
1 parent e06420e commit e53ccef

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"watch": "babel resources/watch.js | node",
3535
"cover": "babel-node node_modules/.bin/isparta cover --root src --report html node_modules/.bin/_mocha -- $npm_package_options_mocha",
3636
"cover:lcov": "babel-node node_modules/.bin/isparta cover --root src --report lcovonly node_modules/.bin/_mocha -- $npm_package_options_mocha",
37-
"preversion": "npm test",
37+
"preversion": ". ./resources/checkgit.sh && npm test",
3838
"prepublish": ". ./resources/prepublish.sh"
3939
},
4040
"dependencies": {

resources/checkgit.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#
2+
# This script determines if current git state is the up to date master. If so
3+
# it exits normally. If not it prompts for an explicit continue. This script
4+
# intends to protect from versioning for NPM without first pushing changes
5+
# and including any changes on master.
6+
#
7+
8+
# First fetch to ensure git is up to date. Fail-fast if this fails.
9+
git fetch;
10+
if [[ $? -ne 0 ]]; then exit 1; fi;
11+
12+
# Extract useful information.
13+
GITBRANCH=$(git branch -v 2> /dev/null | sed '/^[^*]/d');
14+
GITBRANCHNAME=$(echo "$GITBRANCH" | sed 's/* \([A-Za-z0-9_\-]*\).*/\1/');
15+
GITBRANCHSYNC=$(echo "$GITBRANCH" | sed 's/* [^[]*.\([^]]*\).*/\1/');
16+
17+
# Check if master is checked out
18+
if [ "$GITBRANCHNAME" != "master" ]; then
19+
read -p "Git not on master but $GITBRANCHNAME. Continue? (y|N) " yn;
20+
if [ "$yn" != "y" ]; then exit 1; fi;
21+
fi;
22+
23+
# Check if branch is synced with remote
24+
if [ "$GITBRANCHSYNC" != "" ]; then
25+
read -p "Git not up to date but $GITBRANCHSYNC. Continue? (y|N) " yn;
26+
if [ "$yn" != "y" ]; then exit 1; fi;
27+
fi;

0 commit comments

Comments
 (0)