blob: 42b05b5131885ecc38546b3661375ccf230a0188 [file] [log] [blame]
Patrick Georgi1707a164c2015-04-03 17:06:48 -07001#!/bin/sh
2
Jett Rink1eeb94f2019-05-17 07:36:47 -06003# cross-repo-cherrypick - rebase helper script
Patrick Georgi1707a164c2015-04-03 17:06:48 -07004#
Patrick Georgi6f27edd2017-01-13 19:11:29 +01005# Copyright 2015, 2017 Google Inc.
Patrick Georgi40032832016-10-24 11:58:07 +02006#
Patrick Georgi1707a164c2015-04-03 17:06:48 -07007# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; version 2 of the License.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16
17# Adapt to your remote branch:
Patrick Georgi6f27edd2017-01-13 19:11:29 +010018BRANCH="origin/master"
Patrick Georgi1707a164c2015-04-03 17:06:48 -070019
20# When pulling in patches from another tree from a gerrit repository,
21# do the following at the end of a larger cherry-pick series:
22# git remote add ...
23# git checkout -b upstreaming
24# git cherry-pick ...
Jett Rink1eeb94f2019-05-17 07:36:47 -060025# git rebase -i --exec util/scripts/cross-repo-cherrypick master
26# Alternatively, you can run util/scripts/cross-repo-cherrypick after every
Patrick Georgi1707a164c2015-04-03 17:06:48 -070027# individual cherry-pick.
28
Patrick Georgi6f27edd2017-01-13 19:11:29 +010029# use $0 --cros to add a stub BUG/BRANCH/TEST block
30
Patrick Georgi1707a164c2015-04-03 17:06:48 -070031commit_message() {
32 git log -n 1 | grep "^ " | cut -c5-
33}
34
Patrick Georgi6f27edd2017-01-13 19:11:29 +010035ORIGIN_HOST=$( commit_message |grep "^Reviewed-on: " |head -1 |cut -d/ -f3 )
36case "${ORIGIN_HOST}" in
37 review.coreboot.org)
38 BRANCH="origin/master"
39 MESSAGE_PREFIX="UPSTREAM: "
40 ;;
41 chromium-review.googlesource.com)
42 BRANCH="cros/chromeos-2016.05"
43 MESSAGE_PREFIX=""
44 ;;
45esac
46
47# lines must be backwards due to tac(1)
48SPLICE_CMD=""
49if test "$1" = "--cros"; then
50 if test -z "$( commit_message |egrep '^(BUG|TEST)=')"; then
51 SPLICE_CMD='print "\nTEST=none\nBRANCH=none\nBUG=none\n"'
52 fi
53fi
54
Patrick Georgi1707a164c2015-04-03 17:06:48 -070055CHID=$( commit_message | grep -i "^Change-Id: I" )
56CID=$( git log -n1 --grep "^$CHID$" --pretty=%H $BRANCH )
57GUID="$(git config user.name) <$(git config user.email)>"
58
59# TBD: Don't add Original- to empty lines, and possibly make script more
60# solid for commits with an unexpected order of meta data lines.
61
Patrick Georgi6f27edd2017-01-13 19:11:29 +010062(printf "${MESSAGE_PREFIX}"; commit_message) | tac | awk '/^$/ {
63 if (end==0) {
64 print "Original-Commit-Id: '"${CID}"'\nSigned-off-by: '"${GUID}"'";
65 '"${SPLICE_CMD}"'
66 }
Patrick Georgi1707a164c2015-04-03 17:06:48 -070067 end=1
Patrick Georgi77343fd2017-09-14 09:48:35 +020068 }; /^(BUG|BRANCH|TEST|CQ-DEPEND)=/ {
69 if (end==0) {
70 print "Original-Commit-Id: '"${CID}"'\nSigned-off-by: '"${GUID}"'";
71 print "";
72 }
73 end=1
Patrick Georgi1707a164c2015-04-03 17:06:48 -070074 }; {
75 if (end==0)
76 print "Original-" $0;
77 else
78 print $0;
79 }' | tac | git commit --amend -F -