# HG changeset patch # User Mark Thomas # Date 1506978330 25200 # Node ID a991e1d6bc82d8585e8b9d70c5e41da0589f401b # Parent b4955650eb57b5e9252d1c7399ecd62d980a5eec merge: backup conflicting directories when getting files During batchget, if a target file conflicts with a directory, or if the directory a target file is in conflicts with a file, backup and remove the conflicting file or directory before performing the get. Differential Revision: https://phab.mercurial-scm.org/D778 diff -r b4955650eb57 -r a991e1d6bc82 mercurial/merge.py --- a/mercurial/merge.py Mon Oct 02 14:05:30 2017 -0700 +++ b/mercurial/merge.py Mon Oct 02 14:05:30 2017 -0700 @@ -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: