3 # Copyright (c) Josef "Jeff" Sipek, 2007
5 # Heavily based on the long removed sh version of git-cherry
11 echo "Beware, rebase is currently EXPERIMENTAL."
12 echo "In other words, it might eat your patches."
13 echo -n "Do you wish to proceed? [y/N] "
15 if [ "$n" != "y" -a "$n" != "Y" ]; then
22 upstream
=`git rev-parse --verify "$1"` &&
23 ours
=`git rev-parse --verify HEAD` || usage
31 # make sure that there are no unapplied changes
32 if ! must_commit_first
; then
33 die
"Uncommited changes detected. Refresh first."
34 elif [ `wc -l < "$applied"` -eq 0 ]; then
35 die
"Nothing to rebase. First, you need to push patches onto the stack."
38 # Note that these list commits in reverse order;
39 # not that the order in inup matters...
40 inup
=`git rev-list ^$ours $upstream` &&
41 ours
=`git rev-list $ours ^$limit` ||
exit
43 rebase_dir
="$GUILT_DIR/$branch/.rebase.$$"
47 # calculate the patch ids for all the commits in upstream
51 done | git patch-id |
while read id name
; do
52 echo "$name" >> "$rebase_dir/$id"
55 # backup the status file, so we don't have to do more work to figure out all
56 # the patches that were pushed before we started rebasing
57 cp "$applied" "$rebase_dir/status"
59 echo "First, poping all patches..."
61 git merge
--no-commit $upstream > /dev
/null
2> /dev
/null
64 log
=`git log -1 --pretty=oneline`
65 echo "HEAD is now at `echo $log | cut -c 1-7`... `echo "$log" | cut -c 41-`"
68 # For each previously applied patch:
69 # 1) calculate the patchid
70 # 2) if the patchid matches any of the upstream commits' patchids...
71 # a) comment out the patch from the series file
73 # a) push the patch onto the stack
76 cat "$rebase_dir/status" |
while read hash name
; do
79 cat "$GUILT_DIR/$branch/$name" | git patch-id |
80 while read patchid commitid
; do
81 echo "Applying '$name'"
82 if [ -f "$rebase_dir/$patchid" ]; then
83 realcommit
=`head -1 "$rebase_dir/$patchid"`
84 echo "Matches upstream commit $realcommit"
85 series_rename_patch
"$name" "###rebased###$name"
86 echo "Patch removed from series."
88 # FIXME: use a guilt function instead
89 guilt-push
> /dev
/null