Skip to content

Commit e8458d7

Browse files
committed
fix(ci): handle merge commits in welan cherry-pick
Replace the manual commit-accumulation loop with a two-phase approach: 1. Walk first-parent to locate the upstream boundary (unchanged logic). 2. Use `git log --no-merges --reverse` over that range to collect only cherry-pickable, non-merge commits. Previously, a merge commit at the tip (e.g. from a merged PR) caused `git cherry-pick` to fail with "is a merge but no -m option was given". The new approach surfaces the real patch commits from all merged branches instead, so no -m is ever needed.
1 parent bdabd27 commit e8458d7

1 file changed

Lines changed: 23 additions & 12 deletions

File tree

.github/workflows/a-welan-release.yml

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,31 +89,42 @@ jobs:
8989
id: patches
9090
continue-on-error: true
9191
run: |
92-
patch_commits=()
93-
ref="origin/welan"
94-
92+
# Walk the first-parent chain to find the upstream boundary: the first
93+
# commit NOT authored by WELAN_PATCH_AUTHOR. Merge commits count as
94+
# authored by whoever merged them, so this correctly stops at the
95+
# upstream base even when the tip is a merge commit.
96+
base_ref="origin/welan"
9597
while true; do
96-
author="$(git log -1 --format='%an' "$ref")"
98+
author="$(git log -1 --format='%an' "$base_ref")"
9799
if [[ "$author" != *"$WELAN_PATCH_AUTHOR"* ]]; then
98100
break
99101
fi
100-
101-
patch_commits=("$ref" "${patch_commits[@]}")
102-
103-
if ! git rev-parse "${ref}^" >/dev/null 2>&1; then
102+
if ! git rev-parse "${base_ref}^" >/dev/null 2>&1; then
104103
break
105104
fi
106-
ref="${ref}^"
105+
base_ref="${base_ref}^"
107106
done
108107
109-
if [ "${#patch_commits[@]}" -eq 0 ]; then
108+
if [[ "$(git rev-parse "$base_ref")" == "$(git rev-parse "origin/welan")" ]]; then
110109
echo "::error::No commits authored by $WELAN_PATCH_AUTHOR found at the tip of origin/welan"
111110
exit 1
112111
fi
113112
113+
# Collect all non-merge commits in the weizhoublue range (oldest first).
114+
# --no-merges skips merge bookkeeping commits and instead surfaces the
115+
# real patch commits from any merged branches, making each entry safely
116+
# cherry-pickable without needing -m.
117+
mapfile -t patch_commits < <(
118+
git log --no-merges --reverse --format='%H' "${base_ref}..origin/welan"
119+
)
120+
121+
if [ "${#patch_commits[@]}" -eq 0 ]; then
122+
echo "::error::No non-merge commits found between $base_ref and origin/welan"
123+
exit 1
124+
fi
125+
114126
echo "Cherry-picking ${#patch_commits[@]} commit(s) from origin/welan (author: $WELAN_PATCH_AUTHOR)"
115-
for commit in "${patch_commits[@]}"; do
116-
sha="$(git rev-parse "$commit")"
127+
for sha in "${patch_commits[@]}"; do
117128
subject="$(git log -1 --format='%s' "$sha")"
118129
echo "Cherry-picking $sha $subject"
119130
git cherry-pick "$sha"

0 commit comments

Comments
 (0)