t/helper: merge test-wildmatch into test-tool
[alt-git.git] / git-rebase--merge.sh
blobceb715453cc9eba0b6e91abfd2ea3863e74f3e05
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.
5 # Copyright (c) 2010 Junio C Hamano.
8 prec=4
10 read_state () {
11 onto_name=$(cat "$state_dir"/onto_name) &&
12 end=$(cat "$state_dir"/end) &&
13 msgnum=$(cat "$state_dir"/msgnum)
16 continue_merge () {
17 test -d "$state_dir" || die "$state_dir directory does not exist"
19 unmerged=$(git ls-files -u)
20 if test -n "$unmerged"
21 then
22 echo "You still have unmerged paths in your index"
23 echo "did you forget to use git add?"
24 die "$resolvemsg"
27 cmt=$(cat "$state_dir/current")
28 if ! git diff-index --quiet --ignore-submodules HEAD --
29 then
30 if ! git commit ${gpg_sign_opt:+"$gpg_sign_opt"} $allow_empty_message \
31 --no-verify -C "$cmt"
32 then
33 echo "Commit failed, please do not call \"git commit\""
34 echo "directly, but instead do one of the following: "
35 die "$resolvemsg"
37 if test -z "$GIT_QUIET"
38 then
39 printf "Committed: %0${prec}d " $msgnum
41 echo "$cmt $(git rev-parse HEAD^0)" >> "$state_dir/rewritten"
42 else
43 if test -z "$GIT_QUIET"
44 then
45 printf "Already applied: %0${prec}d " $msgnum
48 test -z "$GIT_QUIET" &&
49 GIT_PAGER='' git log --format=%s -1 "$cmt"
51 # onto the next patch:
52 msgnum=$(($msgnum + 1))
53 echo "$msgnum" >"$state_dir/msgnum"
56 call_merge () {
57 msgnum="$1"
58 echo "$msgnum" >"$state_dir/msgnum"
59 cmt="$(cat "$state_dir/cmt.$msgnum")"
60 echo "$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)
64 eval GITHEAD_$cmt='"${cmt_name##refs/heads/}~$(($end - $msgnum))"'
65 eval GITHEAD_$hd='$onto_name'
66 export GITHEAD_$cmt GITHEAD_$hd
67 if test -n "$GIT_QUIET"
68 then
69 GIT_MERGE_VERBOSITY=1 && export GIT_MERGE_VERBOSITY
71 test -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^)
74 eval 'git-merge-$strategy' $strategy_opts $base ' -- "$hd" "$cmt"'
75 rv=$?
76 case "$rv" in
78 unset GITHEAD_$cmt GITHEAD_$hd
79 return
82 git rerere $allow_rerere_autoupdate
83 die "$resolvemsg"
86 echo "Strategy: $strategy failed, try another" 1>&2
87 die "$resolvemsg"
90 die "Unknown exit code ($rv) from command:" \
91 "git-merge-$strategy $cmt^ -- HEAD $cmt"
93 esac
96 finish_rb_merge () {
97 move_to_original_branch
98 if test -s "$state_dir"/rewritten
99 then
100 git notes copy --for-rewrite=rebase <"$state_dir"/rewritten
101 hook="$(git rev-parse --git-path hooks/post-rewrite)"
102 test -x "$hook" && "$hook" rebase <"$state_dir"/rewritten
104 say All done.
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.
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.
116 git_rebase__merge () {
118 case "$action" in
119 continue)
120 read_state
121 continue_merge
122 while test "$msgnum" -le "$end"
124 call_merge "$msgnum"
125 continue_merge
126 done
127 finish_rb_merge
128 return
130 skip)
131 read_state
132 git rerere clear
133 msgnum=$(($msgnum + 1))
134 while test "$msgnum" -le "$end"
136 call_merge "$msgnum"
137 continue_merge
138 done
139 finish_rb_merge
140 return
142 show-current-patch)
143 exec git show REBASE_HEAD --
145 esac
147 mkdir -p "$state_dir"
148 echo "$onto_name" > "$state_dir/onto_name"
149 write_basic_state
150 rm -f "$(git rev-parse --git-path REBASE_HEAD)"
152 msgnum=0
153 for cmt in $(git rev-list --reverse --no-merges "$revisions")
155 msgnum=$(($msgnum + 1))
156 echo "$cmt" > "$state_dir/cmt.$msgnum"
157 done
159 echo 1 >"$state_dir/msgnum"
160 echo $msgnum >"$state_dir/end"
162 end=$msgnum
163 msgnum=1
165 while test "$msgnum" -le "$end"
167 call_merge "$msgnum"
168 continue_merge
169 done
171 finish_rb_merge
174 # ... and then we call the whole thing.
175 git_rebase__merge