Skip to content

Commit

Permalink
pre-push hook to check gitversion.h against tag
Browse files Browse the repository at this point in the history
As discussed in #35
  • Loading branch information
farseerfc authored and gjedeer committed Nov 1, 2017
1 parent 44a23bb commit b8c2242
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions scripts/pre-push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

## hook to check version match tag before push
## usage: ln -s ../../scripts/pre-push.sh .git/hooks/pre-push

VERSIONFILE="gitversion.h"
BRANCH="HEAD"

tagref=$(grep -Po 'refs/tags/([^ ]*) ' </dev/stdin | head -n1 | cut -c11- | tr -d '[:space:]')

if [[ "$tagref" == "" ]]; then
## pushing without --tags , exit normally
exit 0
fi

## versionline may looks like '#define GITVERSION "0.0.8"'
versionline=$(git cat-file blob $BRANCH:"$VERSIONFILE" | grep 'GITVERSION')
ver=$(echo "$versionline" | sed 's/^[^"]*"//;s/"[^"]*$//')

if [[ "$tagref" == "$ver" ]]; then
## tag matches ver
exit 0
fi
echo "Tag name don't match version file. Preventing push."
echo "tag name: $tagref"
echo "version: $ver"
exit 1

0 comments on commit b8c2242

Please sign in to comment.