12 # topic1 stable result
13 # D A contains, merge base=A
14 # D C contains, merge base=A
15 # E A contains, merge base=E
16 # E C contains, merge base=A
19 # * --- * --------- * stable
21 # | A --- B ---- C topic1
23 # D --- E --- F topic2
25 # F: contains=topic1,topic2
28 head=$(git rev-parse HEAD)
30 # Watch out for the very first commit in the repo because we use head^
31 # Hopefully we can optimize this away later.
32 git rev-parse --verify --quiet "$head^" >/dev/null
33 if [ $? -ne 0 ] ; then
38 contains=($(git branch -r --contains $head))
39 if [ ${#contains[@]} -eq 0 ] ; then
40 echo "$head has not been pushed"
45 for branch in ${contains[@]} ; do
46 branch=${branch##origin/}
47 #echo "branch=$branch"
49 # Walk back until we hit a baserev that is not the branch_tip itself (because it was merged)
50 branch_tip=$(git rev-parse origin/$branch)
51 stable_rev=$(git rev-parse origin/stable)
52 stable_base=$(git merge-base "$branch_tip" "$stable_rev")
54 # echo "stable_base=$stable_base"
55 while [ "$stable_base" == "$branch_tip" ] ; do
56 stable_rev=$(git rev-parse "${stable_rev}^")
57 stable_base=$(git merge-base "$branch_tip" "$stable_rev")
59 # echo "stable_base=$stable_base"
61 git rev-list --first-parent $stable_base..$branch_tip | grep --quiet "$head"
62 if [ $? -eq 0 ] ; then
63 if [ "$branch" == "stable" ] ; then
64 describe=$(git describe $head 2>/dev/null)
65 if [ $? -eq 0 ] ; then
66 potential="$potential $describe"
68 potential="$potential stable-$head"
71 number=$(git rev-list --first-parent "$stable_base..$head" | wc -l)
72 potential="$potential $branch-$number"
77 potential=($potential)
78 if [ ${#potential[@]} -eq 1 ] ; then
79 echo "${potential[0]}"