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"} $allow_empty_message \ 31--no-verify -C"$cmt" 32then 33echo"Commit failed, please do not call\"git commit\"" 34echo"directly, but instead do one of the following: " 35 die "$resolvemsg" 36fi 37iftest -z"$GIT_QUIET" 38then 39printf"Committed: %0${prec}d "$msgnum 40fi 41echo"$cmt$(git rev-parse HEAD^0)">>"$state_dir/rewritten" 42else 43iftest -z"$GIT_QUIET" 44then 45printf"Already applied: %0${prec}d "$msgnum 46fi 47fi 48test -z"$GIT_QUIET"&& 49 GIT_PAGER='' git log --format=%s -1"$cmt" 50 51# onto the next patch: 52 msgnum=$(($msgnum + 1)) 53echo"$msgnum">"$state_dir/msgnum" 54} 55 56call_merge () { 57 msgnum="$1" 58echo"$msgnum">"$state_dir/msgnum" 59 cmt="$(cat "$state_dir/cmt.$msgnum")" 60echo"$cmt">"$state_dir/current" 61 git update-ref REBASE_HEAD "$cmt" 62 hd=$(git rev-parse --verify HEAD) 63 cmt_name=$(git symbolic-ref HEAD 2> /dev/null || echo HEAD) 64eval GITHEAD_$cmt='"${cmt_name##refs/heads/}~$(($end - $msgnum))"' 65eval GITHEAD_$hd='$onto_name' 66export GITHEAD_$cmt GITHEAD_$hd 67iftest -n"$GIT_QUIET" 68then 69 GIT_MERGE_VERBOSITY=1&&export GIT_MERGE_VERBOSITY 70fi 71test -z"$strategy"&& strategy=recursive 72# If cmt doesn't have a parent, don't include it as a base 73 base=$(git rev-parse --verify --quiet $cmt^) 74eval'git-merge-$strategy'$strategy_opts $base' -- "$hd" "$cmt"' 75 rv=$? 76case"$rv"in 770) 78unset GITHEAD_$cmt GITHEAD_$hd 79return 80;; 811) 82 git rerere $allow_rerere_autoupdate 83 die "$resolvemsg" 84;; 852) 86echo"Strategy:$strategyfailed, try another"1>&2 87 die "$resolvemsg" 88;; 89*) 90 die "Unknown exit code ($rv) from command:" \ 91"git-merge-$strategy$cmt^ -- HEAD$cmt" 92;; 93esac 94} 95 96finish_rb_merge () { 97 move_to_original_branch 98iftest -s"$state_dir"/rewritten 99then 100 git notes copy --for-rewrite=rebase <"$state_dir"/rewritten 101 hook="$(git rev-parse --git-path hooks/post-rewrite)" 102test -x"$hook"&&"$hook" rebase <"$state_dir"/rewritten 103fi 104 say All done. 105} 106 107# The whole contents of this file is run by dot-sourcing it from 108# inside a shell function. It used to be that "return"s we see 109# below were not inside any function, and expected to return 110# to the function that dot-sourced us. 111# 112# However, older (9.x) versions of FreeBSD /bin/sh misbehave on such a 113# construct and continue to run the statements that follow such a "return". 114# As a work-around, we introduce an extra layer of a function 115# here, and immediately call it after defining it. 116git_rebase__merge () { 117 118case"$action"in 119continue) 120 read_state 121 continue_merge 122whiletest"$msgnum"-le"$end" 123do 124 call_merge "$msgnum" 125 continue_merge 126done 127 finish_rb_merge 128return 129;; 130skip) 131 read_state 132 git rerere clear 133 msgnum=$(($msgnum + 1)) 134whiletest"$msgnum"-le"$end" 135do 136 call_merge "$msgnum" 137 continue_merge 138done 139 finish_rb_merge 140return 141;; 142show-current-patch) 143exec git show REBASE_HEAD -- 144;; 145esac 146 147mkdir-p"$state_dir" 148echo"$onto_name">"$state_dir/onto_name" 149write_basic_state 150rm-f"$(git rev-parse --git-path REBASE_HEAD)" 151 152msgnum=0 153for cmt in$(git rev-list --reverse --no-merges "$revisions") 154do 155 msgnum=$(($msgnum + 1)) 156echo"$cmt">"$state_dir/cmt.$msgnum" 157done 158 159echo1>"$state_dir/msgnum" 160echo$msgnum>"$state_dir/end" 161 162end=$msgnum 163msgnum=1 164 165whiletest"$msgnum"-le"$end" 166do 167 call_merge "$msgnum" 168 continue_merge 169done 170 171finish_rb_merge 172 173} 174# ... and then we call the whole thing. 175git_rebase__merge