Patchwork D778: merge: backup conflicting directories when getting files

login
register
mail settings
Submitter phabricator
Date Oct. 2, 2017, 9:16 p.m.
Message ID <2b34e061b8715ca9bcd4cb94da8725ce@localhost.localdomain>
Download mbox | patch
Permalink /patch/24418/
State Not Applicable
Headers show

Comments

phabricator - Oct. 2, 2017, 9:16 p.m.
mbthomas updated this revision to Diff 2355.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D778?vs=2214&id=2355

REVISION DETAIL
  https://phab.mercurial-scm.org/D778

AFFECTED FILES
  mercurial/merge.py

CHANGE DETAILS




To: mbthomas, #hg-reviewers, ryanmce
Cc: kiilerix, ryanmce, mercurial-devel

Patch

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -1167,14 +1167,18 @@ 
                 repo.ui.note(_("getting %s\n") % f)
 
             if backup:
+                # If a file or directory exists with the same name, back that
+                # up.  Otherwise, look to see if there is a file that conflicts
+                # with a directory this file is in, and if so, back that up.
                 absf = repo.wjoin(f)
+                if not repo.wvfs.lexists(f):
+                    for p in util.finddirs(f):
+                        if repo.wvfs.isfileorlink(p):
+                            absf = repo.wjoin(p)
+                            break
                 orig = scmutil.origpath(ui, repo, absf)
-                try:
-                    if repo.wvfs.isfileorlink(f):
-                        util.rename(absf, orig)
-                except OSError as e:
-                    if e.errno != errno.ENOENT:
-                        raise
+                if repo.wvfs.lexists(absf):
+                    util.rename(absf, orig)
             wctx[f].clearunknown()
             wctx[f].write(fctx(f).data(), flags, backgroundclose=True)
             if i == 100: