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, 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. 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 23return 24;; 25skip) 26 git am --skip --resolvemsg="$resolvemsg"&& 27 move_to_original_branch 28return 29;; 30show-current-patch) 31exec git am --show-current-patch 32;; 33esac 34 35iftest -z"$rebase_root" 36# this is now equivalent to ! -z "$upstream" 37then 38 revisions=$upstream...$orig_head 39else 40 revisions=$onto...$orig_head 41fi 42 43ret=0 44iftest -n"$keep_empty" 45then 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 50 git cherry-pick${gpg_sign_opt:+"$gpg_sign_opt"}--allow-empty \ 51$allow_rerere_autoupdate--right-only"$revisions" \ 52${restrict_revision+^$restrict_revision} 53 ret=$? 54else 55rm-f"$GIT_DIR/rebased-patches" 56 57 git format-patch -k --stdout --full-index --cherry-pick --right-only \ 58--src-prefix=a/--dst-prefix=b/--no-renames --no-cover-letter \ 59--pretty=mboxrd \ 60$git_format_patch_opt \ 61"$revisions"${restrict_revision+^$restrict_revision} \ 62>"$GIT_DIR/rebased-patches" 63 ret=$? 64 65iftest0!=$ret 66then 67rm-f"$GIT_DIR/rebased-patches" 68case"$head_name"in 69 refs/heads/*) 70 git checkout -q"$head_name" 71;; 72*) 73 git checkout -q"$orig_head" 74;; 75esac 76 77cat>&2<<-EOF 78 79 git encountered an error while preparing the patches to replay 80 these revisions: 81 82$revisions 83 84 As a result, git cannot rebase them. 85 EOF 86return$ret 87fi 88 89 git am $git_am_opt--rebasing --resolvemsg="$resolvemsg" \ 90--patch-format=mboxrd \ 91$allow_rerere_autoupdate \ 92${gpg_sign_opt:+"$gpg_sign_opt"}<"$GIT_DIR/rebased-patches" 93 ret=$? 94 95rm-f"$GIT_DIR/rebased-patches" 96fi 97 98iftest0!=$ret 99then 100test -d"$state_dir"&& write_basic_state 101return$ret 102fi 103 104move_to_original_branch 105 106} 107# ... and then we call the whole thing. 108git_rebase__am