Skip to content

Commit 850eef9

Browse files
hsbtclaude
andcommitted
Expand merge-commit cherry-picks when filtering released commits
A `(cherry picked from commit M)` footer where M is a merge commit only covers M itself. The PR's individual commits are still on master, and `gh search prs` finds the PR through them, so PRs merged with "Create a merge commit" were re-listed as backport candidates. Walk M's two parents to also exclude the commits the merge introduced. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 8b044ef commit 850eef9

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

tool/release.rb

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -372,13 +372,22 @@ def unreleased_pull_requests
372372

373373
# Source SHAs already cherry-picked onto the stable branch, derived from the
374374
# `(cherry picked from commit X)` footer that `git cherry-pick -x` records.
375-
# This is more reliable than matching merge commit subjects, which only
376-
# catches PRs merged with "Create a merge commit". Squash-merged PRs are
377-
# cherry-picked as plain commits with subjects like `"Foo (#1234)"` or
378-
# without any PR reference, so subject-based detection misses them.
375+
# When the footer references a merge commit (PRs merged with "Create a merge
376+
# commit", picked with `-m 1`), also include the individual PR commits the
377+
# merge introduced, otherwise `gh search prs` would still re-discover the PR
378+
# through those commits left on master.
379379
def released_commit_shas
380-
@released_commit_shas ||= `git log --format=%B #{@previous_release_tag}..#{@stable_branch}`
381-
.scan(/cherry picked from commit ([0-9a-f]+)/).flatten.to_set
380+
@released_commit_shas ||= begin
381+
log = `git log --format=%B #{@previous_release_tag}..#{@stable_branch}`
382+
shas = Set.new
383+
log.scan(/cherry picked from commit ([0-9a-f]+)/).flatten.each do |sha|
384+
shas << sha
385+
parents = `git rev-list --parents -n 1 #{sha} 2>/dev/null`.strip.split.drop(1)
386+
next unless parents.size >= 2
387+
shas.merge(`git log --format=%H #{parents[0]}..#{parents[1]}`.split("\n"))
388+
end
389+
shas
390+
end
382391
end
383392

384393
def scan_unreleased_pull_requests(ids)

0 commit comments

Comments
 (0)