blob: b27ff4375a9da5230b92fd0624ffedf5b2aac083 [file] [log] [blame]
Martin Roth0ad5fbd2020-12-24 12:06:38 -07001#!/usr/bin/env 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:
Stefan Reinauerb8a71b462023-09-12 08:38:19 -07007BRANCH="origin/main"
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)
Stefan Reinauerb8a71b462023-09-12 08:38:19 -070027 BRANCH="origin/main"
Patrick Georgi6f27edd2017-01-13 19:11:29 +010028 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
Felix Singer74b4bd02023-04-01 14:42:54 +020039 if test -z "$(commit_message | grep -E '^(BUG|TEST)=')"; then
Patrick Georgi6f27edd2017-01-13 19:11:29 +010040 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) {
Patrick Georgi731078902022-01-10 22:41:03 +010053 print "GitOrigin-RevId: '"${CID}"'\nSigned-off-by: '"${GUID}"'";
Patrick Georgi6f27edd2017-01-13 19:11:29 +010054 '"${SPLICE_CMD}"'
55 }
Patrick Georgi1707a164c2015-04-03 17:06:48 -070056 end=1
Karthikeyan Ramasubramaniancb5961d2020-08-26 12:10:10 -060057 }; /^(BUG|BRANCH|TEST)=/ {
Patrick Georgi77343fd2017-09-14 09:48:35 +020058 if (end==0) {
Patrick Georgi731078902022-01-10 22:41:03 +010059 print "GitOrigin-RevId: '"${CID}"'\nSigned-off-by: '"${GUID}"'";
Patrick Georgi77343fd2017-09-14 09:48:35 +020060 print "";
61 }
62 end=1
Karthikeyan Ramasubramaniancb5961d2020-08-26 12:10:10 -060063 }; /^Cq-Depend:/ {
64 print $0;
65 next
Patrick Georgi731078902022-01-10 22:41:03 +010066 }; /^Change-Id:/ {
67 print $0;
68 next
Patrick Georgi1707a164c2015-04-03 17:06:48 -070069 }; {
70 if (end==0)
71 print "Original-" $0;
72 else
73 print $0;
74 }' | tac | git commit --amend -F -