git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Nicolas Cavallari <nicolas.cavallari@green-communications.fr>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>
Subject: [PATCH/RFC 2/2] merge-recursive: Handle rename/rename/delete/delete conflicts.
Date: Fri,  3 Mar 2017 12:33:17 +0100	[thread overview]
Message-ID: <20170303113317.18575-2-nicolas.cavallari@green-communications.fr> (raw)
In-Reply-To: <20170303113317.18575-1-nicolas.cavallari@green-communications.fr>

On a rename 2to1 conflict, where both a and b are renamed to c,
the other branch may have deleted a or b.  This currently luckily
works for files but fails for symlinks.

Fix conflict_rename_rename_2to1 to not merge_file_special_markers()
with diff_filespecs where mode == 0.  The alternative would be to make
merge_file_1() handle it.

Mark the corresponding testcase in t6042 as fixed.

Signed-off-by: Nicolas Cavallari <nicolas.cavallari@green-communications.fr>
---
 merge-recursive.c                    | 28 ++++++++++++++++++++++------
 t/t6042-merge-rename-corner-cases.sh |  2 +-
 2 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/merge-recursive.c b/merge-recursive.c
index b7ff1ada3..0e5a3e3ed 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -1305,13 +1305,29 @@ static int conflict_rename_rename_2to1(struct merge_options *o,
 	remove_file(o, 1, a->path, o->call_depth || would_lose_untracked(a->path));
 	remove_file(o, 1, b->path, o->call_depth || would_lose_untracked(b->path));
 
-	if (merge_file_special_markers(o, a, c1, &ci->ren1_other,
-				       o->branch1, c1->path,
-				       o->branch2, ci->ren1_other.path, &mfi_c1) ||
-	    merge_file_special_markers(o, b, &ci->ren2_other, c2,
-				       o->branch1, ci->ren2_other.path,
-				       o->branch2, c2->path, &mfi_c2))
+	// The other branch may have deleted a, as indicated by mode == 0.
+	if (ci->ren1_other.mode == 0) {
+		mfi_c1.clean = 0;
+		mfi_c1.merge = 0;
+		mfi_c1.mode = c1->mode;
+		oidcpy(&mfi_c1.oid, &c1->oid);
+	} else if (merge_file_special_markers(o, a, c1, &ci->ren1_other,
+					      o->branch1, c1->path,
+					      o->branch2, ci->ren1_other.path,
+					      &mfi_c1)) {
 		return -1;
+	}
+
+	if (ci->ren2_other.mode == 0) {
+		mfi_c2.clean = 0;
+		mfi_c2.merge = 0;
+		mfi_c2.mode = c2->mode;
+		oidcpy(&mfi_c2.oid, &c2->oid);
+	} else if (merge_file_special_markers(o, b, &ci->ren2_other, c2,
+					      o->branch1, ci->ren2_other.path,
+					      o->branch2, c2->path, &mfi_c2)) {
+		return -1;
+	}
 
 	if (o->call_depth) {
 		/*
diff --git a/t/t6042-merge-rename-corner-cases.sh b/t/t6042-merge-rename-corner-cases.sh
index ea4e14cbd..34b16d5d7 100755
--- a/t/t6042-merge-rename-corner-cases.sh
+++ b/t/t6042-merge-rename-corner-cases.sh
@@ -605,7 +605,7 @@ test_expect_success 'setup rename/rename/delete/delete conflict' '
 	git commit -m C
 '
 
-test_expect_failure 'rename/rename/delete/delete leaves at least one file' '
+test_expect_success 'rename/rename/delete/delete leaves at least one file' '
 	git checkout B^0 &&
 	test_must_fail git merge -s recursive C^0 &&
 
-- 
2.11.0


      reply	other threads:[~2017-03-03 11:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-03 11:33 [PATCH 1/2] t6042: Add failing test for rename/rename/delete/delete Nicolas Cavallari
2017-03-03 11:33 ` Nicolas Cavallari [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170303113317.18575-2-nicolas.cavallari@green-communications.fr \
    --to=nicolas.cavallari@green-communications.fr \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).