@matheusbsbs / matheus-bagliano / commits / a6c7a27691
Fork 0

rebase -i: correctly remember --root flag across --continue

d911d14 (rebase -i: learn to rebase root commit, 2009-01-02) tried to remember the --root flag across a merge conflict in a broken way. Introduce a flag file $DOTEST/rebase-root to fix and clarify. While at it, also make sure $UPSTREAM is always initialized to guard against existing values in the environment. [tr: added tests] Signed-off-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Jan 26, 2009 at 10:05 UTC a6c7a27691bd8b059d39c9bc71b19fb8e614fa54
2 files changed +102 -2
git-rebase--interactive.sh
+8 -2
@@ -456,7 +456,7 @@ get_saved_options () {
456 test -d "$REWRITTEN" && PRESERVE_MERGES=t
457 test -f "$DOTEST"/strategy && STRATEGY="$(cat "$DOTEST"/strategy)"
458 test -f "$DOTEST"/verbose && VERBOSE=t
459 - test ! -s "$DOTEST"/upstream && REBASE_ROOT=t
459 + test -f "$DOTEST"/rebase-root && REBASE_ROOT=t
460 }
461
462 while test $# != 0
@@ -586,6 +586,7 @@ first and then run 'git rebase --continue' again."
586 test -z "$ONTO" && ONTO=$UPSTREAM
587 shift
588 else
589 + UPSTREAM=
590 UPSTREAM_ARG=--root
591 test -z "$ONTO" &&
592 die "You must specify --onto when using --root"
@@ -612,7 +613,12 @@ first and then run 'git rebase --continue' again."
613 echo "detached HEAD" > "$DOTEST"/head-name
614
615 echo $HEAD > "$DOTEST"/head
615 - echo $UPSTREAM > "$DOTEST"/upstream
616 + case "$REBASE_ROOT" in
617 + '')
618 + rm -f "$DOTEST"/rebase-root ;;
619 + *)
620 + : >"$DOTEST"/rebase-root ;;
621 + esac
622 echo $ONTO > "$DOTEST"/onto
623 test -z "$STRATEGY" || echo "$STRATEGY" > "$DOTEST"/strategy
624 test t = "$VERBOSE" && : > "$DOTEST"/verbose
t/t3412-rebase-root.sh
+94
@@ -184,4 +184,98 @@ test_expect_success 'pre-rebase hook stops rebase -i' '
184 test 0 = $(git rev-list other...stops2 | wc -l)
185 '
186
187 +test_expect_success 'remove pre-rebase hook' '
188 + rm -f .git/hooks/pre-rebase
189 +'
190 +
191 +test_expect_success 'set up a conflict' '
192 + git checkout master &&
193 + echo conflict > B &&
194 + git add B &&
195 + git commit -m conflict
196 +'
197 +
198 +test_expect_success 'rebase --root with conflict (first part)' '
199 + git checkout -b conflict1 other &&
200 + test_must_fail git rebase --root --onto master &&
201 + git ls-files -u | grep "B$"
202 +'
203 +
204 +test_expect_success 'fix the conflict' '
205 + echo 3 > B &&
206 + git add B
207 +'
208 +
209 +cat > expect-conflict <<EOF
210 +6
211 +5
212 +4
213 +3
214 +conflict
215 +2
216 +1
217 +EOF
218 +
219 +test_expect_success 'rebase --root with conflict (second part)' '
220 + git rebase --continue &&
221 + git log --pretty=tformat:"%s" > conflict1 &&
222 + test_cmp expect-conflict conflict1
223 +'
224 +
225 +test_expect_success 'rebase -i --root with conflict (first part)' '
226 + git checkout -b conflict2 other &&
227 + GIT_EDITOR=: test_must_fail git rebase -i --root --onto master &&
228 + git ls-files -u | grep "B$"
229 +'
230 +
231 +test_expect_success 'fix the conflict' '
232 + echo 3 > B &&
233 + git add B
234 +'
235 +
236 +test_expect_success 'rebase -i --root with conflict (second part)' '
237 + git rebase --continue &&
238 + git log --pretty=tformat:"%s" > conflict2 &&
239 + test_cmp expect-conflict conflict2
240 +'
241 +
242 +cat >expect-conflict-p <<\EOF
243 +commit conflict3 conflict3~1 conflict3^2
244 +Merge branch 'third' into other
245 +commit conflict3^2 conflict3~4
246 +6
247 +commit conflict3~1 conflict3~2 conflict3~1^2
248 +Merge branch 'side' into other
249 +commit conflict3~1^2 conflict3~3
250 +5
251 +commit conflict3~2 conflict3~3
252 +4
253 +commit conflict3~3 conflict3~4
254 +3
255 +commit conflict3~4 conflict3~5
256 +conflict
257 +commit conflict3~5 conflict3~6
258 +2
259 +commit conflict3~6
260 +1
261 +EOF
262 +
263 +test_expect_success 'rebase -i -p --root with conflict (first part)' '
264 + git checkout -b conflict3 other &&
265 + GIT_EDITOR=: test_must_fail git rebase -i -p --root --onto master &&
266 + git ls-files -u | grep "B$"
267 +'
268 +
269 +test_expect_success 'fix the conflict' '
270 + echo 3 > B &&
271 + git add B
272 +'
273 +
274 +test_expect_success 'rebase -i -p --root with conflict (second part)' '
275 + git rebase --continue &&
276 + git rev-list --topo-order --parents --pretty="tformat:%s" HEAD |
277 + git name-rev --stdin --name-only --refs=refs/heads/conflict3 >out &&
278 + test_cmp expect-conflict-p out
279 +'
280 +
281 test_done