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 if [[ $ci_base_branch == "beta" ]]; then
22 verify_cherries master "$BETA_LIMIT" \
25 elif [[ $ci_base_branch == "stable" ]]; then
26 (verify_cherries master "$STABLE_LIMIT" \
27 & verify_cherries beta "$STABLE_LIMIT") \
33 # Verify all commits in `HEAD` are backports of a commit in <upstream>. See
34 # https://git-scm.com/docs/git-cherry for an explanation of the arguments.
39 # commits that lack a `backport-of` comment.
41 # commits with an incorrect `backport-of` comment.
42 local bad_backports=()
44 commits=$(git cherry "origin/$1" HEAD "$2")
46 if [[ -z "$commits" ]]; then
47 echo "All commits in \`HEAD\` are present in \`$1\`"
51 commits=$(echo "$commits" | grep '^\+' | cut -c 3-)
54 # Check each commit in <current>..<upstream>
55 backport_sha=$(get_backport "$sha")
57 if [[ "$backport_sha" == "nothing" ]]; then
58 echo "✓ \`$sha\` backports nothing"
62 if [[ -z "$backport_sha" ]]; then
63 no_backports+=("$sha")
67 if ! is_in_master "$backport_sha"; then
68 bad_backports+=("$sha")
72 echo "✓ \`$sha\` backports \`$backport_sha\`"
77 if [ ${#no_backports[@]} -ne 0 ]; then
78 echo 'Error: Could not find backports for all commits.'
80 echo 'All commits in \`HEAD\` are required to have a corresponding upstream commit.'
81 echo 'It looks like the following commits:'
83 for commit in "${no_backports[@]}"; do
87 echo "do not match any commits in \`$1\`. If this was intended, add the text"
88 echo '\`backport-of: <SHA of a commit already in master>\`'
89 echo 'somewhere in the message of each of these commits.'
94 if [ ${#bad_backports[@]} -ne 0 ]; then
95 echo 'Error: Found incorrectly marked commits.'
97 echo 'The following commits:'
99 for commit in "${bad_backports[@]}"; do
103 echo 'have commit messages marked \`backport-of: <SHA>\`, but the SHA is not in'
112 # Get the backport of a commit. It echoes one of:
114 # 1. A SHA of the backported commit
115 # 2. The string "nothing"
122 # ^.* - throw away any extra starting characters
123 # backport-of: - prefix
124 # \s\? - optional space
125 # \(\) - capture group
126 # [a-f0-9]\+\|nothing - a SHA or the text 'nothing'
127 # .* - throw away any extra ending characters
128 # \1 - replace it with the first match
129 # {s//\1/p;q} - print the first occurrence and quit
131 git show -s --format=%B "$1" \
132 | sed -n '/^.*backport-of:\s\?\([a-f0-9]\+\|nothing\).*/{s//\1/p;q}'
135 # Check if a commit is in master.
139 git merge-base --is-ancestor "$1" origin/master 2> /dev/null
142 verify_backported_commits_main