rebase: fix fork-point with zero arguments
authorJohn Keeping <john@keeping.me.uk>
Thu, 9 Jan 2014 19:47:34 +0000 (19:47 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 9 Jan 2014 23:05:26 +0000 (15:05 -0800)
When no arguments are specified, $switch_to is empty so we end up
passing the empty string to "git merge-base --fork-point", which causes
an error. git-rebase carries on at this point, but in fact we have
failed to apply the fork-point operation.

It turns out that the test in t3400 that was meant to test this didn't
actually need the fork-point behaviour, so enhance it to make sure that
the fork-point is applied correctly. The modified test fails without
the change to git-rebase.sh in this patch.

Reported-by: Andreas Krey <a.krey@gmx.de>
Signed-off-by: John Keeping <john@keeping.me.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-rebase.sh
t/t3400-rebase.sh
index 7185dc84387d6e20299fdda86800372445b9318e..8a3efa2983d08e38d40ae8b6dcecd82b0901ffa1 100755 (executable)
@@ -534,7 +534,8 @@ esac
 
 if test "$fork_point" = t
 then
-       new_upstream=$(git merge-base --fork-point "$upstream_name" "$switch_to")
+       new_upstream=$(git merge-base --fork-point "$upstream_name" \
+                       "${switch_to:-HEAD}")
        if test -n "$new_upstream"
        then
                upstream=$new_upstream
index 998503db12eb115e8e160937d456dfd9cb46311f..6d94b1fcd94e9f724c93a389c50066c92c46e1b9 100755 (executable)
@@ -135,11 +135,19 @@ test_expect_success 'fail when upstream arg is missing and not configured' '
 '
 
 test_expect_success 'default to common base in @{upstream}s reflog if no upstream arg' '
+       git checkout -b default-base master &&
        git checkout -b default topic &&
        git config branch.default.remote . &&
-       git config branch.default.merge refs/heads/master &&
+       git config branch.default.merge refs/heads/default-base &&
        git rebase &&
-       git rev-parse --verify master >expect &&
+       git rev-parse --verify default-base >expect &&
+       git rev-parse default~1 >actual &&
+       test_cmp expect actual &&
+       git checkout default-base &&
+       git reset --hard HEAD^ &&
+       git checkout default &&
+       git rebase &&
+       git rev-parse --verify default-base >expect &&
        git rev-parse default~1 >actual &&
        test_cmp expect actual
 '