7ad1e5455ef4d374a6a0e098d727a890ff51a9d9
[git-central.git] / scripts / gc-tattoo
1 #!/bin/sh
2
3 head=$(git rev-parse HEAD)
4 branch=$(git symbolic-ref --quiet HEAD)
5 if [ $? -ne 0 ] ; then
6         echo "unknown"
7         exit 1
8 fi
9
10 case "$branch" in
11         refs/heads/*)
12                 branch=${branch##refs/heads/}
13                 ;;
14         *)
15                 echo "unknown"
16                 exit 1
17                 ;;
18 esac
19
20 # Ensure pushed
21 git branch -r --contains $head | grep --quiet "origin/$branch"
22 if [ $? -ne 0 ] ; then
23         echo "$branch has not been pushed"
24         exit 1
25 fi
26
27 # Handle stable special to look for the annotated tag
28 if [ "$branch" == "stable" ] ; then
29         describe=$(git describe $head 2>/dev/null)
30         if [ $? -eq 0 ] ; then
31                 echo "$describe"
32         else
33                 echo "stable-$head"
34         fi
35         exit 0
36 fi
37
38 number=$(git rev-list --first-parent "$head" ^origin/stable | wc -l)
39 echo "$branch-$number"
40