Fix tags and short_refname assignment.
[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 case "$refname" in
12         refs/tags/*)
13                 short_refname=${refname##refs/tags/}
14                 ;;
15         *)
16                 exit 0
17                 ;;
18 esac
19
20 # Except if they're getting deleted
21 if [ "$newrev" == "0000000000000000000000000000000000000000" ] ; then
22         exit 0
23 fi
24
25 contains=$(git branch --contains "$newrev" | wc -l)
26 if [ $contains -eq 0 ] ; then
27         echo "----------------------------------------------------"
28         echo
29         echo "The tag $short_refname is not included in any branch."
30         echo
31         echo "----------------------------------------------------"
32         exit 1
33 fi
34