diff --git a/mercurial/merge.py b/mercurial/merge.py --- a/mercurial/merge.py +++ b/mercurial/merge.py @@ -1088,12 +1088,7 @@ yields tuples for progress updates """ verbose = repo.ui.verbose - try: - cwd = pycompat.getcwd() - except OSError as err: - if err.errno != errno.ENOENT: - raise - cwd = None + cwd = _getcwd() i = 0 for f, args, msg in actions: repo.ui.debug(" %s: %s -> r\n" % (f, msg)) @@ -1111,18 +1106,8 @@ i += 1 if i > 0: yield i, f - if cwd: - # cwd was present before we started to remove files - # let's check if it is present after we removed them - try: - pycompat.getcwd() - except OSError as err: - if err.errno != errno.ENOENT: - raise - # Print a warning if cwd was deleted - repo.ui.warn(_("current directory was removed\n" - "(consider changing to repo root: %s)\n") % - repo.root) + + _warnifmissingcwd(repo, cwd) def batchget(repo, mctx, wctx, actions): """apply gets to the working directory @@ -1756,3 +1741,20 @@ # fix up dirstate for copies and renames copies.duplicatecopies(repo, ctx.rev(), pctx.rev()) return stats + +def _getcwd(): + try: + return pycompat.getcwd() + except OSError as err: + if err.errno != errno.ENOENT: + raise + return None + +def _warnifmissingcwd(repo, oldcwd): + # cwd was present before we started to remove files + # let's check if it is present after we removed them + if oldcwd and not _getcwd(): + # Print a warning if cwd was deleted + repo.ui.warn(_("current directory was removed\n" + "(consider changing to repo root: %s)\n") % + repo.root)