From 6e507af2346a3767bbcf42276ef3001f1868af5b Mon Sep 17 00:00:00 2001 From: lukechampine Date: Thu, 6 Feb 2020 15:46:44 -0500 Subject: [PATCH] git: Add pre-push hook for catching accidental versions --- pre-push.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100755 pre-push.sh diff --git a/pre-push.sh b/pre-push.sh new file mode 100755 index 0000000..5d0e487 --- /dev/null +++ b/pre-push.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# A pre-push hook to prevent accidentally pushing new major versions. + +vs="$(git tag | sort -rV | cut -c 1,2 | head -n 2)" +if [[ "$(echo "$vs" | wc -l | awk '{print $1}')" == "2" ]] && [[ -z $(echo "$vs" | uniq -d) ]]; then + echo >&2 "It looks like you're pushing a tag with a new major version!" + echo >&2 "...I'm gonna assume that was a mistake." + echo >&2 "If it wasn't, just rm this hook before pushing again." + exit 1; +fi