1 # This shell script fragment is sourced by git-rebase to implement
2 # its merge-based non-interactive mode that copes well with renamed
5 # Copyright (c) 2010 Junio C Hamano.
11 onto_name
=$
(cat "$state_dir"/onto_name
) &&
12 end
=$
(cat "$state_dir"/end
) &&
13 msgnum
=$
(cat "$state_dir"/msgnum
)
17 test -d "$state_dir" || die
"$state_dir directory does not exist"
19 unmerged
=$
(git ls-files
-u)
20 if test -n "$unmerged"
22 echo "You still have unmerged paths in your index"
23 echo "did you forget to use git add?"
27 cmt
=$
(cat "$state_dir/current")
28 if ! git diff-index
--quiet --ignore-submodules HEAD
--
30 if ! git commit
${gpg_sign_opt:+"$gpg_sign_opt"} --no-verify -C "$cmt"
32 echo "Commit failed, please do not call \"git commit\""
33 echo "directly, but instead do one of the following: "
36 if test -z "$GIT_QUIET"
38 printf "Committed: %0${prec}d " $msgnum
40 echo "$cmt $(git rev-parse HEAD^0)" >> "$state_dir/rewritten"
42 if test -z "$GIT_QUIET"
44 printf "Already applied: %0${prec}d " $msgnum
47 test -z "$GIT_QUIET" &&
48 GIT_PAGER
='' git log
--format=%s
-1 "$cmt"
50 # onto the next patch:
51 msgnum
=$
(($msgnum + 1))
52 echo "$msgnum" >"$state_dir/msgnum"
57 echo "$msgnum" >"$state_dir/msgnum"
58 cmt
="$(cat "$state_dir/cmt.
$msgnum")"
59 echo "$cmt" > "$state_dir/current"
60 hd
=$
(git rev-parse
--verify HEAD
)
61 cmt_name
=$
(git symbolic-ref HEAD
2> /dev
/null ||
echo HEAD
)
62 eval GITHEAD_
$cmt='"${cmt_name##refs/heads/}~$(($end - $msgnum))"'
63 eval GITHEAD_
$hd='$onto_name'
64 export GITHEAD_
$cmt GITHEAD_
$hd
65 if test -n "$GIT_QUIET"
67 GIT_MERGE_VERBOSITY
=1 && export GIT_MERGE_VERBOSITY
69 test -z "$strategy" && strategy
=recursive
70 eval 'git-merge-$strategy' $strategy_opts '"$cmt^" -- "$hd" "$cmt"'
74 unset GITHEAD_
$cmt GITHEAD_
$hd
78 git rerere
$allow_rerere_autoupdate
82 echo "Strategy: $strategy failed, try another" 1>&2
86 die
"Unknown exit code ($rv) from command:" \
87 "git-merge-$strategy $cmt^ -- HEAD $cmt"
93 move_to_original_branch
94 if test -s "$state_dir"/rewritten
96 git notes copy
--for-rewrite=rebase
<"$state_dir"/rewritten
97 if test -x "$GIT_DIR"/hooks
/post-rewrite
99 "$GIT_DIR"/hooks
/post-rewrite rebase
<"$state_dir"/rewritten
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.
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.
114 git_rebase__merge
() {
120 while test "$msgnum" -le "$end"
131 msgnum
=$
(($msgnum + 1))
132 while test "$msgnum" -le "$end"
142 mkdir
-p "$state_dir"
143 echo "$onto_name" > "$state_dir/onto_name"
147 for cmt
in $
(git rev-list
--reverse --no-merges "$revisions")
149 msgnum
=$
(($msgnum + 1))
150 echo "$cmt" > "$state_dir/cmt.$msgnum"
153 echo 1 >"$state_dir/msgnum"
154 echo $msgnum >"$state_dir/end"
159 while test "$msgnum" -le "$end"
168 # ... and then we call the whole thing.