blob: 9247cc2e4001cb1446019d4c9bca9597d447ffc0 [file] [log] [blame]
Patrick Georgi1707a164c2015-04-03 17:06:48 -07001#!/bin/sh
2
3# rebase.sh - rebase helper script
4#
Patrick Georgi40032832016-10-24 11:58:07 +02005# Copyright 2015 Google Inc.
6#
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:
Martin Rothdeed1862016-06-22 15:49:42 -060018BRANCH="cros/chromeos-2016.05"
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
29commit_message() {
30 git log -n 1 | grep "^ " | cut -c5-
31}
32
33CHID=$( commit_message | grep -i "^Change-Id: I" )
34CID=$( git log -n1 --grep "^$CHID$" --pretty=%H $BRANCH )
35GUID="$(git config user.name) <$(git config user.email)>"
36
37# TBD: Don't add Original- to empty lines, and possibly make script more
38# solid for commits with an unexpected order of meta data lines.
39
40commit_message | tac | awk '/^$/ {
41 if (end==0)
42 print "Original-Commit-Id: '"$CID"'\nSigned-off-by: '"$GUID"'";
43 end=1
44 }; {
45 if (end==0)
46 print "Original-" $0;
47 else
48 print $0;
49 }' | tac | git commit --amend -F -