* [PATCH 1/2] t6042: Add failing test for rename/rename/delete/delete.
@ 2017-03-03 11:33 Nicolas Cavallari
2017-03-03 11:33 ` [PATCH/RFC 2/2] merge-recursive: Handle rename/rename/delete/delete conflicts Nicolas Cavallari
0 siblings, 1 reply; 2+ messages in thread
From: Nicolas Cavallari @ 2017-03-03 11:33 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano
Each side of a rename 2to1 could also be deleted by the other side.
The code does not expect this. While it luckily works for files,
it fails for symlinks as follow:
CONFLICT (rename/rename): Rename a->c in HEAD. Rename b->c in C^0
Renaming a to c~HEAD and b to c~C^0 instead
error: cannot read object 0000000000000000000000000000000000000000 'c~C^0'
Signed-off-by: Nicolas Cavallari <nicolas.cavallari@green-communications.fr>
---
t/t6042-merge-rename-corner-cases.sh | 38 ++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/t/t6042-merge-rename-corner-cases.sh b/t/t6042-merge-rename-corner-cases.sh
index 411550d2b..ea4e14cbd 100755
--- a/t/t6042-merge-rename-corner-cases.sh
+++ b/t/t6042-merge-rename-corner-cases.sh
@@ -575,4 +575,42 @@ test_expect_success 'rename/rename/add-dest merge still knows about conflicting
test ! -f c
'
+# Testcase setup for rename/rename/delete/delete (2in1, deleted):
+# Commit A: new symlinks: a->alice b->bob
+# Commit B: rename a->c, delete b
+# Commit C: rename b->c, delete a
+#
+# We should not fail completely.
+
+test_expect_success 'setup rename/rename/delete/delete conflict' '
+ git rm -rf . &&
+ git clean -fdqx &&
+ rm -rf .git &&
+ git init &&
+
+ ln -s alice a &&
+ ln -s bob b &&
+ git add a b &&
+ git commit -m A &&
+ git tag A &&
+
+ git checkout -b B A &&
+ git mv a c &&
+ git rm b &&
+ git commit -m B &&
+
+ git checkout -b C A &&
+ git mv b c &&
+ git rm a &&
+ git commit -m C
+'
+
+test_expect_failure 'rename/rename/delete/delete leaves at least one file' '
+ git checkout B^0 &&
+ test_must_fail git merge -s recursive C^0 &&
+
+ test -L "c~HEAD" &&
+ test -L "c~C^0"
+'
+
test_done
--
2.11.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH/RFC 2/2] merge-recursive: Handle rename/rename/delete/delete conflicts.
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
0 siblings, 0 replies; 2+ messages in thread
From: Nicolas Cavallari @ 2017-03-03 11:33 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-03-03 11:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-03 11:33 [PATCH 1/2] t6042: Add failing test for rename/rename/delete/delete Nicolas Cavallari
2017-03-03 11:33 ` [PATCH/RFC 2/2] merge-recursive: Handle rename/rename/delete/delete conflicts Nicolas Cavallari
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).