3 # rebase.sh - rebase helper script
5 # Copyright 2015, 2017 Google Inc.
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.
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.
17 # Adapt to your remote branch:
18 BRANCH
="origin/master"
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:
23 # git checkout -b upstreaming
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.
29 # use $0 --cros to add a stub BUG/BRANCH/TEST block
32 git log
-n 1 |
grep "^ " | cut
-c5-
35 ORIGIN_HOST
=$
( commit_message |
grep "^Reviewed-on: " |
head -1 |cut
-d/ -f3 )
36 case "${ORIGIN_HOST}" in
38 BRANCH
="origin/master"
39 MESSAGE_PREFIX
="UPSTREAM: "
41 chromium-review.googlesource.com
)
42 BRANCH
="cros/chromeos-2016.05"
47 # lines must be backwards due to tac(1)
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"'
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)>"
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.
62 (printf "${MESSAGE_PREFIX}"; commit_message
) |
tac |
awk '/^$/ {
64 print "Original-Commit-Id: '"${CID}"'\nSigned-off-by: '"${GUID}"'";
68 }; /^(BUG|BRANCH|TEST|CQ-DEPEND)=/ {
70 print "Original-Commit-Id: '"${CID}"'\nSigned-off-by: '"${GUID}"'";
79 }' |
tac | git commit
--amend -F -