Patrick Georgi | 1707a164c | 2015-04-03 17:06:48 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | # rebase.sh - rebase helper script |
| 4 | # |
Patrick Georgi | 4003283 | 2016-10-24 11:58:07 +0200 | [diff] [blame] | 5 | # Copyright 2015 Google Inc. |
| 6 | # |
Patrick Georgi | 1707a164c | 2015-04-03 17:06:48 -0700 | [diff] [blame] | 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. |
| 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 Roth | deed186 | 2016-06-22 15:49:42 -0600 | [diff] [blame] | 18 | BRANCH="cros/chromeos-2016.05" |
Patrick Georgi | 1707a164c | 2015-04-03 17:06:48 -0700 | [diff] [blame] | 19 | |
| 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 | |
| 29 | commit_message() { |
| 30 | git log -n 1 | grep "^ " | cut -c5- |
| 31 | } |
| 32 | |
| 33 | CHID=$( commit_message | grep -i "^Change-Id: I" ) |
| 34 | CID=$( git log -n1 --grep "^$CHID$" --pretty=%H $BRANCH ) |
| 35 | GUID="$(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 | |
| 40 | commit_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 - |