summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiachen Yang <farseerfc@gmail.com>2017-11-01 20:05:55 +0900
committerGDR! <gdr@gdr.name>2017-11-01 14:06:56 +0100
commitb8c2242cafe33bda19c9774e2584be7508cb35f0 (patch)
treed885b599e9a43e38f6e92a4e5bbba0b1fce35b68
parent44a23bb83ced58f9bf9e4368c507a5af0113ba48 (diff)
pre-push hook to check gitversion.h against tag
As discussed in #35
-rwxr-xr-xscripts/pre-push.sh27
1 files changed, 27 insertions, 0 deletions
diff --git a/scripts/pre-push.sh b/scripts/pre-push.sh
new file mode 100755
index 0000000..0ad3bbc
--- /dev/null
+++ b/scripts/pre-push.sh
@@ -0,0 +1,27 @@
1#!/bin/bash
2
3## hook to check version match tag before push
4## usage: ln -s ../../scripts/pre-push.sh .git/hooks/pre-push
5
6VERSIONFILE="gitversion.h"
7BRANCH="HEAD"
8
9tagref=$(grep -Po 'refs/tags/([^ ]*) ' </dev/stdin | head -n1 | cut -c11- | tr -d '[:space:]')
10
11if [[ "$tagref" == "" ]]; then
12 ## pushing without --tags , exit normally
13 exit 0
14fi
15
16## versionline may looks like '#define GITVERSION "0.0.8"'
17versionline=$(git cat-file blob $BRANCH:"$VERSIONFILE" | grep 'GITVERSION')
18ver=$(echo "$versionline" | sed 's/^[^"]*"//;s/"[^"]*$//')
19
20if [[ "$tagref" == "$ver" ]]; then
21 ## tag matches ver
22 exit 0
23fi
24echo "Tag name don't match version file. Preventing push."
25echo "tag name: $tagref"
26echo "version: $ver"
27exit 1