Patrick Georgi | 1707a164c | 2015-04-03 17:06:48 -0700 | [diff] [blame] | 1 | #!/bin/sh |
Jett Rink | 1eeb94f | 2019-05-17 07:36:47 -0600 | [diff] [blame] | 2 | # cross-repo-cherrypick - rebase helper script |
Patrick Georgi | 1707a164c | 2015-04-03 17:06:48 -0700 | [diff] [blame] | 3 | # |
Patrick Georgi | 7333a11 | 2020-05-08 20:48:04 +0200 | [diff] [blame] | 4 | # SPDX-License-Identifier: GPL-2.0-only |
Patrick Georgi | 1707a164c | 2015-04-03 17:06:48 -0700 | [diff] [blame] | 5 | |
| 6 | # Adapt to your remote branch: |
Patrick Georgi | 6f27edd | 2017-01-13 19:11:29 +0100 | [diff] [blame] | 7 | BRANCH="origin/master" |
Patrick Georgi | 1707a164c | 2015-04-03 17:06:48 -0700 | [diff] [blame] | 8 | |
| 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 Rink | 1eeb94f | 2019-05-17 07:36:47 -0600 | [diff] [blame] | 14 | # git rebase -i --exec util/scripts/cross-repo-cherrypick master |
| 15 | # Alternatively, you can run util/scripts/cross-repo-cherrypick after every |
Patrick Georgi | 1707a164c | 2015-04-03 17:06:48 -0700 | [diff] [blame] | 16 | # individual cherry-pick. |
| 17 | |
Patrick Georgi | 6f27edd | 2017-01-13 19:11:29 +0100 | [diff] [blame] | 18 | # use $0 --cros to add a stub BUG/BRANCH/TEST block |
| 19 | |
Patrick Georgi | 1707a164c | 2015-04-03 17:06:48 -0700 | [diff] [blame] | 20 | commit_message() { |
| 21 | git log -n 1 | grep "^ " | cut -c5- |
| 22 | } |
| 23 | |
Patrick Georgi | 6f27edd | 2017-01-13 19:11:29 +0100 | [diff] [blame] | 24 | ORIGIN_HOST=$( commit_message |grep "^Reviewed-on: " |head -1 |cut -d/ -f3 ) |
| 25 | case "${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 | ;; |
| 34 | esac |
| 35 | |
| 36 | # lines must be backwards due to tac(1) |
| 37 | SPLICE_CMD="" |
| 38 | if 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 |
| 42 | fi |
| 43 | |
Patrick Georgi | 1707a164c | 2015-04-03 17:06:48 -0700 | [diff] [blame] | 44 | CHID=$( commit_message | grep -i "^Change-Id: I" ) |
| 45 | CID=$( git log -n1 --grep "^$CHID$" --pretty=%H $BRANCH ) |
| 46 | GUID="$(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 Georgi | 6f27edd | 2017-01-13 19:11:29 +0100 | [diff] [blame] | 51 | (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 Georgi | 1707a164c | 2015-04-03 17:06:48 -0700 | [diff] [blame] | 56 | end=1 |
Patrick Georgi | 77343fd | 2017-09-14 09:48:35 +0200 | [diff] [blame] | 57 | }; /^(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 Georgi | 1707a164c | 2015-04-03 17:06:48 -0700 | [diff] [blame] | 63 | }; { |
| 64 | if (end==0) |
| 65 | print "Original-" $0; |
| 66 | else |
| 67 | print $0; |
| 68 | }' | tac | git commit --amend -F - |