64f73699be03be147faf1f857bcf25dada0a532e
[git-central.git] / server / update-stable
1 #!/bin/sh
2
3 #
4 # This enforces stable only moving in the approved way, which
5 # is via empty (no change) merge commits. The rationale is that
6 # in the DAG we want a simple, one-commit move from each release
7 # to the next.
8 #
9 # We started out with:
10 #
11 # * -- A                stable
12 #  \    \
13 #   \    * -- * -- B    topic1
14 #    \           /
15 #     * -- * -- *       topic2
16 #
17 # And then publishing stable was a matter of fast-forwarding
18 # from A to B.
19 #
20 # In a complicated (non-rebased) DAG, this becomes hard to follow,
21 # so want we want instead is:
22 #
23 # * -- A ----------- C  stable
24 #  \    \           /
25 #   \    * -- * -- B    topic1
26 #    \           /
27 #     * -- * -- *       topic2
28 #
29 # Where commit C lists as it's first parent the prior stable
30 # commit and as it's second parent the release candidate. No
31 # other parents are allowed (e.g. no octopus merges here, which
32 # would insinuate qa didn't happen on the merged result).
33 #
34 # Also, we want to enforce that C does not actually introduce
35 # any diffs to the files between B and C--otherwise this changes
36 # would not have appeared in QA.
37 #
38
39 # Command line
40 refname="$1"
41 oldrev="$2"
42 newrev="$3"
43
44 if expr "$oldrev" : '0*$' >/dev/null ; then
45         exit 0
46 fi
47
48 if [ "$refname" != "refs/heads/stable" ] ; then
49         exit 0
50 fi
51
52 # read backwards:
53 # - all commits from old..new
54 # - unless they were already pointed to by a branch
55 # = all new commits on stable
56 count=$(git rev-parse --not --branches | git rev-list --stdin $oldrev..$newrev | wc -l)
57 if [ "$count" -ne "1" ] ; then
58         echo "----------------------------------------------------"
59         echo
60         echo "Moving stable must entail a single commit"
61         echo
62         echo "----------------------------------------------------"
63         exit 1
64 fi
65
66 number_of_parents=$(git rev-list --no-walk --parents $newrev | sed 's/ /\n/g' | grep -v $newrev | wc -l)
67 if [ "$number_of_parents" -ne "2" ] ; then
68         echo "----------------------------------------------------"
69         echo
70         echo "Moving stable must entail a merge commit"
71         echo
72         echo "----------------------------------------------------"
73         exit 1
74 fi
75
76 first_parent=$(git rev-list --no-walk --parents $newrev | sed 's/ /\n/g' | grep -v $newrev | head --lines=1)
77 if [ "$first_parent" != "$oldrev" ] ; then
78         echo "----------------------------------------------------"
79         echo
80         echo "Moving stable must have the previous stable as the first parent"
81         echo
82         echo "----------------------------------------------------"
83         exit 1
84 fi
85
86 second_parent=$(git rev-list --no-walk --parents $newrev | sed 's/ /\n/g' | grep -v $newrev | tail --lines=1)
87 changed_lines=$(git diff $second_parent..$newrev | wc -l)
88 if [ "$changed_lines" -ne "0" ] ; then
89         echo "----------------------------------------------------"
90         echo
91         echo "Moving stable must not result in any changes"
92         echo
93         echo "----------------------------------------------------"
94         exit 1
95 fi
96