subrepo: handle missing subrepo spec file as removed stable
authorPatrick Mezard <pmezard@gmail.com>
Thu, 18 Nov 2010 23:05:10 +0100
branchstable
changeset 13017 d0e21c5fde41
parent 13015 82ca0c43bc44
child 13018 96956105e92d
child 13020 ea3bada953d3
subrepo: handle missing subrepo spec file as removed Otherwise, all commands involving a dirstate walk will abort when trying to readone of them. Deleting .hgsub basically breaks a repository.
mercurial/subrepo.py
tests/test-subrepo-missing.t
--- a/mercurial/subrepo.py	Wed Nov 17 21:25:23 2010 +0100
+++ b/mercurial/subrepo.py	Thu Nov 18 23:05:10 2010 +0100
@@ -21,7 +21,15 @@
     p = config.config()
     def read(f, sections=None, remap=None):
         if f in ctx:
-            p.parse(f, ctx[f].data(), sections, remap, read)
+            try:
+                data = ctx[f].data()
+            except IOError, err:
+                if err.errno != errno.ENOENT:
+                    raise
+                # handle missing subrepo spec files as removed
+                ui.warn(_("warning: subrepo spec file %s not found\n") % f)
+                return
+            p.parse(f, data, sections, remap, read)
         else:
             raise util.Abort(_("subrepo spec file %s not found") % f)
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-subrepo-missing.t	Thu Nov 18 23:05:10 2010 +0100
@@ -0,0 +1,51 @@
+  $ hg init repo
+  $ cd repo
+  $ hg init subrepo
+  $ echo a > subrepo/a
+  $ hg -R subrepo ci -Am adda
+  adding a
+  $ echo 'subrepo = subrepo' > .hgsub
+  $ hg ci -Am addsubrepo
+  adding .hgsub
+  committing subrepository subrepo
+  $ echo b > subrepo/b
+  $ hg -R subrepo ci -Am addb
+  adding b
+  $ hg ci -m updatedsub
+  committing subrepository subrepo
+
+delete .hgsub and revert it
+
+  $ rm .hgsub
+  $ hg revert .hgsub
+  warning: subrepo spec file .hgsub not found
+
+delete .hgsubstate and revert it
+
+  $ rm .hgsubstate
+  $ hg revert .hgsubstate
+
+delete .hgsub and update
+
+  $ rm .hgsub
+  $ hg up 0
+  warning: subrepo spec file .hgsub not found
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg st
+  ! .hgsub
+  $ ls subrepo
+  a
+
+delete .hgsubstate and update
+
+  $ hg up -C
+  warning: subrepo spec file .hgsub not found
+  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ rm .hgsubstate
+  $ hg up 0  
+  remote changed .hgsubstate which local deleted
+  use (c)hanged version or leave (d)eleted? c
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg st
+  $ ls subrepo
+  a