1# This shell script fragment is sourced by git-rebase to implement 2# its merge-based non-interactive mode that copes well with renamed 3# files. 4# 5# Copyright (c) 2010 Junio C Hamano. 6# 7 8prec=4 9 10read_state () { 11 onto_name=$(cat "$state_dir"/onto_name)&& 12 end=$(cat "$state_dir"/end)&& 13 msgnum=$(cat "$state_dir"/msgnum) 14} 15 16continue_merge () { 17test -d"$state_dir"|| die "$state_dirdirectory does not exist" 18 19 unmerged=$(git ls-files -u) 20iftest -n"$unmerged" 21then 22echo"You still have unmerged paths in your index" 23echo"did you forget to use git add?" 24 die "$resolvemsg" 25fi 26 27 cmt=`cat "$state_dir/current"` 28if! git diff-index --quiet --ignore-submodules HEAD -- 29then 30if! git commit ${gpg_sign_opt:+"$gpg_sign_opt"}--no-verify -C"$cmt" 31then 32echo"Commit failed, please do not call\"git commit\"" 33echo"directly, but instead do one of the following: " 34 die "$resolvemsg" 35fi 36iftest -z"$GIT_QUIET" 37then 38printf"Committed: %0${prec}d "$msgnum 39fi 40echo"$cmt$(git rev-parse HEAD^0)">>"$state_dir/rewritten" 41else 42iftest -z"$GIT_QUIET" 43then 44printf"Already applied: %0${prec}d "$msgnum 45fi 46fi 47test -z"$GIT_QUIET"&& 48 GIT_PAGER='' git log --format=%s -1"$cmt" 49 50# onto the next patch: 51 msgnum=$(($msgnum + 1)) 52echo"$msgnum">"$state_dir/msgnum" 53} 54 55call_merge () { 56 cmt="$(cat "$state_dir/cmt.$1")" 57echo"$cmt">"$state_dir/current" 58 hd=$(git rev-parse --verify HEAD) 59 cmt_name=$(git symbolic-ref HEAD 2> /dev/null || echo HEAD) 60 msgnum=$(cat "$state_dir/msgnum") 61eval GITHEAD_$cmt='"${cmt_name##refs/heads/}~$(($end - $msgnum))"' 62eval GITHEAD_$hd='$onto_name' 63export GITHEAD_$cmt GITHEAD_$hd 64iftest -n"$GIT_QUIET" 65then 66 GIT_MERGE_VERBOSITY=1&&export GIT_MERGE_VERBOSITY 67fi 68test -z"$strategy"&& strategy=recursive 69eval'git-merge-$strategy'$strategy_opts'"$cmt^" -- "$hd" "$cmt"' 70 rv=$? 71case"$rv"in 720) 73unset GITHEAD_$cmt GITHEAD_$hd 74return 75;; 761) 77 git rerere $allow_rerere_autoupdate 78 die "$resolvemsg" 79;; 802) 81echo"Strategy:$strategyfailed, try another"1>&2 82 die "$resolvemsg" 83;; 84*) 85 die "Unknown exit code ($rv) from command:" \ 86"git-merge-$strategy$cmt^ -- HEAD$cmt" 87;; 88esac 89} 90 91finish_rb_merge () { 92 move_to_original_branch 93iftest -s"$state_dir"/rewritten 94then 95 git notes copy --for-rewrite=rebase <"$state_dir"/rewritten 96iftest -x"$GIT_DIR"/hooks/post-rewrite 97then 98"$GIT_DIR"/hooks/post-rewrite rebase <"$state_dir"/rewritten 99fi 100fi 101 say All done. 102} 103 104# The whole contents of this file is run by dot-sourcing it from 105# inside a shell function. It used to be that "return"s we see 106# below were not inside any function, and expected to return 107# to the function that dot-sourced us. 108# 109# However, FreeBSD /bin/sh misbehaves on such a construct and 110# continues to run the statements that follow such a "return". 111# As a work-around, we introduce an extra layer of a function 112# here, and immediately call it after defining it. 113git_rebase__merge () { 114 115case"$action"in 116continue) 117 read_state 118 continue_merge 119whiletest"$msgnum"-le"$end" 120do 121 call_merge "$msgnum" 122 continue_merge 123done 124 finish_rb_merge 125return 126;; 127skip) 128 read_state 129 git rerere clear 130 msgnum=$(($msgnum + 1)) 131whiletest"$msgnum"-le"$end" 132do 133 call_merge "$msgnum" 134 continue_merge 135done 136 finish_rb_merge 137return 138;; 139esac 140 141mkdir-p"$state_dir" 142echo"$onto_name">"$state_dir/onto_name" 143write_basic_state 144 145msgnum=0 146for cmt in`git rev-list --reverse --no-merges "$revisions"` 147do 148 msgnum=$(($msgnum + 1)) 149echo"$cmt">"$state_dir/cmt.$msgnum" 150done 151 152echo1>"$state_dir/msgnum" 153echo$msgnum>"$state_dir/end" 154 155end=$msgnum 156msgnum=1 157 158whiletest"$msgnum"-le"$end" 159do 160 call_merge "$msgnum" 161 continue_merge 162done 163 164finish_rb_merge 165 166} 167# ... and then we call the whole thing. 168git_rebase__merge