]>
Commit | Line | Data |
---|---|---|
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. | |
16 | git_rebase__am () { | |
17 | ||
46df82d5 MZ |
18 | case "$action" in |
19 | continue) | |
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 | ;; |
25 | skip) | |
c5e610be | 26 | git am --skip --resolvemsg="$resolvemsg" && |
46df82d5 | 27 | move_to_original_branch |
a1549e10 | 28 | return |
46df82d5 | 29 | ;; |
66335298 NTND |
30 | show-current-patch) |
31 | exec git am --show-current-patch | |
32 | ;; | |
46df82d5 MZ |
33 | esac |
34 | ||
b6266dc8 JK |
35 | if test -z "$rebase_root" |
36 | # this is now equivalent to ! -z "$upstream" | |
37 | then | |
38 | revisions=$upstream...$orig_head | |
39 | else | |
40 | revisions=$onto...$orig_head | |
41 | fi | |
46df82d5 | 42 | |
e481af06 | 43 | ret=0 |
90e1818f NH |
44 | if test -n "$keep_empty" |
45 | then | |
46 | # we have to do this the hard way. git format-patch completely squashes | |
47 | # empty commits and even if it didn't the format doesn't really lend | |
48 | # itself well to recording empty patches. fortunately, cherry-pick | |
49 | # makes this easy | |
b6266dc8 | 50 | git cherry-pick ${gpg_sign_opt:+"$gpg_sign_opt"} --allow-empty \ |
5fb415b5 | 51 | $allow_rerere_autoupdate --right-only "$revisions" \ |
a6c612b5 | 52 | $allow_empty_message \ |
1e0dacdb | 53 | ${restrict_revision+^$restrict_revision} |
e481af06 | 54 | ret=$? |
90e1818f | 55 | else |
e481af06 AW |
56 | rm -f "$GIT_DIR/rebased-patches" |
57 | ||
b6266dc8 | 58 | git format-patch -k --stdout --full-index --cherry-pick --right-only \ |
0597ffa5 | 59 | --src-prefix=a/ --dst-prefix=b/ --no-renames --no-cover-letter \ |
ae3b2b04 | 60 | --pretty=mboxrd \ |
9eaa858e | 61 | $git_format_patch_opt \ |
1e0dacdb JK |
62 | "$revisions" ${restrict_revision+^$restrict_revision} \ |
63 | >"$GIT_DIR/rebased-patches" | |
e481af06 AW |
64 | ret=$? |
65 | ||
66 | if test 0 != $ret | |
67 | then | |
68 | rm -f "$GIT_DIR/rebased-patches" | |
69 | case "$head_name" in | |
70 | refs/heads/*) | |
71 | git checkout -q "$head_name" | |
72 | ;; | |
73 | *) | |
74 | git checkout -q "$orig_head" | |
75 | ;; | |
76 | esac | |
77 | ||
78 | cat >&2 <<-EOF | |
79 | ||
80 | git encountered an error while preparing the patches to replay | |
81 | these revisions: | |
82 | ||
83 | $revisions | |
84 | ||
85 | As a result, git cannot rebase them. | |
86 | EOF | |
60d708b2 | 87 | return $ret |
e481af06 AW |
88 | fi |
89 | ||
3ee5e540 | 90 | git am $git_am_opt --rebasing --resolvemsg="$resolvemsg" \ |
ae3b2b04 | 91 | --patch-format=mboxrd \ |
5fb415b5 | 92 | $allow_rerere_autoupdate \ |
3ee5e540 | 93 | ${gpg_sign_opt:+"$gpg_sign_opt"} <"$GIT_DIR/rebased-patches" |
e481af06 AW |
94 | ret=$? |
95 | ||
96 | rm -f "$GIT_DIR/rebased-patches" | |
97 | fi | |
98 | ||
99 | if test 0 != $ret | |
100 | then | |
101 | test -d "$state_dir" && write_basic_state | |
a1549e10 | 102 | return $ret |
e481af06 | 103 | fi |
90e1818f | 104 | |
e481af06 | 105 | move_to_original_branch |
9f50d32b KM |
106 | |
107 | } | |
108 | # ... and then we call the whole thing. | |
109 | git_rebase__am |