Skip to content

Commit 2c970c9

Browse files
pyokagangitster
authored andcommitted
am -3: support 3way merge on unborn branch
While on an unborn branch, git am -3 will fail to do a threeway merge as it references HEAD as "our tree", but HEAD does not point to a valid tree. Fix this by using an empty tree as "our tree" when we are on an unborn branch. Signed-off-by: Paul Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 88d5072 commit 2c970c9

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

git-am.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ It does not apply to blobs recorded in its index.")"
178178
then
179179
GIT_MERGE_VERBOSITY=0 && export GIT_MERGE_VERBOSITY
180180
fi
181-
git-merge-recursive $orig_tree -- HEAD $his_tree || {
181+
our_tree=$(git rev-parse --verify -q HEAD || echo $empty_tree)
182+
git-merge-recursive $orig_tree -- $our_tree $his_tree || {
182183
git rerere $allow_rerere_autoupdate
183184
die "$(gettext "Failed to merge in the changes.")"
184185
}

t/t4151-am-abort.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,13 @@ test_expect_success 'am --abort will keep the local commits intact' '
8383
test_cmp expect actual
8484
'
8585

86+
test_expect_success 'am -3 stops on conflict on unborn branch' '
87+
git checkout -f --orphan orphan &&
88+
git reset &&
89+
rm -f otherfile-4 &&
90+
test_must_fail git am -3 0003-*.patch &&
91+
test 2 -eq $(git ls-files -u | wc -l) &&
92+
test 4 = "$(cat otherfile-4)"
93+
'
94+
8695
test_done

0 commit comments

Comments
 (0)