[PATCH] subrepo: precisely identify the missing subrepo spec file

Matt Harbison mharbison72 at gmail.com
Tue Apr 7 01:32:45 UTC 2015


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1428260935 14400
#      Sun Apr 05 15:08:55 2015 -0400
# Node ID 88ad50d9bedc8010d6267b3a7ebdc22389920c89
# Parent  b2fb1403994e033584aed8a487ab162a9d75fa80
subrepo: precisely identify the missing subrepo spec file

It isn't obvious which file is the problem with deep subrepos, so provide the
path.  Since the parsing is done with a ctx and not a subrepo object, it isn't
possible to display a path from the root subrepo.  Therefore, the path shown is
relative to cwd.

There's no test coverage for the first abort, and I couldn't figure out how to
trigger it, but it is changed for consistency.

diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -70,11 +70,14 @@
                 if err.errno != errno.ENOENT:
                     raise
                 # handle missing subrepo spec files as removed
-                ui.warn(_("warning: subrepo spec file %s not found\n") % f)
+                ui.warn(_("warning: subrepo spec file \'%s\' not found\n") %
+                        util.pathto(ctx.repo().root, ctx.repo().getcwd(), f))
                 return
             p.parse(f, data, sections, remap, read)
         else:
-            raise util.Abort(_("subrepo spec file %s not found") % f)
+            repo = ctx.repo()
+            raise util.Abort(_("subrepo spec file \'%s\' not found") %
+                             util.pathto(repo.root, repo.getcwd(), f))
 
     if '.hgsub' in ctx:
         read('.hgsub')
@@ -92,9 +95,11 @@
                 try:
                     revision, path = l.split(" ", 1)
                 except ValueError:
+                    repo = ctx.repo()
                     raise util.Abort(_("invalid subrepository revision "
-                                       "specifier in .hgsubstate line %d")
-                                     % (i + 1))
+                                       "specifier in \'%s\' line %d")
+                                     % (util.pathto(repo.root, repo.getcwd(),
+                                        '.hgsubstate'), (i + 1)))
                 rev[path] = revision
         except IOError, err:
             if err.errno != errno.ENOENT:
diff --git a/tests/test-mq-subrepo.t b/tests/test-mq-subrepo.t
--- a/tests/test-mq-subrepo.t
+++ b/tests/test-mq-subrepo.t
@@ -299,7 +299,7 @@
   +sub = sub
   record this change to '.hgsub'? [Ynesfdaq?] y
   
-  warning: subrepo spec file .hgsub not found
+  warning: subrepo spec file '.hgsub' not found
   abort: uncommitted changes in subrepository 'sub'
   [255]
   % update substate when adding .hgsub w/clean updated subrepo
@@ -313,7 +313,7 @@
   +sub = sub
   record this change to '.hgsub'? [Ynesfdaq?] y
   
-  warning: subrepo spec file .hgsub not found
+  warning: subrepo spec file '.hgsub' not found
   path sub
    source   sub
    revision b2fdb12cd82b021c3b7053d67802e77b6eeaee31
diff --git a/tests/test-subrepo-deep-nested-change.t b/tests/test-subrepo-deep-nested-change.t
--- a/tests/test-subrepo-deep-nested-change.t
+++ b/tests/test-subrepo-deep-nested-change.t
@@ -141,9 +141,14 @@
   $ hg status -S
   $ hg remove sub1/sub2/folder/test.txt
   $ hg remove sub1/.hgsubstate
+  $ mv sub1/.hgsub sub1/x.hgsub
   $ hg status -S
+  warning: subrepo spec file 'sub1/.hgsub' not found (glob)
   R sub1/.hgsubstate
   R sub1/sub2/folder/test.txt
+  ! sub1/.hgsub
+  ? sub1/x.hgsub
+  $ mv sub1/x.hgsub sub1/.hgsub
   $ hg update -Cq
   $ touch sub1/foo
   $ hg forget sub1/sub2/folder/test.txt
diff --git a/tests/test-subrepo-missing.t b/tests/test-subrepo-missing.t
--- a/tests/test-subrepo-missing.t
+++ b/tests/test-subrepo-missing.t
@@ -24,7 +24,7 @@
   $ cp .hgsubstate .hgsubstate.old
   >>> file('.hgsubstate', 'wb').write('\ninvalid')
   $ hg st --subrepos
-  abort: invalid subrepository revision specifier in .hgsubstate line 2
+  abort: invalid subrepository revision specifier in '.hgsubstate' line 2
   [255]
   $ mv .hgsubstate.old .hgsubstate
 
@@ -32,9 +32,9 @@
 
   $ rm .hgsub
   $ hg revert .hgsub
-  warning: subrepo spec file .hgsub not found
-  warning: subrepo spec file .hgsub not found
-  warning: subrepo spec file .hgsub not found
+  warning: subrepo spec file '.hgsub' not found
+  warning: subrepo spec file '.hgsub' not found
+  warning: subrepo spec file '.hgsub' not found
 
 delete .hgsubstate and revert it
 
@@ -45,11 +45,11 @@
 
   $ rm .hgsub
   $ hg up 0
-  warning: subrepo spec file .hgsub not found
-  warning: subrepo spec file .hgsub not found
+  warning: subrepo spec file '.hgsub' not found
+  warning: subrepo spec file '.hgsub' not found
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ hg st
-  warning: subrepo spec file .hgsub not found
+  warning: subrepo spec file '.hgsub' not found
   ! .hgsub
   $ ls subrepo
   a
@@ -57,8 +57,8 @@
 delete .hgsubstate and update
 
   $ hg up -C
-  warning: subrepo spec file .hgsub not found
-  warning: subrepo spec file .hgsub not found
+  warning: subrepo spec file '.hgsub' not found
+  warning: subrepo spec file '.hgsub' not found
   2 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ rm .hgsubstate
   $ hg up 0


More information about the Mercurial-devel mailing list