blob: 3fbc46faed56f8db83012ef0ea6543fefa6abe4a [file] [log] [blame]
Patrick Georgi1707a164c2015-04-03 17:06:48 -07001#!/bin/sh
Jett Rink1eeb94f2019-05-17 07:36:47 -06002# cross-repo-cherrypick - rebase helper script
Patrick Georgi1707a164c2015-04-03 17:06:48 -07003#
Patrick Georgi7333a112020-05-08 20:48:04 +02004# SPDX-License-Identifier: GPL-2.0-only
Patrick Georgi1707a164c2015-04-03 17:06:48 -07005
6# Adapt to your remote branch:
Patrick Georgi6f27edd2017-01-13 19:11:29 +01007BRANCH="origin/master"
Patrick Georgi1707a164c2015-04-03 17:06:48 -07008
9# When pulling in patches from another tree from a gerrit repository,
10# do the following at the end of a larger cherry-pick series:
11# git remote add ...
12# git checkout -b upstreaming
13# git cherry-pick ...
Jett Rink1eeb94f2019-05-17 07:36:47 -060014# git rebase -i --exec util/scripts/cross-repo-cherrypick master
15# Alternatively, you can run util/scripts/cross-repo-cherrypick after every
Patrick Georgi1707a164c2015-04-03 17:06:48 -070016# individual cherry-pick.
17
Patrick Georgi6f27edd2017-01-13 19:11:29 +010018# use $0 --cros to add a stub BUG/BRANCH/TEST block
19
Patrick Georgi1707a164c2015-04-03 17:06:48 -070020commit_message() {
21 git log -n 1 | grep "^ " | cut -c5-
22}
23
Patrick Georgi6f27edd2017-01-13 19:11:29 +010024ORIGIN_HOST=$( commit_message |grep "^Reviewed-on: " |head -1 |cut -d/ -f3 )
25case "${ORIGIN_HOST}" in
26 review.coreboot.org)
27 BRANCH="origin/master"
28 MESSAGE_PREFIX="UPSTREAM: "
29 ;;
30 chromium-review.googlesource.com)
31 BRANCH="cros/chromeos-2016.05"
32 MESSAGE_PREFIX=""
33 ;;
34esac
35
36# lines must be backwards due to tac(1)
37SPLICE_CMD=""
38if test "$1" = "--cros"; then
39 if test -z "$( commit_message |egrep '^(BUG|TEST)=')"; then
40 SPLICE_CMD='print "\nTEST=none\nBRANCH=none\nBUG=none\n"'
41 fi
42fi
43
Patrick Georgi1707a164c2015-04-03 17:06:48 -070044CHID=$( commit_message | grep -i "^Change-Id: I" )
45CID=$( git log -n1 --grep "^$CHID$" --pretty=%H $BRANCH )
46GUID="$(git config user.name) <$(git config user.email)>"
47
48# TBD: Don't add Original- to empty lines, and possibly make script more
49# solid for commits with an unexpected order of meta data lines.
50
Patrick Georgi6f27edd2017-01-13 19:11:29 +010051(printf "${MESSAGE_PREFIX}"; commit_message) | tac | awk '/^$/ {
52 if (end==0) {
53 print "Original-Commit-Id: '"${CID}"'\nSigned-off-by: '"${GUID}"'";
54 '"${SPLICE_CMD}"'
55 }
Patrick Georgi1707a164c2015-04-03 17:06:48 -070056 end=1
Patrick Georgi77343fd2017-09-14 09:48:35 +020057 }; /^(BUG|BRANCH|TEST|CQ-DEPEND)=/ {
58 if (end==0) {
59 print "Original-Commit-Id: '"${CID}"'\nSigned-off-by: '"${GUID}"'";
60 print "";
61 }
62 end=1
Patrick Georgi1707a164c2015-04-03 17:06:48 -070063 }; {
64 if (end==0)
65 print "Original-" $0;
66 else
67 print $0;
68 }' | tac | git commit --amend -F -