[PATCH 2 of 2] update: improve behaviour when working directory is removed (issue2293)

Nicolas Dumazet nicdumz at gmail.com
Tue Jul 20 01:17:37 CDT 2010


# HG changeset patch
# User Nicolas Dumazet <nicdumz.commits at gmail.com>
# Date 1279592973 -32400
# Node ID c4406f92fb047ff278f5404b7bc9d15f53bd24da
# Parent  a3660fbdb439bcf7201ceba09abc568d2ce950a3
update: improve behaviour when working directory is removed (issue2293)

chdir to repository root to apply changes, and try to chdir back into
the old working directory after applying changes.
If old working directory was removed in the process, warn the user about
it, and stay in repository root.

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -512,7 +512,16 @@
         if not partial:
             repo.hook('preupdate', throw=True, parent1=xp1, parent2=xp2)
 
+        curdir = os.getcwd()
+        os.chdir(repo.root)
         stats = applyupdates(repo, action, wc, p2, pa)
+        try:
+            os.chdir(curdir)
+        except OSError, inst:
+            if inst.errno != errno.ENOENT:
+                raise
+            repo.ui.warn(_("working directory was removed during update\n"))
+
 
         if not partial:
             repo.dirstate.setparents(fp1, fp2)
diff --git a/tests/test-remove-cwd.out b/tests/test-remove-cwd.out
--- a/tests/test-remove-cwd.out
+++ b/tests/test-remove-cwd.out
@@ -1,4 +1,5 @@
 adding a/a
+working directory was removed during update
 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
 % run hg from removed directory
 'import site' failed; use -v for traceback


More information about the Mercurial-devel mailing list