From: Michał Kiedrowicz Date: Tue, 17 Apr 2012 18:25:18 GMT Subject: [PATCH] git-merge: Reduce heads before trying to merge them Message-ID: <1334687118-5386-1-git-send-email-michal.kiedrowicz@gmail.com> In-Reply-To: This makes us do proper fast-forward merges even for octopus merges, which could otherwise result in "merge commit" that only had one actual parent, and should have been a fast-forward. Odd-case-triggered-by: James Morris Signed-off-by: Michał Kiedrowicz --- This is the proposed fix sent as a proper patch with commit message stolen from Linus and testcases. I'm not sure if I don't introduce a memleak with the call to reduce_heads() but other callers seem to not care, just like whole cmd_merge(). builtin/merge.c | 3 +++ t/t7603-merge-reduce-heads.sh | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 0 deletions(-) diff --git a/builtin/merge.c b/builtin/merge.c index 08e01e8..2d5930f 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -1346,6 +1346,9 @@ int cmd_merge(int argc, const char **argv, const char *prefix) allow_trivial = 0; } + if (remoteheads->next) + remoteheads = reduce_heads(remoteheads); + if (!remoteheads->next) common = get_merge_bases(head_commit, remoteheads->item, 1); else { diff --git a/t/t7603-merge-reduce-heads.sh b/t/t7603-merge-reduce-heads.sh index 7e17eb4..a3b08a6 100755 --- a/t/t7603-merge-reduce-heads.sh +++ b/t/t7603-merge-reduce-heads.sh @@ -113,4 +113,23 @@ test_expect_success 'verify merge result' ' test $(git rev-parse HEAD^1) = $(git rev-parse E2) && test $(git rev-parse HEAD^2) = $(git rev-parse I2) ' + +test_expect_success 'fast-forward to redundant refs' ' + git reset --hard c0 && + git merge c4 c5 +' + +test_expect_success 'verify merge result' ' + test $(git rev-parse HEAD) = $(git rev-parse c5) +' + +test_expect_success 'merge up-to-date redundant refs' ' + git reset --hard c5 && + git merge c0 c4 +' + +test_expect_success 'verify merge result' ' + test $(git rev-parse HEAD) = $(git rev-parse c5) +' + test_done -- 1.7.8.4