From 0b3d85925751c2b3fd49effa50f7bd7b558b4926 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Fri, 12 Jan 2018 11:02:19 +0000 Subject: 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 #". While the heuristic works in practice, we could instead also use the direct references from GitHub via "pull/#/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. --- script/backport.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 script/backport.sh (limited to 'script') diff --git a/script/backport.sh b/script/backport.sh new file mode 100755 index 000000000..3c2f899d6 --- /dev/null +++ b/script/backport.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +if test $# -eq 0 +then + echo "USAGE: $0 <#PR> [<#PR>...]" + exit +fi + +commits= + +for pr in $* +do + mergecommit=$(git rev-parse ":/Merge pull request #$pr" || exit 1) + mergebase=$(git merge-base "$mergecommit"^1 "$mergecommit"^2 || exit 1) + + commits="$commits $(git rev-list --reverse "$mergecommit"^2 ^"$mergebase")" +done + +echo "Cherry-picking the following commits:" +git rev-list --no-walk --oneline $commits +echo + +git cherry-pick $commits -- cgit v1.2.1