diff --git a/enable_hooks.sh b/enable_hooks.sh new file mode 100755 index 0000000000..ddffeda24b --- /dev/null +++ b/enable_hooks.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +echo "Enabling Hooks" +git config core.hooksPath git/hooks diff --git a/git/hooks/pre-push b/git/hooks/pre-push new file mode 100755 index 0000000000..c990ae16dc --- /dev/null +++ b/git/hooks/pre-push @@ -0,0 +1,25 @@ +#!/bin/sh + +# read inputs passed by pre-push +while read -r _local_ref _local_sha remote_ref _remote_sha +do + case "$remote_ref" in + refs/tags/*) + tag_version="${remote_ref#refs/tags/mc*?-}" + mod_version=$(sed -n 's/.*MOD_VERSION: String = "\(.*\)"/\1/p' buildSrc/src/main/kotlin/BuildConfig.kt) + + # check if either local branch is dirty or if there's a tag mismatch + if [ -n "$(git status --porcelain)" ]; then + echo "Local branch is dirty, please commit your changes or stash them before trying to push a tag" + exit 1 + elif [ "$tag_version" != "$mod_version" ]; then + echo "Tag version and Mod version does not match! Did you forget to update the mod version?" + echo "Tag version : $tag_version" + echo "Mod version : $mod_version" + exit 1 + fi + ;; + esac +done + +exit 0 \ No newline at end of file