diff -r 5d16ebe7b14f -r 1e4512eac59e mercurial/merge.py --- a/mercurial/merge.py Fri Jul 01 14:09:53 2016 +0200 +++ b/mercurial/merge.py Fri Jul 01 17:42:55 2016 +0200 @@ -1076,15 +1076,14 @@ absf = repo.wjoin(f) orig = scmutil.origpath(ui, repo, absf) try: - # TODO Mercurial has always aborted if an untracked - # directory is replaced by a tracked file, or generally - # with file/directory merges. This needs to be sorted out. if repo.wvfs.isfileorlink(f): util.rename(absf, orig) except OSError as e: if e.errno != errno.ENOENT: raise + if repo.wvfs.isdir(f): + repo.wvfs.removedirs(f) wwrite(f, fctx(f).data(), flags, backgroundclose=True) if i == 100: yield i, f