Remove the server-/client- prefixes in the tests.
[git-central.git] / server / update-ensure-merged
1 #!/bin/sh
2
3 #
4 # When tagging the candidate branch, and commit "A"
5 # has gone onto a topic branch that we previously
6 # merged, reject the tag.
7 #
8 # * -- * -- * -- A   topic A
9 #  \        \
10 #   * -- *           topic B
11 #          \ \
12 #            *       candidate
13 #
14 # We want to detect A when trying to tag candidate.
15 #
16 # This also implements candidate protection, e.g.
17 # only merges are allowed on candidate branches.
18
19 # Command line
20 refname="$1"
21 oldrev="$2"
22 newrev="$3"
23
24 echo "updating $refname $oldrev $newrev"
25 fail=0
26
27 case "$refname" in
28         refs/tags/*)
29                 # First make sure stable hasn't moved on us
30                 baserev=$(git merge-base stable $newrev)
31                 stablerev=$(git rev-parse stable)
32                 if [ "$baserev" != "$stablerev" ] ; then
33                         echo "----------------------------------------------------"
34                         echo
35                         echo " Rejecting $refname because you need to merge:"
36                         echo
37                         git rev-list "$baserev..$stablerev" | xargs git name-rev
38                         echo
39                         echo "----------------------------------------------------"
40                         fail=1
41                 else
42
43                         # Now go back to stable and iterate through looking for commits on
44                         # our merge parents that are not within us
45                         git rev-list --first-parent "stable..$newrev" | while read commit ; do
46                                 number_of_parents=$(git rev-list -n 1 --parents $commit | sed 's/ /\n/g' | grep -v $commit | wc -l)
47                                 if [[ $number_of_parents > 1 ]] ; then
48                                         # For each parent
49                                         git rev-list --no-walk --parents $commit | sed 's/ /\n/g' | grep -v $commit | while read parent ; do
50                                                 # Does this parent have any children besides us?
51                                                 #
52                                                 # List the parents of all branch commits (after stable/parent), find
53                                                 # those that include our parent, get their sha1, remove our merge
54                                                 git rev-list --parents --branches ^stable "^$parent" | grep $parent | gawk '{print $1}' | grep -v $commit | while read child ; do
55                                                         number_missing=$(git rev-list "$child" "^$newrev" | wc -l)
56                                                         if [[ $number_missing > 0 ]] ; then
57                                                                 echo "----------------------------------------------------"
58                                                                 echo
59                                                                 echo " Rejecting $refname because you need to merge:"
60                                                                 echo
61                                                                 git rev-list "$child" "^$newrev" | xargs git name-rev
62                                                                 echo
63                                                                 echo "----------------------------------------------------"
64                                                                 fail=1
65                                                         fi
66                                                 done
67
68                                                 # Find any commits in the parent (and another branch) but not us--that means we need it
69                                                 # number_missing=$(git rev-list "$parent" --all "^$newrev" | wc -l)
70                                                 # if [[ $number_missing > 0 ]] ; then
71                                                 #       echo "----------------------------------------------------"
72                                                 #       echo
73                                                 #       echo " Rejecting $refname because you need to merge:"
74                                                 #       echo
75                                                 #       git rev-list "$parent" --all "^$newrev" | xargs git name-rev
76                                                 #       echo
77                                                 #       echo "----------------------------------------------------"
78                                                 #       exit 1
79                                                 # fi
80                                         done
81                                 fi
82                         done
83
84                 fi
85                 ;;
86
87         refs/heads/candidate*)
88                 # Look at commits between stable and us--ignoring those brought in by merges
89                 git rev-list --first-parent "$newrev" ^stable | while read commit ; do
90                         number_of_parents=$(git rev-list -n 1 --parents $commit | sed 's/ /\n/g' | grep -v $commit | wc -l)
91                         if [[ $number_of_parents == 1 ]] ; then
92                                 echo "----------------------------------------------------"
93                                 echo
94                                 echo " Candidate branches must be only merges"
95                                 echo
96                                 echo "----------------------------------------------------"
97                                 fail=1
98                         fi
99                 done
100                 ;;
101
102         *)
103                 ;;
104 esac
105
106 exit "$fail"
107