Skip to content

Commit 0b3d859

Browse files
committed
scripts: add backporting script
This adds a simple script for backporting pull requests to older branches. It accepts as parameters a list of pull request numbers which whose commits are to be cherry-picked. The identification of PRs currently happens by using the commit message of the merge of the PR, which should conform to the message "Merge pull request #<PR>". While the heuristic works in practice, we could instead also use the direct references from GitHub via "pull/#<PR>/head". This requires the user to have all these references fetched, though, so we can just use the current heuristic until we experience any issues with that.
1 parent 7610638 commit 0b3d859

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

script/backport.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/sh
2+
3+
if test $# -eq 0
4+
then
5+
echo "USAGE: $0 <#PR> [<#PR>...]"
6+
exit
7+
fi
8+
9+
commits=
10+
11+
for pr in $*
12+
do
13+
mergecommit=$(git rev-parse ":/Merge pull request #$pr" || exit 1)
14+
mergebase=$(git merge-base "$mergecommit"^1 "$mergecommit"^2 || exit 1)
15+
16+
commits="$commits $(git rev-list --reverse "$mergecommit"^2 ^"$mergebase")"
17+
done
18+
19+
echo "Cherry-picking the following commits:"
20+
git rev-list --no-walk --oneline $commits
21+
echo
22+
23+
git cherry-pick $commits

0 commit comments

Comments
 (0)