Patchwork [3,of,4,V2] merge: don't ignore conflicting file in remote renamed directory

login
register
mail settings
Submitter Martin von Zweigbergk
Date Dec. 4, 2014, 5:15 a.m.
Message ID <a8f9e63789da94b50152.1417670151@martinvonz.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/6996/
State Accepted
Commit 67f1d68861fb4d85829eaee1220d0627dfc64ed5
Headers show

Comments

Martin von Zweigbergk - Dec. 4, 2014, 5:15 a.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1417632967 28800
#      Wed Dec 03 10:56:07 2014 -0800
# Node ID a8f9e63789da94b50152dae28e2de0343c8c247a
# Parent  f335a578687feba71e75751fac6d0d43326e8829
merge: don't ignore conflicting file in remote renamed directory

When the remote side has renamed a directory from a/ to b/ and added a
file b/c in it, and the local side has added a file a/c, we end up
moving a/c to b/c without considering the remote version of b/c. Add a
check for this case and use the merge ('m') action in this case
instead of the directory rename ('dm') action.

Patch

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -446,8 +446,12 @@ 
                 pass # we'll deal with it on m2 side
             elif f in movewithdir: # directory rename, move local
                 f2 = movewithdir[f]
-                actions['dm'].append((f2, (f, fl1),
-                                "remote directory rename - move from " + f))
+                if f2 in m2:
+                    actions['m'].append((f2, (f, f2, None, True, pa.node()),
+                                   "remote directory rename, both created"))
+                else:
+                    actions['dm'].append((f2, (f, fl1),
+                                  "remote directory rename - move from " + f))
             elif f in copy:
                 f2 = copy[f]
                 actions['m'].append((f, (f, f2, f2, False, pa.node()),
diff --git a/tests/test-rename-dir-merge.t b/tests/test-rename-dir-merge.t
--- a/tests/test-rename-dir-merge.t
+++ b/tests/test-rename-dir-merge.t
@@ -148,8 +148,6 @@ 
 Remote directory rename with conflicting file added in remote target directory
 and committed in local source directory.
 
-BROKEN: the remote is ignored; it should be merged
-
   $ hg co -qC 2
   $ rm b/c
   $ hg st -A
@@ -158,19 +156,28 @@ 
   C a/b
   C a/c
   $ hg merge 5
-  3 files updated, 0 files merged, 2 files removed, 0 files unresolved
-  (branch merge, don't forget to commit)
+  merging a/c and b/c to b/c
+  warning: conflicts during merge.
+  merging b/c incomplete! (edit conflicts, then use 'hg resolve --mark')
+  2 files updated, 0 files merged, 2 files removed, 1 files unresolved
+  use 'hg resolve' to retry unresolved file merges or 'hg update -C .' to abandon
+  [1]
   $ hg st -A
   M b/a
   M b/b
-  A b/c
+  M b/c
     a/c
   R a/a
   R a/b
   R a/c
   ? a/d
+  ? b/c.orig
   $ cat b/c
+  <<<<<<< local: ce36d17b18fb  - test: 2 add a/c
   baz
+  =======
+  target
+  >>>>>>> other: f1c50ca4f127 - test: new file in target directory
 
 Second scenario with two repos: