aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--update-hook.sh77
1 files changed, 77 insertions, 0 deletions
diff --git a/update-hook.sh b/update-hook.sh
new file mode 100644
index 0000000..ff4d20b
--- /dev/null
+++ b/update-hook.sh
@@ -0,0 +1,77 @@
+#!/bin/sh
+#
+# Update Hook to ensure the version code is increased in a new tag
+#
+
+# --- Command line
+refname="$1"
+oldrev="$2"
+newrev="$3"
+
+# --- Safety check
+if [ -z "$GIT_DIR" ]; then
+ echo "Don't run this script from the command line." >&2
+ echo " (if you want, you could supply GIT_DIR then run" >&2
+ echo " $0 <ref> <oldrev> <newrev>)" >&2
+ exit 1
+fi
+
+if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then
+ echo "usage: $0 <ref> <oldrev> <newrev>" >&2
+ exit 1
+fi
+
+# --- Check types
+# if $newrev is 0000...0000, it's a commit to delete a ref.
+zero="0000000000000000000000000000000000000000"
+if [ "$newrev" = "$zero" ]; then
+ newrev_type=delete
+else
+ newrev_type=$(git cat-file -t $newrev)
+fi
+
+case "$refname","$newrev_type" in
+ refs/tags/*,commit)
+ # un-annotated tag
+ oldVersionCode=`git archive $(git describe --tags) build.gradle | tar -xO | less - | grep versionCode | awk '{print $2}' 2> /dev/null`
+
+ if [[ "$oldVersionCode" =~ ^[0-9]+$ ]]
+ then
+ echo "*** Old version code is not an integer" >&2
+ exit 1
+ fi
+ newVersionCode=`git archive $newrev build.gradle | tar -xO | less - | grep versionCode | awk '{print $2}' 2> /dev/null`
+ if [[ "$newVersionCode" =~ ^[0-9]+$ ]]
+ then
+ echo "*** New version code is not an integer" >&2
+ exit 1
+ fi
+ if [ "$oldVersionCode" = "$newVersionCode" ]; then
+ echo "*** A new version code is needed to commit" >&2
+ exit 1
+ fi
+ ;;
+ refs/tags/*,tag)
+ # annotated tag
+ oldVersionCode=`git archive $(git describe --tags) build.gradle | tar -xO | less - | grep versionCode | awk '{print $2}' 2> /dev/null`
+
+ if [[ "$oldVersionCode" =~ ^[0-9]+$ ]]
+ then
+ echo "*** Old version code is not an integer" >&2
+ exit 1
+ fi
+ newVersionCode=`git archive $newrev build.gradle | tar -xO | less - | grep versionCode | awk '{print $2}' 2> /dev/null`
+ if [[ "$newVersionCode" =~ ^[0-9]+$ ]]
+ then
+ echo "*** New version code is not an integer" >&2
+ exit 1
+ fi
+ if [ "$oldVersionCode" = "$newVersionCode" ]; then
+ echo "*** A new version code is needed to commit" >&2
+ exit 1
+ fi
+ ;;
+esac
+
+# --- Finished
+exit 0 \ No newline at end of file