diff --git a/mercurial/context.py b/mercurial/context.py --- a/mercurial/context.py +++ b/mercurial/context.py @@ -275,9 +275,9 @@ class basectx(object): except error.LookupError: return '' - def sub(self, path): + def sub(self, path, allowcreate=True): '''return a subrepo for the stored revision of path, never wdir()''' - return subrepo.subrepo(self, path) + return subrepo.subrepo(self, path, allowcreate=allowcreate) def nullsub(self, path, pctx): return subrepo.nullsubrepo(self, path, pctx) diff --git a/mercurial/hg.py b/mercurial/hg.py --- a/mercurial/hg.py +++ b/mercurial/hg.py @@ -886,7 +886,11 @@ def verify(repo): ctx = repo[rev] try: for subpath in ctx.substate: - ret = ctx.sub(subpath).verify() or ret + try: + ret = (ctx.sub(subpath, allowcreate=False).verify() + or ret) + except error.RepoError as e: + repo.ui.warn(_('%s: %s\n') % (rev, e)) except Exception: repo.ui.warn(_('.hgsubstate is corrupt in revision %s\n') % node.short(ctx.node())) diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py --- a/mercurial/subrepo.py +++ b/mercurial/subrepo.py @@ -340,7 +340,7 @@ def _sanitize(ui, vfs, ignore): "in '%s'\n") % vfs.join(dirname)) vfs.unlink(vfs.reljoin(dirname, f)) -def subrepo(ctx, path, allowwdir=False): +def subrepo(ctx, path, allowwdir=False, allowcreate=True): """return instance of the right subrepo class for subrepo in path""" # subrepo inherently violates our import layering rules # because it wants to make repo objects from deep inside the stack @@ -356,7 +356,7 @@ def subrepo(ctx, path, allowwdir=False): raise error.Abort(_('unknown subrepo type %s') % state[2]) if allowwdir: state = (state[0], ctx.subrev(path), state[2]) - return types[state[2]](ctx, path, state[:2]) + return types[state[2]](ctx, path, state[:2], allowcreate) def nullsubrepo(ctx, path, pctx): """return an empty subrepo in pctx for the extant subrepo in ctx""" @@ -375,7 +375,7 @@ def nullsubrepo(ctx, path, pctx): subrev = '' if state[2] == 'hg': subrev = "0" * 40 - return types[state[2]](pctx, path, (state[0], subrev)) + return types[state[2]](pctx, path, (state[0], subrev), True) def newcommitphase(ui, ctx): commitphase = phases.newcommitphase(ui) @@ -611,12 +611,12 @@ class abstractsubrepo(object): return self.wvfs.reljoin(reporelpath(self._ctx.repo()), self._path) class hgsubrepo(abstractsubrepo): - def __init__(self, ctx, path, state): + def __init__(self, ctx, path, state, allowcreate): super(hgsubrepo, self).__init__(ctx, path) self._state = state r = ctx.repo() root = r.wjoin(path) - create = not r.wvfs.exists('%s/.hg' % path) + create = allowcreate and not r.wvfs.exists('%s/.hg' % path) self._repo = hg.repository(r.baseui, root, create=create) # Propagate the parent's --hidden option @@ -1064,7 +1064,7 @@ class hgsubrepo(abstractsubrepo): return reporelpath(self._repo) class svnsubrepo(abstractsubrepo): - def __init__(self, ctx, path, state): + def __init__(self, ctx, path, state, allowcreate): super(svnsubrepo, self).__init__(ctx, path) self._state = state self._exe = util.findexe('svn') @@ -1284,7 +1284,7 @@ class svnsubrepo(abstractsubrepo): class gitsubrepo(abstractsubrepo): - def __init__(self, ctx, path, state): + def __init__(self, ctx, path, state, allowcreate): super(gitsubrepo, self).__init__(ctx, path) self._state = state self._abspath = ctx.repo().wjoin(path) 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 @@ -121,4 +121,22 @@ verify will warn if locked-in subrepo re subrepo 'subrepo' is hidden in revision 674d05939c1e subrepo 'subrepo' not found in revision a7d05d9055a4 +verifying shouldn't init a new subrepo if the reference doesn't exist + + $ mv subrepo b + $ hg verify + checking changesets + checking manifests + crosschecking files in changesets and manifests + checking files + 2 files, 5 changesets, 5 total revisions + checking subrepo links + 0: repository $TESTTMP/repo/subrepo not found (glob) + 1: repository $TESTTMP/repo/subrepo not found (glob) + 3: repository $TESTTMP/repo/subrepo not found (glob) + 4: repository $TESTTMP/repo/subrepo not found (glob) + $ ls + b + $ mv b subrepo + $ cd ..