2 # Ensure commits in beta are in master & commits in stable are in beta + master.
6 source "$(cd "$(dirname "$0")" && pwd)/../shared.sh"
8 # We don't care about commits that predate this automation check, so we pass a
9 # `<limit>` argument to `git cherry`.
10 BETA_LIMIT="53fd98ca776cb875bc9e5514f56b52eb74f9e7a9"
11 STABLE_LIMIT="a178d0322ce20e33eac124758e837cbd80a6f633"
13 verify_backported_commits_main() {
14 ci_base_branch=$(ciBaseBranch)
16 if [[ "$ci_base_branch" != "beta" && "$ci_base_branch" != "stable" ]]; then
17 echo 'Skipping. This is only run when merging to the beta or stable branches.'
21 echo 'git: unshallowing the repository so we can check commits'
24 --no-recurse-submodules \
29 if [[ $ci_base_branch == "beta" ]]; then
30 verify_cherries master "$BETA_LIMIT" \
33 elif [[ $ci_base_branch == "stable" ]]; then
34 (verify_cherries master "$STABLE_LIMIT" \
35 & verify_cherries beta "$STABLE_LIMIT") \
41 # Verify all commits in `HEAD` are backports of a commit in <upstream>. See
42 # https://git-scm.com/docs/git-cherry for an explanation of the arguments.
47 # commits that lack a `backport-of` comment.
49 # commits with an incorrect `backport-of` comment.
50 local bad_backports=()
52 commits=$(git cherry "origin/$1" HEAD "$2")
54 if [[ -z "$commits" ]]; then
55 echo "All commits in \`HEAD\` are present in \`$1\`"
59 commits=$(echo "$commits" | grep '^\+' | cut -c 3-)
62 # Check each commit in <current>..<upstream>
63 backport_sha=$(get_backport "$sha")
65 if [[ "$backport_sha" == "nothing" ]]; then
66 echo "✓ \`$sha\` backports nothing"
70 if [[ -z "$backport_sha" ]]; then
71 no_backports+=("$sha")
75 if ! is_in_master "$backport_sha"; then
76 bad_backports+=("$sha")
80 echo "✓ \`$sha\` backports \`$backport_sha\`"
85 if [ ${#no_backports[@]} -ne 0 ]; then
86 echo 'Error: Could not find backports for all commits.'
88 echo 'All commits in \`HEAD\` are required to have a corresponding upstream commit.'
89 echo 'It looks like the following commits:'
91 for commit in "${no_backports[@]}"; do
95 echo "do not match any commits in \`$1\`. If this was intended, add the text"
96 echo '\`backport-of: <SHA of a commit already in master>\`'
97 echo 'somewhere in the message of each of these commits.'
102 if [ ${#bad_backports[@]} -ne 0 ]; then
103 echo 'Error: Found incorrectly marked commits.'
105 echo 'The following commits:'
107 for commit in "${bad_backports[@]}"; do
111 echo 'have commit messages marked \`backport-of: <SHA>\`, but the SHA is not in'
120 # Get the backport of a commit. It echoes one of:
122 # 1. A SHA of the backported commit
123 # 2. The string "nothing"
130 # ^.* - throw away any extra starting characters
131 # backport-of: - prefix
132 # \s\? - optional space
133 # \(\) - capture group
134 # [a-f0-9]\+\|nothing - a SHA or the text 'nothing'
135 # .* - throw away any extra ending characters
136 # \1 - replace it with the first match
137 # {s//\1/p;q} - print the first occurrence and quit
139 git show -s --format=%B "$1" \
140 | sed -n '/^.*backport-of:\s\?\([a-f0-9]\+\|nothing\).*/{s//\1/p;q}'
143 # Check if a commit is in master.
147 git merge-base --is-ancestor "$1" origin/master 2> /dev/null
150 verify_backported_commits_main