Skip to content

Commit 374f0a0

Browse files
authored
chore(scripts): handle renamed cherry-pick commits in release script (#13395)
1 parent bc8126f commit 374f0a0

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

scripts/release/check_commit_metadata.sh

+31-4
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ main() {
9696
# and main. These are sorted by commit title so that we can group
9797
# two cherry-picks together.
9898
declare -A cherry_pick_commits
99+
declare -A renamed_cherry_pick_commits
100+
declare -a renamed_cherry_pick_commits_pending
99101
git_cherry_out=$(
100102
{
101103
git log --no-merges --cherry-mark --pretty=format:"%m %H %s" "${to_ref}...origin/main"
@@ -109,20 +111,45 @@ main() {
109111
# Iterate over the array in groups of two
110112
for ((i = 0; i < ${#cherry_picks[@]}; i += 2)); do
111113
mapfile -d ' ' -t parts1 <<<"${cherry_picks[i]}"
112-
mapfile -d ' ' -t parts2 <<<"${cherry_picks[i + 1]}"
113114
commit1=${parts1[1]}
114115
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
117123

118124
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
120140
fi
121141

122142
cherry_pick_commits[${commit1}]=${commit2}
123143
cherry_pick_commits[${commit2}]=${commit1}
124144
done
125145
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
126153

127154
# Get abbreviated and full commit hashes and titles for each commit.
128155
git_log_out="$(git log --no-merges --left-right --pretty=format:"%m %h %H %s" "${range}")"

0 commit comments

Comments
 (0)