blob: 34e3102fcbfa64ec101c1fe009c9b14a5976e4c2 [file] [log] [blame]
Martin von Zweigbergk46df82d2011-02-06 13:43:48 -05001#!/bin/sh
2#
3# Copyright (c) 2010 Junio C Hamano.
4#
5
Martin von Zweigbergk46df82d2011-02-06 13:43:48 -05006case "$action" in
7continue)
Martin von Zweigbergkc5e610b2011-02-06 13:43:58 -05008 git am --resolved --resolvemsg="$resolvemsg" &&
Martin von Zweigbergk46df82d2011-02-06 13:43:48 -05009 move_to_original_branch
Ramkumar Ramachandraa1549e12013-05-12 17:26:38 +053010 return
Martin von Zweigbergk46df82d2011-02-06 13:43:48 -050011 ;;
12skip)
Martin von Zweigbergkc5e610b2011-02-06 13:43:58 -050013 git am --skip --resolvemsg="$resolvemsg" &&
Martin von Zweigbergk46df82d2011-02-06 13:43:48 -050014 move_to_original_branch
Ramkumar Ramachandraa1549e12013-05-12 17:26:38 +053015 return
Martin von Zweigbergk46df82d2011-02-06 13:43:48 -050016 ;;
17esac
18
19test -n "$rebase_root" && root_flag=--root
20
Andrew Wonge481af02012-10-10 23:54:03 -040021ret=0
Neil Horman90e18182012-04-20 10:36:17 -040022if test -n "$keep_empty"
23then
24 # we have to do this the hard way. git format-patch completely squashes
25 # empty commits and even if it didn't the format doesn't really lend
26 # itself well to recording empty patches. fortunately, cherry-pick
27 # makes this easy
28 git cherry-pick --allow-empty "$revisions"
Andrew Wonge481af02012-10-10 23:54:03 -040029 ret=$?
Neil Horman90e18182012-04-20 10:36:17 -040030else
Andrew Wonge481af02012-10-10 23:54:03 -040031 rm -f "$GIT_DIR/rebased-patches"
32
Neil Horman90e18182012-04-20 10:36:17 -040033 git format-patch -k --stdout --full-index --ignore-if-in-upstream \
Felipe Contreras0597ffa2013-04-14 17:27:04 -050034 --src-prefix=a/ --dst-prefix=b/ --no-renames --no-cover-letter \
35 $root_flag "$revisions" >"$GIT_DIR/rebased-patches"
Andrew Wonge481af02012-10-10 23:54:03 -040036 ret=$?
Neil Horman90e18182012-04-20 10:36:17 -040037
Andrew Wonge481af02012-10-10 23:54:03 -040038 if test 0 != $ret
39 then
40 rm -f "$GIT_DIR/rebased-patches"
41 case "$head_name" in
42 refs/heads/*)
43 git checkout -q "$head_name"
44 ;;
45 *)
46 git checkout -q "$orig_head"
47 ;;
48 esac
49
50 cat >&2 <<-EOF
51
52 git encountered an error while preparing the patches to replay
53 these revisions:
54
55 $revisions
56
57 As a result, git cannot rebase them.
58 EOF
Ramkumar Ramachandraa1549e12013-05-12 17:26:38 +053059 return $?
Andrew Wonge481af02012-10-10 23:54:03 -040060 fi
61
62 git am $git_am_opt --rebasing --resolvemsg="$resolvemsg" <"$GIT_DIR/rebased-patches"
63 ret=$?
64
65 rm -f "$GIT_DIR/rebased-patches"
66fi
67
68if test 0 != $ret
69then
70 test -d "$state_dir" && write_basic_state
Ramkumar Ramachandraa1549e12013-05-12 17:26:38 +053071 return $ret
Andrew Wonge481af02012-10-10 23:54:03 -040072fi
73
74move_to_original_branch