1# This shell script fragment is sourced by git-rebase to implement 2# its default, fast, patch-based, non-interactive mode. 3# 4# Copyright (c) 2010 Junio C Hamano. 5# 6 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# 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 18case "$action" in 19continue) 20 git am --resolved --resolvemsg="$resolvemsg" \ 21 ${gpg_sign_opt:+"$gpg_sign_opt"} && 22 move_to_original_branch 23 return 24 ;; 25skip) 26 git am --skip --resolvemsg="$resolvemsg" && 27 move_to_original_branch 28 return 29 ;; 30esac 31 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 39 40ret=0 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 47 git cherry-pick ${gpg_sign_opt:+"$gpg_sign_opt"} --allow-empty \ 48 --right-only "$revisions" 49 ret=$? 50else 51 rm -f "$GIT_DIR/rebased-patches" 52 53 git format-patch -k --stdout --full-index --cherry-pick --right-only \ 54 --src-prefix=a/ --dst-prefix=b/ --no-renames --no-cover-letter \ 55 "$revisions" >"$GIT_DIR/rebased-patches" 56 ret=$? 57 58 if test 0 != $ret 59 then 60 rm -f "$GIT_DIR/rebased-patches" 61 case "$head_name" in 62 refs/heads/*) 63 git checkout -q "$head_name" 64 ;; 65 *) 66 git checkout -q "$orig_head" 67 ;; 68 esac 69 70 cat >&2 <<-EOF 71 72 git encountered an error while preparing the patches to replay 73 these revisions: 74 75 $revisions 76 77 As a result, git cannot rebase them. 78 EOF 79 return $? 80 fi 81 82 git am $git_am_opt --rebasing --resolvemsg="$resolvemsg" \ 83 ${gpg_sign_opt:+"$gpg_sign_opt"} <"$GIT_DIR/rebased-patches" 84 ret=$? 85 86 rm -f "$GIT_DIR/rebased-patches" 87fi 88 89if test 0 != $ret 90then 91 test -d "$state_dir" && write_basic_state 92 return $ret 93fi 94 95move_to_original_branch 96 97} 98# ... and then we call the whole thing. 99git_rebase__am