Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 168 lines (150 sloc) 3.806 kb
11d6214 @jrn remove #!interpreter line from shell libraries
jrn authored
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.
fa99c1e rebase: extract merge code to new source file
Martin von Zweigbergk authored
4 #
5 # Copyright (c) 2010 Junio C Hamano.
6 #
7
8 prec=4
9
10 read_state () {
11 onto_name=$(cat "$state_dir"/onto_name) &&
12 end=$(cat "$state_dir"/end) &&
13 msgnum=$(cat "$state_dir"/msgnum)
14 }
15
16 continue_merge () {
17 test -d "$state_dir" || die "$state_dir directory does not exist"
18
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"
25 fi
26
f257482 @devzero2000 git-rebase--merge.sh: use the $( ... ) construct for command substitu…
devzero2000 authored
27 cmt=$(cat "$state_dir/current")
fa99c1e rebase: extract merge code to new source file
Martin von Zweigbergk authored
28 if ! git diff-index --quiet --ignore-submodules HEAD --
29 then
3ee5e54 @boklm rebase: add the --gpg-sign option
boklm authored
30 if ! git commit ${gpg_sign_opt:+"$gpg_sign_opt"} --no-verify -C "$cmt"
fa99c1e rebase: extract merge code to new source file
Martin von Zweigbergk authored
31 then
32 echo "Commit failed, please do not call \"git commit\""
33 echo "directly, but instead do one of the following: "
34 die "$resolvemsg"
35 fi
36 if test -z "$GIT_QUIET"
37 then
38 printf "Committed: %0${prec}d " $msgnum
39 fi
40 echo "$cmt $(git rev-parse HEAD^0)" >> "$state_dir/rewritten"
41 else
42 if test -z "$GIT_QUIET"
43 then
44 printf "Already applied: %0${prec}d " $msgnum
45 fi
46 fi
47 test -z "$GIT_QUIET" &&
48 GIT_PAGER='' git log --format=%s -1 "$cmt"
49
50 # onto the next patch:
51 msgnum=$(($msgnum + 1))
52 echo "$msgnum" >"$state_dir/msgnum"
53 }
54
55 call_merge () {
95104c7 @bk2204 rebase--merge: fix --skip with two conflicts in a row
bk2204 authored
56 msgnum="$1"
57 echo "$msgnum" >"$state_dir/msgnum"
58 cmt="$(cat "$state_dir/cmt.$msgnum")"
fa99c1e rebase: extract merge code to new source file
Martin von Zweigbergk authored
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"
66 then
67 GIT_MERGE_VERBOSITY=1 && export GIT_MERGE_VERBOSITY
68 fi
69 test -z "$strategy" && strategy=recursive
70 eval 'git-merge-$strategy' $strategy_opts '"$cmt^" -- "$hd" "$cmt"'
71 rv=$?
72 case "$rv" in
73 0)
74 unset GITHEAD_$cmt GITHEAD_$hd
75 return
76 ;;
77 1)
78 git rerere $allow_rerere_autoupdate
79 die "$resolvemsg"
80 ;;
81 2)
b325680 rebase -m: don't print exit code 2 when merge fails
Martin von Zweigbergk authored
82 echo "Strategy: $strategy failed, try another" 1>&2
fa99c1e rebase: extract merge code to new source file
Martin von Zweigbergk authored
83 die "$resolvemsg"
84 ;;
85 *)
86 die "Unknown exit code ($rv) from command:" \
87 "git-merge-$strategy $cmt^ -- HEAD $cmt"
88 ;;
89 esac
90 }
91
92 finish_rb_merge () {
93 move_to_original_branch
ad687b4 @andrewkww rebase -m: only call "notes copy" when rewritten exists and is non-empty
andrewkww authored
94 if test -s "$state_dir"/rewritten
95 then
96 git notes copy --for-rewrite=rebase <"$state_dir"/rewritten
b849b95 @pclouds *.sh: avoid hardcoding $GIT_DIR/hooks/...
pclouds authored
97 hook="$(git rev-parse --git-path hooks/post-rewrite)"
98 test -x "$hook" && "$hook" rebase <"$state_dir"/rewritten
fa99c1e rebase: extract merge code to new source file
Martin von Zweigbergk authored
99 fi
100 say All done.
101 }
102
9f50d32 @mackyle rebase: avoid non-function use of "return" on FreeBSD
mackyle authored
103 # The whole contents of this file is run by dot-sourcing it from
104 # inside a shell function. It used to be that "return"s we see
105 # below were not inside any function, and expected to return
106 # to the function that dot-sourced us.
107 #
108 # However, FreeBSD /bin/sh misbehaves on such a construct and
109 # continues to run the statements that follow such a "return".
110 # As a work-around, we introduce an extra layer of a function
111 # here, and immediately call it after defining it.
112 git_rebase__merge () {
113
fa99c1e rebase: extract merge code to new source file
Martin von Zweigbergk authored
114 case "$action" in
115 continue)
116 read_state
117 continue_merge
118 while test "$msgnum" -le "$end"
119 do
120 call_merge "$msgnum"
121 continue_merge
122 done
123 finish_rb_merge
01a1e64 @artagnon rebase --merge: return control to caller, for housekeeping
artagnon authored
124 return
fa99c1e rebase: extract merge code to new source file
Martin von Zweigbergk authored
125 ;;
126 skip)
127 read_state
128 git rerere clear
129 msgnum=$(($msgnum + 1))
130 while test "$msgnum" -le "$end"
131 do
132 call_merge "$msgnum"
133 continue_merge
134 done
135 finish_rb_merge
01a1e64 @artagnon rebase --merge: return control to caller, for housekeeping
artagnon authored
136 return
fa99c1e rebase: extract merge code to new source file
Martin von Zweigbergk authored
137 ;;
138 esac
139
140 mkdir -p "$state_dir"
141 echo "$onto_name" > "$state_dir/onto_name"
84df456 rebase: extract code for writing basic state
Martin von Zweigbergk authored
142 write_basic_state
fa99c1e rebase: extract merge code to new source file
Martin von Zweigbergk authored
143
144 msgnum=0
f257482 @devzero2000 git-rebase--merge.sh: use the $( ... ) construct for command substitu…
devzero2000 authored
145 for cmt in $(git rev-list --reverse --no-merges "$revisions")
fa99c1e rebase: extract merge code to new source file
Martin von Zweigbergk authored
146 do
147 msgnum=$(($msgnum + 1))
148 echo "$cmt" > "$state_dir/cmt.$msgnum"
149 done
150
151 echo 1 >"$state_dir/msgnum"
152 echo $msgnum >"$state_dir/end"
153
154 end=$msgnum
155 msgnum=1
156
157 while test "$msgnum" -le "$end"
158 do
159 call_merge "$msgnum"
160 continue_merge
161 done
162
163 finish_rb_merge
9f50d32 @mackyle rebase: avoid non-function use of "return" on FreeBSD
mackyle authored
164
165 }
166 # ... and then we call the whole thing.
167 git_rebase__merge
Something went wrong with that request. Please try again.