]> asedeno.scripts.mit.edu Git - git.git/commitdiff
rebase -i: correctly remember --root flag across --continue
authorJunio C Hamano <gitster@pobox.com>
Mon, 26 Jan 2009 09:05:22 +0000 (10:05 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 27 Jan 2009 05:23:19 +0000 (21:23 -0800)
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>
git-rebase--interactive.sh
t/t3412-rebase-root.sh

index 002929eb091fe3724ba2f37277a61364f1c90db1..1438650ae8a2ec71615821168970936b9d170f35 100755 (executable)
@@ -456,7 +456,7 @@ get_saved_options () {
        test -d "$REWRITTEN" && PRESERVE_MERGES=t
        test -f "$DOTEST"/strategy && STRATEGY="$(cat "$DOTEST"/strategy)"
        test -f "$DOTEST"/verbose && VERBOSE=t
-       test ! -s "$DOTEST"/upstream && REBASE_ROOT=t
+       test -f "$DOTEST"/rebase-root && REBASE_ROOT=t
 }
 
 while test $# != 0
@@ -586,6 +586,7 @@ first and then run 'git rebase --continue' again."
                        test -z "$ONTO" && ONTO=$UPSTREAM
                        shift
                else
+                       UPSTREAM=
                        UPSTREAM_ARG=--root
                        test -z "$ONTO" &&
                                die "You must specify --onto when using --root"
@@ -612,7 +613,12 @@ first and then run 'git rebase --continue' again."
                        echo "detached HEAD" > "$DOTEST"/head-name
 
                echo $HEAD > "$DOTEST"/head
-               echo $UPSTREAM > "$DOTEST"/upstream
+               case "$REBASE_ROOT" in
+               '')
+                       rm -f "$DOTEST"/rebase-root ;;
+               *)
+                       : >"$DOTEST"/rebase-root ;;
+               esac
                echo $ONTO > "$DOTEST"/onto
                test -z "$STRATEGY" || echo "$STRATEGY" > "$DOTEST"/strategy
                test t = "$VERBOSE" && : > "$DOTEST"/verbose
index 6359580262e9a171e46c60749b1827324e6535f9..ef6f7a54ae23bc58198363b20019a58c54b021fc 100755 (executable)
@@ -184,4 +184,98 @@ test_expect_success 'pre-rebase hook stops rebase -i' '
        test 0 = $(git rev-list other...stops2 | wc -l)
 '
 
+test_expect_success 'remove pre-rebase hook' '
+       rm -f .git/hooks/pre-rebase
+'
+
+test_expect_success 'set up a conflict' '
+       git checkout master &&
+       echo conflict > B &&
+       git add B &&
+       git commit -m conflict
+'
+
+test_expect_success 'rebase --root with conflict (first part)' '
+       git checkout -b conflict1 other &&
+       test_must_fail git rebase --root --onto master &&
+       git ls-files -u | grep "B$"
+'
+
+test_expect_success 'fix the conflict' '
+       echo 3 > B &&
+       git add B
+'
+
+cat > expect-conflict <<EOF
+6
+5
+4
+3
+conflict
+2
+1
+EOF
+
+test_expect_success 'rebase --root with conflict (second part)' '
+       git rebase --continue &&
+       git log --pretty=tformat:"%s" > conflict1 &&
+       test_cmp expect-conflict conflict1
+'
+
+test_expect_success 'rebase -i --root with conflict (first part)' '
+       git checkout -b conflict2 other &&
+       GIT_EDITOR=: test_must_fail git rebase -i --root --onto master &&
+       git ls-files -u | grep "B$"
+'
+
+test_expect_success 'fix the conflict' '
+       echo 3 > B &&
+       git add B
+'
+
+test_expect_success 'rebase -i --root with conflict (second part)' '
+       git rebase --continue &&
+       git log --pretty=tformat:"%s" > conflict2 &&
+       test_cmp expect-conflict conflict2
+'
+
+cat >expect-conflict-p <<\EOF
+commit conflict3 conflict3~1 conflict3^2
+Merge branch 'third' into other
+commit conflict3^2 conflict3~4
+6
+commit conflict3~1 conflict3~2 conflict3~1^2
+Merge branch 'side' into other
+commit conflict3~1^2 conflict3~3
+5
+commit conflict3~2 conflict3~3
+4
+commit conflict3~3 conflict3~4
+3
+commit conflict3~4 conflict3~5
+conflict
+commit conflict3~5 conflict3~6
+2
+commit conflict3~6
+1
+EOF
+
+test_expect_success 'rebase -i -p --root with conflict (first part)' '
+       git checkout -b conflict3 other &&
+       GIT_EDITOR=: test_must_fail git rebase -i -p --root --onto master &&
+       git ls-files -u | grep "B$"
+'
+
+test_expect_success 'fix the conflict' '
+       echo 3 > B &&
+       git add B
+'
+
+test_expect_success 'rebase -i -p --root with conflict (second part)' '
+       git rebase --continue &&
+       git rev-list --topo-order --parents --pretty="tformat:%s" HEAD |
+       git name-rev --stdin --name-only --refs=refs/heads/conflict3 >out &&
+       test_cmp expect-conflict-p out
+'
+
 test_done