diff options
author | Jiachen Yang <farseerfc@gmail.com> | 2017-11-01 20:05:55 +0900 |
---|---|---|
committer | GDR! <gdr@gdr.name> | 2017-11-01 14:06:56 +0100 |
commit | b8c2242cafe33bda19c9774e2584be7508cb35f0 (patch) | |
tree | d885b599e9a43e38f6e92a4e5bbba0b1fce35b68 | |
parent | 44a23bb83ced58f9bf9e4368c507a5af0113ba48 (diff) |
pre-push hook to check gitversion.h against tag
As discussed in #35
-rwxr-xr-x | scripts/pre-push.sh | 27 |
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 | |||
6 | VERSIONFILE="gitversion.h" | ||
7 | BRANCH="HEAD" | ||
8 | |||
9 | tagref=$(grep -Po 'refs/tags/([^ ]*) ' </dev/stdin | head -n1 | cut -c11- | tr -d '[:space:]') | ||
10 | |||
11 | if [[ "$tagref" == "" ]]; then | ||
12 | ## pushing without --tags , exit normally | ||
13 | exit 0 | ||
14 | fi | ||
15 | |||
16 | ## versionline may looks like '#define GITVERSION "0.0.8"' | ||
17 | versionline=$(git cat-file blob $BRANCH:"$VERSIONFILE" | grep 'GITVERSION') | ||
18 | ver=$(echo "$versionline" | sed 's/^[^"]*"//;s/"[^"]*$//') | ||
19 | |||
20 | if [[ "$tagref" == "$ver" ]]; then | ||
21 | ## tag matches ver | ||
22 | exit 0 | ||
23 | fi | ||
24 | echo "Tag name don't match version file. Preventing push." | ||
25 | echo "tag name: $tagref" | ||
26 | echo "version: $ver" | ||
27 | exit 1 | ||