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