blob: 9ae898bc1d7d301983893e6df404c696b80a87f5 [file] [log] [blame]
Jonathan Nieder11d62142013-11-25 13:03:52 -08001# This shell script fragment is sourced by git-rebase to implement
2# its default, fast, patch-based, non-interactive mode.
Martin von Zweigbergk46df82d2011-02-06 13:43:48 -05003#
4# Copyright (c) 2010 Junio C Hamano.
5#
6
Kyle J. McKay9f50d322014-04-11 01:28:17 -07007# The whole contents of this file is run by dot-sourcing it from
8# inside a shell function. It used to be that "return"s we see
9# below were not inside any function, and expected to return
10# to the function that dot-sourced us.
11#
12# However, FreeBSD /bin/sh misbehaves on such a construct and
13# continues to run the statements that follow such a "return".
14# As a work-around, we introduce an extra layer of a function
15# here, and immediately call it after defining it.
16git_rebase__am () {
17
Martin von Zweigbergk46df82d2011-02-06 13:43:48 -050018case "$action" in
19continue)
Nicolas Vigier3ee5e542014-02-10 01:03:37 +000020 git am --resolved --resolvemsg="$resolvemsg" \
21 ${gpg_sign_opt:+"$gpg_sign_opt"} &&
Martin von Zweigbergk46df82d2011-02-06 13:43:48 -050022 move_to_original_branch
Ramkumar Ramachandraa1549e12013-05-12 17:26:38 +053023 return
Martin von Zweigbergk46df82d2011-02-06 13:43:48 -050024 ;;
25skip)
Martin von Zweigbergkc5e610b2011-02-06 13:43:58 -050026 git am --skip --resolvemsg="$resolvemsg" &&
Martin von Zweigbergk46df82d2011-02-06 13:43:48 -050027 move_to_original_branch
Ramkumar Ramachandraa1549e12013-05-12 17:26:38 +053028 return
Martin von Zweigbergk46df82d2011-02-06 13:43:48 -050029 ;;
30esac
31
John Keepingb6266dc2014-07-15 20:14:02 +010032if test -z "$rebase_root"
33 # this is now equivalent to ! -z "$upstream"
34then
35 revisions=$upstream...$orig_head
36else
37 revisions=$onto...$orig_head
38fi
Martin von Zweigbergk46df82d2011-02-06 13:43:48 -050039
Andrew Wonge481af02012-10-10 23:54:03 -040040ret=0
Neil Horman90e18182012-04-20 10:36:17 -040041if test -n "$keep_empty"
42then
43 # we have to do this the hard way. git format-patch completely squashes
44 # empty commits and even if it didn't the format doesn't really lend
45 # itself well to recording empty patches. fortunately, cherry-pick
46 # makes this easy
John Keepingb6266dc2014-07-15 20:14:02 +010047 git cherry-pick ${gpg_sign_opt:+"$gpg_sign_opt"} --allow-empty \
John Keeping1e0dacd2014-07-16 20:23:49 +010048 --right-only "$revisions" \
49 ${restrict_revision+^$restrict_revision}
Andrew Wonge481af02012-10-10 23:54:03 -040050 ret=$?
Neil Horman90e18182012-04-20 10:36:17 -040051else
Andrew Wonge481af02012-10-10 23:54:03 -040052 rm -f "$GIT_DIR/rebased-patches"
53
John Keepingb6266dc2014-07-15 20:14:02 +010054 git format-patch -k --stdout --full-index --cherry-pick --right-only \
Felipe Contreras0597ffa2013-04-14 17:27:04 -050055 --src-prefix=a/ --dst-prefix=b/ --no-renames --no-cover-letter \
John Keeping1e0dacd2014-07-16 20:23:49 +010056 "$revisions" ${restrict_revision+^$restrict_revision} \
57 >"$GIT_DIR/rebased-patches"
Andrew Wonge481af02012-10-10 23:54:03 -040058 ret=$?
Neil Horman90e18182012-04-20 10:36:17 -040059
Andrew Wonge481af02012-10-10 23:54:03 -040060 if test 0 != $ret
61 then
62 rm -f "$GIT_DIR/rebased-patches"
63 case "$head_name" in
64 refs/heads/*)
65 git checkout -q "$head_name"
66 ;;
67 *)
68 git checkout -q "$orig_head"
69 ;;
70 esac
71
72 cat >&2 <<-EOF
73
74 git encountered an error while preparing the patches to replay
75 these revisions:
76
77 $revisions
78
79 As a result, git cannot rebase them.
80 EOF
Clemens Buchacher60d708b2015-07-02 11:11:33 +020081 return $ret
Andrew Wonge481af02012-10-10 23:54:03 -040082 fi
83
Nicolas Vigier3ee5e542014-02-10 01:03:37 +000084 git am $git_am_opt --rebasing --resolvemsg="$resolvemsg" \
85 ${gpg_sign_opt:+"$gpg_sign_opt"} <"$GIT_DIR/rebased-patches"
Andrew Wonge481af02012-10-10 23:54:03 -040086 ret=$?
87
88 rm -f "$GIT_DIR/rebased-patches"
89fi
90
91if test 0 != $ret
92then
93 test -d "$state_dir" && write_basic_state
Ramkumar Ramachandraa1549e12013-05-12 17:26:38 +053094 return $ret
Andrew Wonge481af02012-10-10 23:54:03 -040095fi
96
97move_to_original_branch
Kyle J. McKay9f50d322014-04-11 01:28:17 -070098
99}
100# ... and then we call the whole thing.
101git_rebase__am