Fix update-stable for 0-commit branches.
[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 . $(dirname $0)/functions
7
8 refname="$1"
9 oldrev="$2"
10 newrev="$3"
11
12 # Only interested in tags
13 case "$refname" in
14         refs/tags/*)
15                 short_refname=${refname##refs/tags/}
16                 ;;
17         *)
18                 exit 0
19                 ;;
20 esac
21
22 # Except if they're getting deleted
23 if [ "$newrev" == "0000000000000000000000000000000000000000" ] ; then
24         exit 0
25 fi
26
27 contains=$(git branch --contains "$newrev" | wc -l)
28 if [ $contains -eq 0 ] ; then
29         display_error_message "The tag $short_refname is not included in any branch."
30         exit 1
31 fi
32