4 # This enforces stable/candidate/topic patterns.
8 # * stable must be moved 1 merge commit at a time (see below)
9 # * candidates/topics are frozen once merged into stable
10 # * topics are frozen once merged into candidates
12 # For DAG aesthetics, we prefer stable only moving in the approved way,
13 # which is via empty (no change) merge commits. The rationale is that
14 # in the DAG we want a simple, one-commit move from each release to the
17 # We started out with:
21 # \ * -- * -- B topic1
25 # And then publishing stable was a matter of fast-forwarding
28 # In a complicated (non-rebased) DAG, this becomes hard to follow,
29 # so want we want instead is:
31 # * -- A ----------- C stable
33 # \ * -- * -- B topic1
37 # Where commit C lists as it's first parent the prior stable
38 # commit and as it's second parent the release candidate. No
39 # other parents are allowed (e.g. no octopus merges here, which
40 # would insinuate qa didn't happen on the merged result).
42 # Also, we want to enforce that C does not actually introduce
43 # any diffs to the files between B and C--otherwise this changes
44 # would not have appeared in QA.
47 . $(dirname $0)/functions
55 short_refname=${refname##refs/heads/}
63 if [ "$change_type" == "delete" ] ; then
67 if [ "$change_type" == "create" -a "$short_refname" != "stable" ] ; then
68 not_on_stable=$(git rev-list stable..$newrev)
69 if [ "$not_on_stable" == "" ] ; then
70 display_error_message "Creating a branch must include new commits"
75 # create/delete is okay
76 if [ "$change_type" != "update" ] ; then
80 # # The tip must always be new
81 # already=$(git branch --contains "$newrev")
82 # if [ "$already" != "" ] ; then
83 # already=${already## }
84 # echo "----------------------------------------------------"
86 # echo "$short_refname is already referred to by $already"
88 # echo "----------------------------------------------------"
92 if [ "$short_refname" == "stable" ] ; then
96 # - all commits from old..new
97 # - unless they were already pointed to by a branch
98 # = all new commits on stable
99 count=$(git rev-parse --not --branches | git rev-list --stdin $oldrev..$newrev | wc -l)
100 if [ "$count" -ne "1" ] ; then
101 display_error_message "Moving stable must entail a single commit"
105 number_of_parents=$(git rev-list --no-walk --parents $newrev | sed 's/ /\n/g' | grep -v $newrev | wc -l)
106 if [ "$number_of_parents" -ne "2" ] ; then
107 display_error_message "Moving stable must entail a merge commit"
111 first_parent=$(git rev-list --no-walk --parents $newrev | sed 's/ /\n/g' | grep -v $newrev | head --lines=1)
112 if [ "$first_parent" != "$oldrev" ] ; then
113 display_error_message "Moving stable must have the previous stable as the first parent"
117 second_parent=$(git rev-list --no-walk --parents $newrev | sed 's/ /\n/g' | grep -v $newrev | tail --lines=1)
118 changed_lines=$(git diff $second_parent..$newrev | wc -l)
119 if [ "$changed_lines" -ne "0" ] ; then
120 display_error_message "Moving stable must not result in any changes from $second_parent"
124 # Check if candidate/topic is already in stable
125 git branch --contains "$oldrev" | grep stable >/dev/null
126 if [ $? -eq 0 ] ; then
127 display_error_message "$short_refname has been merged into stable"
131 # For now candidates can mix amongst each other so early exit
133 refs/heads/candidate*)
140 # Check if topic is already in candidates
141 candidate=$(git branch --contains "$oldrev" | grep -oP "candidate.*" --max-count=1)
142 if [ $? -eq 0 ] ; then
143 display_error_message "$short_refname has been merged into $candidate"