]> git.ipfire.org Git - thirdparty/git.git/blame - git-rebase--merge.sh
glossary: define commit-ish (a.k.a. committish)
[thirdparty/git.git] / git-rebase--merge.sh
CommitLineData
fa99c1e1
MZ
1#!/bin/sh
2#
3# Copyright (c) 2010 Junio C Hamano.
4#
5
fa99c1e1
MZ
6prec=4
7
8read_state () {
9 onto_name=$(cat "$state_dir"/onto_name) &&
10 end=$(cat "$state_dir"/end) &&
11 msgnum=$(cat "$state_dir"/msgnum)
12}
13
14continue_merge () {
15 test -d "$state_dir" || die "$state_dir directory does not exist"
16
17 unmerged=$(git ls-files -u)
18 if test -n "$unmerged"
19 then
20 echo "You still have unmerged paths in your index"
21 echo "did you forget to use git add?"
22 die "$resolvemsg"
23 fi
24
25 cmt=`cat "$state_dir/current"`
26 if ! git diff-index --quiet --ignore-submodules HEAD --
27 then
28 if ! git commit --no-verify -C "$cmt"
29 then
30 echo "Commit failed, please do not call \"git commit\""
31 echo "directly, but instead do one of the following: "
32 die "$resolvemsg"
33 fi
34 if test -z "$GIT_QUIET"
35 then
36 printf "Committed: %0${prec}d " $msgnum
37 fi
38 echo "$cmt $(git rev-parse HEAD^0)" >> "$state_dir/rewritten"
39 else
40 if test -z "$GIT_QUIET"
41 then
42 printf "Already applied: %0${prec}d " $msgnum
43 fi
44 fi
45 test -z "$GIT_QUIET" &&
46 GIT_PAGER='' git log --format=%s -1 "$cmt"
47
48 # onto the next patch:
49 msgnum=$(($msgnum + 1))
50 echo "$msgnum" >"$state_dir/msgnum"
51}
52
53call_merge () {
54 cmt="$(cat "$state_dir/cmt.$1")"
55 echo "$cmt" > "$state_dir/current"
56 hd=$(git rev-parse --verify HEAD)
57 cmt_name=$(git symbolic-ref HEAD 2> /dev/null || echo HEAD)
58 msgnum=$(cat "$state_dir/msgnum")
59 eval GITHEAD_$cmt='"${cmt_name##refs/heads/}~$(($end - $msgnum))"'
60 eval GITHEAD_$hd='$onto_name'
61 export GITHEAD_$cmt GITHEAD_$hd
62 if test -n "$GIT_QUIET"
63 then
64 GIT_MERGE_VERBOSITY=1 && export GIT_MERGE_VERBOSITY
65 fi
66 test -z "$strategy" && strategy=recursive
67 eval 'git-merge-$strategy' $strategy_opts '"$cmt^" -- "$hd" "$cmt"'
68 rv=$?
69 case "$rv" in
70 0)
71 unset GITHEAD_$cmt GITHEAD_$hd
72 return
73 ;;
74 1)
75 git rerere $allow_rerere_autoupdate
76 die "$resolvemsg"
77 ;;
78 2)
b3256809 79 echo "Strategy: $strategy failed, try another" 1>&2
fa99c1e1
MZ
80 die "$resolvemsg"
81 ;;
82 *)
83 die "Unknown exit code ($rv) from command:" \
84 "git-merge-$strategy $cmt^ -- HEAD $cmt"
85 ;;
86 esac
87}
88
89finish_rb_merge () {
90 move_to_original_branch
ad687b44
AW
91 if test -s "$state_dir"/rewritten
92 then
93 git notes copy --for-rewrite=rebase <"$state_dir"/rewritten
94 if test -x "$GIT_DIR"/hooks/post-rewrite
95 then
96 "$GIT_DIR"/hooks/post-rewrite rebase <"$state_dir"/rewritten
97 fi
fa99c1e1 98 fi
fa99c1e1
MZ
99 say All done.
100}
101
102case "$action" in
103continue)
104 read_state
105 continue_merge
106 while test "$msgnum" -le "$end"
107 do
108 call_merge "$msgnum"
109 continue_merge
110 done
111 finish_rb_merge
01a1e646 112 return
fa99c1e1
MZ
113 ;;
114skip)
115 read_state
116 git rerere clear
117 msgnum=$(($msgnum + 1))
118 while test "$msgnum" -le "$end"
119 do
120 call_merge "$msgnum"
121 continue_merge
122 done
123 finish_rb_merge
01a1e646 124 return
fa99c1e1
MZ
125 ;;
126esac
127
128mkdir -p "$state_dir"
129echo "$onto_name" > "$state_dir/onto_name"
84df4560 130write_basic_state
fa99c1e1
MZ
131
132msgnum=0
133for cmt in `git rev-list --reverse --no-merges "$revisions"`
134do
135 msgnum=$(($msgnum + 1))
136 echo "$cmt" > "$state_dir/cmt.$msgnum"
137done
138
139echo 1 >"$state_dir/msgnum"
140echo $msgnum >"$state_dir/end"
141
142end=$msgnum
143msgnum=1
144
145while test "$msgnum" -le "$end"
146do
147 call_merge "$msgnum"
148 continue_merge
149done
150
151finish_rb_merge