Skip to content

Commit

Permalink
am -3: support 3way merge on unborn branch
Browse files Browse the repository at this point in the history
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 <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Paul Tan authored and Junio C Hamano committed Jun 8, 2015
1 parent 88d5072 commit 2c970c9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion git-am.sh
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ It does not apply to blobs recorded in its index.")"
then
GIT_MERGE_VERBOSITY=0 && export GIT_MERGE_VERBOSITY
fi
git-merge-recursive $orig_tree -- HEAD $his_tree || {
our_tree=$(git rev-parse --verify -q HEAD || echo $empty_tree)
git-merge-recursive $orig_tree -- $our_tree $his_tree || {
git rerere $allow_rerere_autoupdate
die "$(gettext "Failed to merge in the changes.")"
}
Expand Down
9 changes: 9 additions & 0 deletions t/t4151-am-abort.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,13 @@ test_expect_success 'am --abort will keep the local commits intact' '
test_cmp expect actual
'

test_expect_success 'am -3 stops on conflict on unborn branch' '
git checkout -f --orphan orphan &&
git reset &&
rm -f otherfile-4 &&
test_must_fail git am -3 0003-*.patch &&
test 2 -eq $(git ls-files -u | wc -l) &&
test 4 = "$(cat otherfile-4)"
'

test_done

0 comments on commit 2c970c9

Please sign in to comment.