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 msgnum="$1" 57echo"$msgnum">"$state_dir/msgnum" 58 cmt="$(cat "$state_dir/cmt.$msgnum")" 59echo"$cmt">"$state_dir/current" 60 hd=$(git rev-parse --verify HEAD) 61 cmt_name=$(git symbolic-ref HEAD 2> /dev/null || echo HEAD) 62eval GITHEAD_$cmt='"${cmt_name##refs/heads/}~$(($end - $msgnum))"' 63eval GITHEAD_$hd='$onto_name' 64export GITHEAD_$cmt GITHEAD_$hd 65iftest -n"$GIT_QUIET" 66then 67 GIT_MERGE_VERBOSITY=1&&export GIT_MERGE_VERBOSITY 68fi 69test -z"$strategy"&& strategy=recursive 70eval'git-merge-$strategy'$strategy_opts'"$cmt^" -- "$hd" "$cmt"' 71 rv=$? 72case"$rv"in 730) 74unset GITHEAD_$cmt GITHEAD_$hd 75return 76;; 771) 78 git rerere $allow_rerere_autoupdate 79 die "$resolvemsg" 80;; 812) 82echo"Strategy:$strategyfailed, try another"1>&2 83 die "$resolvemsg" 84;; 85*) 86 die "Unknown exit code ($rv) from command:" \ 87"git-merge-$strategy$cmt^ -- HEAD$cmt" 88;; 89esac 90} 91 92finish_rb_merge () { 93 move_to_original_branch 94iftest -s"$state_dir"/rewritten 95then 96 git notes copy --for-rewrite=rebase <"$state_dir"/rewritten 97iftest -x"$GIT_DIR"/hooks/post-rewrite 98then 99"$GIT_DIR"/hooks/post-rewrite rebase <"$state_dir"/rewritten 100fi 101fi 102 say All done. 103} 104 105# The whole contents of this file is run by dot-sourcing it from 106# inside a shell function. It used to be that "return"s we see 107# below were not inside any function, and expected to return 108# to the function that dot-sourced us. 109# 110# However, FreeBSD /bin/sh misbehaves on such a construct and 111# continues to run the statements that follow such a "return". 112# As a work-around, we introduce an extra layer of a function 113# here, and immediately call it after defining it. 114git_rebase__merge () { 115 116case"$action"in 117continue) 118 read_state 119 continue_merge 120whiletest"$msgnum"-le"$end" 121do 122 call_merge "$msgnum" 123 continue_merge 124done 125 finish_rb_merge 126return 127;; 128skip) 129 read_state 130 git rerere clear 131 msgnum=$(($msgnum + 1)) 132whiletest"$msgnum"-le"$end" 133do 134 call_merge "$msgnum" 135 continue_merge 136done 137 finish_rb_merge 138return 139;; 140esac 141 142mkdir-p"$state_dir" 143echo"$onto_name">"$state_dir/onto_name" 144write_basic_state 145 146msgnum=0 147for cmt in$(git rev-list --reverse --no-merges "$revisions") 148do 149 msgnum=$(($msgnum + 1)) 150echo"$cmt">"$state_dir/cmt.$msgnum" 151done 152 153echo1>"$state_dir/msgnum" 154echo$msgnum>"$state_dir/end" 155 156end=$msgnum 157msgnum=1 158 159whiletest"$msgnum"-le"$end" 160do 161 call_merge "$msgnum" 162 continue_merge 163done 164 165finish_rb_merge 166 167} 168# ... and then we call the whole thing. 169git_rebase__merge