Patrick Georgi | 1707a164c | 2015-04-03 17:06:48 -0700 | [diff] [blame] | 1 | #!/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 Georgi | bf8589e | 2015-08-28 20:27:28 +0200 | [diff] [blame^] | 16 | BRANCH="cros/chromeos-2015.07" |
Patrick Georgi | 1707a164c | 2015-04-03 17:06:48 -0700 | [diff] [blame] | 17 | |
| 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 | |
| 27 | commit_message() { |
| 28 | git log -n 1 | grep "^ " | cut -c5- |
| 29 | } |
| 30 | |
| 31 | CHID=$( commit_message | grep -i "^Change-Id: I" ) |
| 32 | CID=$( git log -n1 --grep "^$CHID$" --pretty=%H $BRANCH ) |
| 33 | GUID="$(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 | |
| 38 | commit_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 - |