git-rebase--merge: don't include absent parent as a base
authorBen Woosley <ben.woosley@gmail.com>
Wed, 20 Apr 2016 18:20:56 +0000 (18:20 +0000)
committerJunio C Hamano <gitster@pobox.com>
Sun, 24 Apr 2016 19:05:08 +0000 (12:05 -0700)
Absent this fix, attempts to rebase an orphan branch using "rebase -m"
fails with:

$ git rebase -m ORPHAN_TARGET_BASE
First, rewinding head to replay your work on top of it...
fatal: Could not parse object 'ORPHAN_ROOT_SHA^'
Unknown exit code (128) from command: git-merge-recursive ORPHAN_ROOT_SHA^ -- HEAD ORPHAN_ROOT_SHA

To fix, this will only include the rebase root's parent as a base if it exists,
so that in cases of rebasing an orphan branch, it is a simple two-way merge.

Note the default rebase behavior does not fail:

$ git rebase ORPHAN_TARGET_BASE
First, rewinding head to replay your work on top of it...
Applying: ORPHAN_ROOT_COMMIT_MSG
Using index info to reconstruct a base tree...

A few tests were expecting the old behaviour to forbid rebasing such
a history with "rebase -m", which now need to expect them to succeed.

Signed-off-by: Ben Woosley <ben.woosley@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-rebase--merge.sh
t/t3402-rebase-merge.sh
t/t3421-rebase-topology-linear.sh
index 2cc2a6d2734c0ef12222004f22d717f4f724d82f..8d43db9069f5c478fa6cb2deb6cf7d1d37f1e6b2 100644 (file)
@@ -67,7 +67,9 @@ call_merge () {
                GIT_MERGE_VERBOSITY=1 && export GIT_MERGE_VERBOSITY
        fi
        test -z "$strategy" && strategy=recursive
-       eval 'git-merge-$strategy' $strategy_opts '"$cmt^" -- "$hd" "$cmt"'
+       # If cmt doesn't have a parent, don't include it as a base
+       base=$(git rev-parse --verify --quiet $cmt^)
+       eval 'git-merge-$strategy' $strategy_opts $base ' -- "$hd" "$cmt"'
        rv=$?
        case "$rv" in
        0)
index 8f64505e4f94432de6cc287f4ab2f3129703536a..488945e0071b1ba4ae988848b5cb42df72737d2b 100755 (executable)
@@ -85,6 +85,15 @@ test_expect_success 'rebase -Xtheirs' '
        ! grep 11 original
 '
 
+test_expect_success 'rebase -Xtheirs from orphan' '
+       git checkout --orphan orphan-conflicting master~2 &&
+       echo "AB $T" >> original &&
+       git commit -morphan-conflicting original &&
+       git rebase -Xtheirs master &&
+       grep AB original &&
+       ! grep 11 original
+'
+
 test_expect_success 'merge and rebase should match' '
        git diff-tree -r test-rebase test-merge >difference &&
        if test -s difference
index 9c55cba198e4ed4cbc01ffce79abeb39504bf544..68fe2003ef5f74073cafa4741bee31ade85cf5c0 100755 (executable)
@@ -253,7 +253,7 @@ test_run_rebase () {
        "
 }
 test_run_rebase success ''
-test_run_rebase failure -m
+test_run_rebase success -m
 test_run_rebase success -i
 test_run_rebase success -p
 
@@ -268,7 +268,7 @@ test_run_rebase () {
        "
 }
 test_run_rebase success ''
-test_run_rebase failure -m
+test_run_rebase success -m
 test_run_rebase success -i
 test_run_rebase failure -p