[PATCH] git-merge: Reduce heads before trying to merge them

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <jmorris@xxxxxxxxx>
Signed-off-by: Michał Kiedrowicz <michal.kiedrowicz@xxxxxxxxx>
---

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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]