]> git.ipfire.org Git - thirdparty/git.git/blame - git-rebase--am.sh
Start preparation for 2.15.1
[thirdparty/git.git] / git-rebase--am.sh
CommitLineData
11d62145
JN
1# This shell script fragment is sourced by git-rebase to implement
2# its default, fast, patch-based, non-interactive mode.
46df82d5
MZ
3#
4# Copyright (c) 2010 Junio C Hamano.
5#
6
9f50d32b
KM
7# 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#
9b35cadc
EM
12# However, older (9.x) versions of FreeBSD /bin/sh misbehave on such a
13# construct and continue to run the statements that follow such a "return".
9f50d32b
KM
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
46df82d5
MZ
18case "$action" in
19continue)
3ee5e540
NV
20 git am --resolved --resolvemsg="$resolvemsg" \
21 ${gpg_sign_opt:+"$gpg_sign_opt"} &&
46df82d5 22 move_to_original_branch
a1549e10 23 return
46df82d5
MZ
24 ;;
25skip)
c5e610be 26 git am --skip --resolvemsg="$resolvemsg" &&
46df82d5 27 move_to_original_branch
a1549e10 28 return
46df82d5
MZ
29 ;;
30esac
31
b6266dc8
JK
32if 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
46df82d5 39
e481af06 40ret=0
90e1818f
NH
41if 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
b6266dc8 47 git cherry-pick ${gpg_sign_opt:+"$gpg_sign_opt"} --allow-empty \
5fb415b5 48 $allow_rerere_autoupdate --right-only "$revisions" \
1e0dacdb 49 ${restrict_revision+^$restrict_revision}
e481af06 50 ret=$?
90e1818f 51else
e481af06
AW
52 rm -f "$GIT_DIR/rebased-patches"
53
b6266dc8 54 git format-patch -k --stdout --full-index --cherry-pick --right-only \
0597ffa5 55 --src-prefix=a/ --dst-prefix=b/ --no-renames --no-cover-letter \
9eaa858e 56 $git_format_patch_opt \
1e0dacdb
JK
57 "$revisions" ${restrict_revision+^$restrict_revision} \
58 >"$GIT_DIR/rebased-patches"
e481af06
AW
59 ret=$?
60
61 if test 0 != $ret
62 then
63 rm -f "$GIT_DIR/rebased-patches"
64 case "$head_name" in
65 refs/heads/*)
66 git checkout -q "$head_name"
67 ;;
68 *)
69 git checkout -q "$orig_head"
70 ;;
71 esac
72
73 cat >&2 <<-EOF
74
75 git encountered an error while preparing the patches to replay
76 these revisions:
77
78 $revisions
79
80 As a result, git cannot rebase them.
81 EOF
60d708b2 82 return $ret
e481af06
AW
83 fi
84
3ee5e540 85 git am $git_am_opt --rebasing --resolvemsg="$resolvemsg" \
5fb415b5 86 $allow_rerere_autoupdate \
3ee5e540 87 ${gpg_sign_opt:+"$gpg_sign_opt"} <"$GIT_DIR/rebased-patches"
e481af06
AW
88 ret=$?
89
90 rm -f "$GIT_DIR/rebased-patches"
91fi
92
93if test 0 != $ret
94then
95 test -d "$state_dir" && write_basic_state
a1549e10 96 return $ret
e481af06 97fi
90e1818f 98
e481af06 99move_to_original_branch
9f50d32b
KM
100
101}
102# ... and then we call the whole thing.
103git_rebase__am