blob: 0f2acf8eae15548f20f55c740d4708c6d6af6868 [file] [log] [blame]
Patrick Georgi1707a164c2015-04-03 17:06:48 -07001#!/bin/sh
2
3# rebase.sh - rebase helper script
4#
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 ...
25# git rebase -i --exec util/gitconfig/rebase.sh master
26# Alternatively, you can run util/gitconfig/rebase.sh after every
27# 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
68 }; {
69 if (end==0)
70 print "Original-" $0;
71 else
72 print $0;
73 }' | tac | git commit --amend -F -