Skip to content

Commit 79f4344

Browse files
Empactgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6a66362 commit 79f4344

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

git-rebase--merge.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ call_merge () {
6767
GIT_MERGE_VERBOSITY=1 && export GIT_MERGE_VERBOSITY
6868
fi
6969
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"'
7173
rv=$?
7274
case "$rv" in
7375
0)

t/t3402-rebase-merge.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ test_expect_success 'rebase -Xtheirs' '
8585
! grep 11 original
8686
'
8787

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+
8897
test_expect_success 'merge and rebase should match' '
8998
git diff-tree -r test-rebase test-merge >difference &&
9099
if test -s difference

t/t3421-rebase-topology-linear.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ test_run_rebase () {
253253
"
254254
}
255255
test_run_rebase success ''
256-
test_run_rebase failure -m
256+
test_run_rebase success -m
257257
test_run_rebase success -i
258258
test_run_rebase success -p
259259

@@ -268,7 +268,7 @@ test_run_rebase () {
268268
"
269269
}
270270
test_run_rebase success ''
271-
test_run_rebase failure -m
271+
test_run_rebase success -m
272272
test_run_rebase success -i
273273
test_run_rebase failure -p
274274

0 commit comments

Comments
 (0)