worktree prune: improve prune logic when worktree is moved
[alt-git.git] / git-rebase--am.sh
blob0f78051792fae93f7966c2a3f9fc670b4fca9188
1 # This shell script fragment is sourced by git-rebase to implement
2 # its default, fast, patch-based, non-interactive mode.
4 # Copyright (c) 2010 Junio C Hamano.
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.
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".
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 () {
18 case "$action" in
19 continue)
20 git am --resolved --resolvemsg="$resolvemsg" \
21 ${gpg_sign_opt:+"$gpg_sign_opt"} &&
22 move_to_original_branch
23 return
25 skip)
26 git am --skip --resolvemsg="$resolvemsg" &&
27 move_to_original_branch
28 return
30 esac
32 if test -z "$rebase_root"
33 # this is now equivalent to ! -z "$upstream"
34 then
35 revisions=$upstream...$orig_head
36 else
37 revisions=$onto...$orig_head
40 ret=0
41 if test -n "$keep_empty"
42 then
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
47 git cherry-pick ${gpg_sign_opt:+"$gpg_sign_opt"} --allow-empty \
48 $allow_rerere_autoupdate --right-only "$revisions" \
49 $allow_empty_message \
50 ${restrict_revision+^$restrict_revision}
51 ret=$?
52 else
53 rm -f "$GIT_DIR/rebased-patches"
55 git format-patch -k --stdout --full-index --cherry-pick --right-only \
56 --src-prefix=a/ --dst-prefix=b/ --no-renames --no-cover-letter \
57 --pretty=mboxrd \
58 $git_format_patch_opt \
59 "$revisions" ${restrict_revision+^$restrict_revision} \
60 >"$GIT_DIR/rebased-patches"
61 ret=$?
63 if test 0 != $ret
64 then
65 rm -f "$GIT_DIR/rebased-patches"
66 case "$head_name" in
67 refs/heads/*)
68 git checkout -q "$head_name"
71 git checkout -q "$orig_head"
73 esac
75 cat >&2 <<-EOF
77 git encountered an error while preparing the patches to replay
78 these revisions:
80 $revisions
82 As a result, git cannot rebase them.
83 EOF
84 return $ret
87 git am $git_am_opt --rebasing --resolvemsg="$resolvemsg" \
88 --patch-format=mboxrd \
89 $allow_rerere_autoupdate \
90 ${gpg_sign_opt:+"$gpg_sign_opt"} <"$GIT_DIR/rebased-patches"
91 ret=$?
93 rm -f "$GIT_DIR/rebased-patches"
96 if test 0 != $ret
97 then
98 test -d "$state_dir" && write_basic_state
99 return $ret
102 move_to_original_branch
105 # ... and then we call the whole thing.
106 git_rebase__am