268bfae3f5eee908f1f59072c15897798092c80c
[git-central.git] / server / update-ensure-tag-in-branch
1 #!/bin/sh
2 #
3 # Tags should only be allowed to point to commits that are within a branch.
4 #
5
6 refname="$1"
7 oldrev="$2"
8 newrev="$3"
9
10 # Only interested in tags
11 if [[ "$refname" =~ refs/tags/(.*) ]] ; then
12         short_refname=${BASH_REMATCH[1]}
13 else
14         exit 0
15 fi
16
17 # Except if they're getting deleted
18 if [ "$newrev" == "0000000000000000000000000000000000000000" ] ; then
19         exit 0
20 fi
21
22 contains=$(git branch --contains "$newrev" | wc -l)
23 if [ $contains -eq 0 ] ; then
24         echo "----------------------------------------------------"
25         echo
26         echo "The tag $short_refname is not included in any branch."
27         echo
28         echo "----------------------------------------------------"
29         exit 1
30 fi
31