Patrick Georgi | 1707a164c | 2015-04-03 17:06:48 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
Jett Rink | 1eeb94f | 2019-05-17 07:36:47 -0600 | [diff] [blame] | 3 | # cross-repo-cherrypick - rebase helper script |
Patrick Georgi | 1707a164c | 2015-04-03 17:06:48 -0700 | [diff] [blame] | 4 | # |
Patrick Georgi | 6f27edd | 2017-01-13 19:11:29 +0100 | [diff] [blame] | 5 | # Copyright 2015, 2017 Google Inc. |
Patrick Georgi | 4003283 | 2016-10-24 11:58:07 +0200 | [diff] [blame] | 6 | # |
Patrick Georgi | 1707a164c | 2015-04-03 17:06:48 -0700 | [diff] [blame] | 7 | # 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 Georgi | 6f27edd | 2017-01-13 19:11:29 +0100 | [diff] [blame] | 18 | BRANCH="origin/master" |
Patrick Georgi | 1707a164c | 2015-04-03 17:06:48 -0700 | [diff] [blame] | 19 | |
| 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 Rink | 1eeb94f | 2019-05-17 07:36:47 -0600 | [diff] [blame] | 25 | # git rebase -i --exec util/scripts/cross-repo-cherrypick master |
| 26 | # Alternatively, you can run util/scripts/cross-repo-cherrypick after every |
Patrick Georgi | 1707a164c | 2015-04-03 17:06:48 -0700 | [diff] [blame] | 27 | # individual cherry-pick. |
| 28 | |
Patrick Georgi | 6f27edd | 2017-01-13 19:11:29 +0100 | [diff] [blame] | 29 | # use $0 --cros to add a stub BUG/BRANCH/TEST block |
| 30 | |
Patrick Georgi | 1707a164c | 2015-04-03 17:06:48 -0700 | [diff] [blame] | 31 | commit_message() { |
| 32 | git log -n 1 | grep "^ " | cut -c5- |
| 33 | } |
| 34 | |
Patrick Georgi | 6f27edd | 2017-01-13 19:11:29 +0100 | [diff] [blame] | 35 | ORIGIN_HOST=$( commit_message |grep "^Reviewed-on: " |head -1 |cut -d/ -f3 ) |
| 36 | case "${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 | ;; |
| 45 | esac |
| 46 | |
| 47 | # lines must be backwards due to tac(1) |
| 48 | SPLICE_CMD="" |
| 49 | if 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 |
| 53 | fi |
| 54 | |
Patrick Georgi | 1707a164c | 2015-04-03 17:06:48 -0700 | [diff] [blame] | 55 | CHID=$( commit_message | grep -i "^Change-Id: I" ) |
| 56 | CID=$( git log -n1 --grep "^$CHID$" --pretty=%H $BRANCH ) |
| 57 | GUID="$(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 Georgi | 6f27edd | 2017-01-13 19:11:29 +0100 | [diff] [blame] | 62 | (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 Georgi | 1707a164c | 2015-04-03 17:06:48 -0700 | [diff] [blame] | 67 | end=1 |
Patrick Georgi | 77343fd | 2017-09-14 09:48:35 +0200 | [diff] [blame] | 68 | }; /^(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 Georgi | 1707a164c | 2015-04-03 17:06:48 -0700 | [diff] [blame] | 74 | }; { |
| 75 | if (end==0) |
| 76 | print "Original-" $0; |
| 77 | else |
| 78 | print $0; |
| 79 | }' | tac | git commit --amend -F - |