Don't let in tags that are not within a branch.
[git-central.git] / server / update-ensure-tag-in-branch
diff --git a/server/update-ensure-tag-in-branch b/server/update-ensure-tag-in-branch
new file mode 100644 (file)
index 0000000..268bfae
--- /dev/null
@@ -0,0 +1,31 @@
+#!/bin/sh
+#
+# Tags should only be allowed to point to commits that are within a branch.
+#
+
+refname="$1"
+oldrev="$2"
+newrev="$3"
+
+# Only interested in tags
+if [[ "$refname" =~ refs/tags/(.*) ]] ; then
+       short_refname=${BASH_REMATCH[1]}
+else
+       exit 0
+fi
+
+# Except if they're getting deleted
+if [ "$newrev" == "0000000000000000000000000000000000000000" ] ; then
+       exit 0
+fi
+
+contains=$(git branch --contains "$newrev" | wc -l)
+if [ $contains -eq 0 ] ; then
+       echo "----------------------------------------------------"
+       echo
+       echo "The tag $short_refname is not included in any branch."
+       echo
+       echo "----------------------------------------------------"
+       exit 1
+fi
+