@@ -62,6 +62,11 @@ verify_cherries() {
6262 # Check each commit in <current>..<upstream>
6363 backport_sha=$( get_backport " $sha " )
6464
65+ if [[ " $backport_sha " == " nothing" ]]; then
66+ echo " ✓ \` $sha \` backports nothing"
67+ continue
68+ fi
69+
6570 if [[ -z " $backport_sha " ]]; then
6671 no_backports+=(" $sha " )
6772 continue
@@ -88,8 +93,8 @@ verify_cherries() {
8893 done
8994 echo
9095 echo " do not match any commits in \` $1 \` . If this was intended, add the text"
91- echo ' \`backport-of: <SHA of a commit already in master>\` somewhere in the '
92- echo ' message of each of these commits.'
96+ echo ' \`backport-of: <SHA of a commit already in master>\`'
97+ echo ' somewhere in the message of each of these commits.'
9398 echo
9499 failure=1
95100 fi
@@ -112,12 +117,27 @@ verify_cherries() {
112117 return $failure
113118}
114119
115- # Get the backport of a commit, or empty string if it does not exist.
120+ # Get the backport of a commit. It echoes one of:
121+ #
122+ # 1. A SHA of the backported commit
123+ # 2. The string "nothing"
124+ # 3. An empty string
116125#
117126# $1 = <sha>
118127get_backport () {
128+ # This regex is:
129+ #
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
138+ #
119139 git show -s --format=%B " $1 " \
120- | sed -n ' s /^.*backport-of:\s\?\([a-f0-9]\+\).*/\1/p'
140+ | sed -n ' /^.*backport-of:\s\?\([a-f0-9]\+\|nothing\ ).*/{s// \1/p;q} '
121141}
122142
123143# Check if a commit is in master.
0 commit comments