blob: 26cec55fde25ad58e7d54b023215253c2f02540a [file] [log] [blame]
Patrick Georgi1707a164c2015-04-03 17:06:48 -07001#!/bin/sh
2
3# rebase.sh - rebase helper script
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; version 2 of the License.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14
15# Adapt to your remote branch:
Patrick Georgibf8589e2015-08-28 20:27:28 +020016BRANCH="cros/chromeos-2015.07"
Patrick Georgi1707a164c2015-04-03 17:06:48 -070017
18# When pulling in patches from another tree from a gerrit repository,
19# do the following at the end of a larger cherry-pick series:
20# git remote add ...
21# git checkout -b upstreaming
22# git cherry-pick ...
23# git rebase -i --exec util/gitconfig/rebase.sh master
24# Alternatively, you can run util/gitconfig/rebase.sh after every
25# individual cherry-pick.
26
27commit_message() {
28 git log -n 1 | grep "^ " | cut -c5-
29}
30
31CHID=$( commit_message | grep -i "^Change-Id: I" )
32CID=$( git log -n1 --grep "^$CHID$" --pretty=%H $BRANCH )
33GUID="$(git config user.name) <$(git config user.email)>"
34
35# TBD: Don't add Original- to empty lines, and possibly make script more
36# solid for commits with an unexpected order of meta data lines.
37
38commit_message | tac | awk '/^$/ {
39 if (end==0)
40 print "Original-Commit-Id: '"$CID"'\nSigned-off-by: '"$GUID"'";
41 end=1
42 }; {
43 if (end==0)
44 print "Original-" $0;
45 else
46 print $0;
47 }' | tac | git commit --amend -F -