@@ -96,6 +96,8 @@ main() {
96
96
# and main. These are sorted by commit title so that we can group
97
97
# two cherry-picks together.
98
98
declare -A cherry_pick_commits
99
+ declare -A renamed_cherry_pick_commits
100
+ declare -a renamed_cherry_pick_commits_pending
99
101
git_cherry_out=$(
100
102
{
101
103
git log --no-merges --cherry-mark --pretty=format:" %m %H %s" " ${to_ref} ...origin/main"
@@ -109,20 +111,45 @@ main() {
109
111
# Iterate over the array in groups of two
110
112
for (( i = 0 ; i < ${# cherry_picks[@]} ; i += 2 )) ; do
111
113
mapfile -d ' ' -t parts1 <<< " ${cherry_picks[i]}"
112
- mapfile -d ' ' -t parts2 <<< " ${cherry_picks[i + 1]}"
113
114
commit1=${parts1[1]}
114
115
title1=${parts1[*]: 2}
115
- commit2=${parts2[1]}
116
- title2=${parts2[*]: 2}
116
+
117
+ title2=
118
+ if (( i + 1 < ${# cherry_picks[@]} )) ; then
119
+ mapfile -d ' ' -t parts2 <<< " ${cherry_picks[i + 1]}"
120
+ commit2=${parts2[1]}
121
+ title2=${parts2[*]: 2}
122
+ fi
117
123
118
124
if [[ ${title1} != " ${title2} " ]]; then
119
- error " Invariant failed, cherry-picked commits have different titles: ${title1} != ${title2} "
125
+ log " Invariant failed, cherry-picked commits have different titles: ${title1} != ${title2} , attempting to check commit body for cherry-pick information..."
126
+
127
+ renamed=$( git show " ${commit1} " | sed -ne ' s/.*cherry picked from commit \([0-9a-f]*\).*/\1/p' )
128
+ if [[ -n ${renamed} ]]; then
129
+ log " Found renamed cherry-pick commit ${commit1} -> ${renamed} "
130
+ renamed_cherry_pick_commits[${commit1} ]=${renamed}
131
+ renamed_cherry_pick_commits[${renamed} ]=${commit1}
132
+ continue
133
+ else
134
+ log " Not a cherry-pick commit, adding ${commit1} to pending list..."
135
+ renamed_cherry_pick_commits_pending+=(" ${commit1} " )
136
+ fi
137
+ # error "Invariant failed, cherry-picked commits have different titles: ${title1} != ${title2}"
138
+ (( i-- ))
139
+ continue
120
140
fi
121
141
122
142
cherry_pick_commits[${commit1} ]=${commit2}
123
143
cherry_pick_commits[${commit2} ]=${commit1}
124
144
done
125
145
fi
146
+ for commit in " ${renamed_cherry_pick_commits_pending[@]} " ; do
147
+ log " Checking if pending commit ${commit} has a corresponding cherry-pick..."
148
+ if [[ ! -v renamed_cherry_pick_commits[${commit} ] ]]; then
149
+ error " Invariant failed, cherry-picked commit ${commit} has no corresponding original commit"
150
+ fi
151
+ log " Found matching cherry-pick commit ${commit} -> ${renamed_cherry_pick_commits[${commit}]} "
152
+ done
126
153
127
154
# Get abbreviated and full commit hashes and titles for each commit.
128
155
git_log_out=" $( git log --no-merges --left-right --pretty=format:" %m %h %H %s" " ${range} " ) "
0 commit comments