diff --git a/mercurial/context.py b/mercurial/context.py --- a/mercurial/context.py +++ b/mercurial/context.py @@ -249,11 +249,18 @@ class basectx(object): return '' def sub(self, path): + '''return a subrepo for the stored revision of path, never wdir()''' return subrepo.subrepo(self, path) def nullsub(self, path, pctx): return subrepo.nullsubrepo(self, path, pctx) + def workingsub(self, path): + '''return a subrepo for the stored revision, or wdir if this is a wdir + context. + ''' + return subrepo.subrepo(self, path, allowwdir=True) + def match(self, pats=[], include=None, exclude=None, default='glob', listsubrepos=False, badfn=None): r = self._repo diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py --- a/mercurial/subrepo.py +++ b/mercurial/subrepo.py @@ -324,7 +324,7 @@ def _sanitize(ui, vfs, ignore): "in '%s'\n") % vfs.join(dirname)) vfs.unlink(vfs.reljoin(dirname, f)) -def subrepo(ctx, path): +def subrepo(ctx, path, allowwdir=False): """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 @@ -338,6 +338,8 @@ def subrepo(ctx, path): state = ctx.substate[path] if state[2] not in types: raise util.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]) def nullsubrepo(ctx, path, pctx):