| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
set -e |
| 4 |
|
| 5 |
if [ -z "$*" ] ; then |
| 6 |
echo "Usage: $0 [commit [commit ..]]" |
| 7 |
exit 1 |
| 8 |
fi |
| 9 |
|
| 10 |
|
| 11 |
curbranch=$(git rev-parse --abbrev-ref HEAD) |
| 12 |
|
| 13 |
# assert we got a branch |
| 14 |
[ -n "$curbranch" ] |
| 15 |
|
| 16 |
if [ $curbranch = HEAD ] ; then |
| 17 |
echo "You are not currently on a branch, cannot cherry-pick" |
| 18 |
exit 1 |
| 19 |
fi |
| 20 |
|
| 21 |
case $curbranch in |
| 22 |
patch-queue/*) |
| 23 |
debbranch=${curbranch/patch-queue\/} |
| 24 |
pqbranch=$curbranch |
| 25 |
;; |
| 26 |
*) |
| 27 |
debbranch=$curbranch |
| 28 |
pqbranch=patch-queue/$curbranch |
| 29 |
;; |
| 30 |
esac |
| 31 |
|
| 32 |
commits=$(git rev-parse "$@") |
| 33 |
|
| 34 |
if git rev-parse $pqbranch &>/dev/null ; then |
| 35 |
echo |
| 36 |
echo "Will recreate patch-queue branch $pqbranch" |
| 37 |
echo "It was pointing to" $(git rev-parse $pqbranch) |
| 38 |
echo |
| 39 |
fi |
| 40 |
|
| 41 |
gbp pq import --force |
| 42 |
|
| 43 |
echo "Cherry-picking the following commits:" |
| 44 |
echo "$commits" |
| 45 |
|
| 46 |
picks=$(echo "$commits" | xargs echo exec git cherry-pick -x --no-edit --commit) |
| 47 |
|
| 48 |
# find the first debian commit |
| 49 |
firstdebian=$(git log -i --grep "topic.*debian" --pretty=%h --reverse $debbranch..$pqbranch | head -1) |
| 50 |
|
| 51 |
sedexpr="/$firstdebian/i$picks" |
| 52 |
|
| 53 |
GIT_EDITOR="sed -i -e '$sedexpr'" git rebase --interactive --no-autosquash $debbranch |