3 # Copyright (c) Josef "Jeff" Sipek, 2007
5 # Heavily based on the long removed sh version of git-cherry
13 upstream
=`git-rev-parse --verify "$1"` &&
14 ours
=`git-rev-parse --verify HEAD` || usage
22 # make sure that there are no unapplied changes
23 if ! must_commit_first
; then
24 die
"Uncommited changes detected. Refresh first."
25 elif [ `wc -l < "$applied"` -eq 0 ]; then
26 die
"Nothing to rebase. First, you need to push patches onto the stack."
29 # Note that these list commits in reverse order;
30 # not that the order in inup matters...
31 inup
=`git-rev-list ^$ours $upstream` &&
32 ours
=`git-rev-list $ours ^$limit` ||
exit
34 rebase_dir
="$GUILT_DIR/$branch/.rebase.$$"
38 # calculate the patch ids for all the commits in upstream
42 done | git-patch-id |
while read id name
; do
43 echo "$name" >> "$rebase_dir/$id"
46 # backup the status file, so we don't have to do more work to figure out all
47 # the patches that were pushed before we started rebasing
48 cp "$applied" "$rebase_dir/status"
50 echo "First, poping all patches..."
52 git-merge
--no-commit "" HEAD
$upstream > /dev
/null
2> /dev
/null
55 log
=`git-log -1 --pretty=oneline`
56 echo "HEAD is now at `echo $log | cut -c 1-7`... `echo $log | cut -c 41-`"
59 # For each previously applied patch:
60 # 1) calculate the patchid
61 # 2) if the patchid matches any of the upstream commits' patchids...
62 # a) comment out the patch from the series file
64 # a) push the patch onto the stack
67 cat "$rebase_dir/status" |
while read hash name
; do
70 cat "$GUILT_DIR/$branch/$name" | git-patch-id |
71 while read patchid commitid
; do
72 echo "Applying '$name'"
73 if [ -f "$rebase_dir/$patchid" ]; then
74 realcommit
=`head -1 "$rebase_dir/$patchid"`
75 echo "Matches upstream commit $realcommit"
76 series_rename_patch
"$name" "###rebased###$name"
77 echo "Patch removed from series."
79 # FIXME: use a guilt function instead
80 guilt-push
> /dev
/null