git-rebase--merge: don't include absent parent as a base

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>

Ben Woosley committed Apr 20, 2016 at 18:20 UTC 79f43447d2b542d1e521987287822ff376d43e93
3 files changed +14 -3
git-rebase--merge.sh
+3 -1
@@ -67,7 +67,9 @@ call_merge () {
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"'
70 + # If cmt doesn't have a parent, don't include it as a base
71 + base=$(git rev-parse --verify --quiet $cmt^)
72 + eval 'git-merge-$strategy' $strategy_opts $base ' -- "$hd" "$cmt"'
73 rv=$?
74 case "$rv" in
75 0)
t/t3402-rebase-merge.sh
+9
@@ -85,6 +85,15 @@ test_expect_success 'rebase -Xtheirs' '
85 ! grep 11 original
86 '
87
88 +test_expect_success 'rebase -Xtheirs from orphan' '
89 + git checkout --orphan orphan-conflicting master~2 &&
90 + echo "AB $T" >> original &&
91 + git commit -morphan-conflicting original &&
92 + git rebase -Xtheirs master &&
93 + grep AB original &&
94 + ! grep 11 original
95 +'
96 +
97 test_expect_success 'merge and rebase should match' '
98 git diff-tree -r test-rebase test-merge >difference &&
99 if test -s difference
t/t3421-rebase-topology-linear.sh
+2 -2
@@ -253,7 +253,7 @@ test_run_rebase () {
253 "
254 }
255 test_run_rebase success ''
256 -test_run_rebase failure -m
256 +test_run_rebase success -m
257 test_run_rebase success -i
258 test_run_rebase success -p
259
@@ -268,7 +268,7 @@ test_run_rebase () {
268 "
269 }
270 test_run_rebase success ''
271 -test_run_rebase failure -m
271 +test_run_rebase success -m
272 test_run_rebase success -i
273 test_run_rebase failure -p
274