diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py --- a/mercurial/subrepo.py +++ b/mercurial/subrepo.py @@ -74,6 +74,23 @@ def state(ctx, ui): raise util.Abort(_('missing ] in subrepo source')) kind, src = src.split(']', 1) kind = kind[1:] + src = src.lstrip() # strip any extra whitespace after ']' + + if not util.url(src).isabs(): + parent = _abssource(ctx._repo, abort=False) + if parent: + parent = util.url(parent) + parent.path = posixpath.join(parent.path or '', src) + parent.path = posixpath.normpath(parent.path) + joined = str(parent) + # Remap the full joined path and use it if it changes, + # else remap the original source. + remapped = remap(joined) + if remapped == joined: + src = remap(src) + else: + src = remapped + src = remap(src) state[path] = (src.strip(), rev.get(path, ''), kind) diff --git a/tests/test-subrepo-paths.t b/tests/test-subrepo-paths.t --- a/tests/test-subrepo-paths.t +++ b/tests/test-subrepo-paths.t @@ -1,19 +1,22 @@ $ hg init outer $ cd outer + $ echo '[paths]' >> .hg/hgrc + $ echo 'default = http://example.net/' >> .hg/hgrc + hg debugsub with no remapping - $ echo 'sub = http://example.net/libfoo' > .hgsub + $ echo 'sub = libfoo' > .hgsub $ hg add .hgsub $ hg debugsub path sub - source http://example.net/libfoo + source libfoo revision hg debugsub with remapping - $ echo '[subpaths]' > .hg/hgrc + $ echo '[subpaths]' >> .hg/hgrc $ printf 'http://example.net/lib(.*) = C:\\libs\\\\1-lib\\\n' >> .hg/hgrc $ hg debugsub @@ -30,6 +33,21 @@ test cumulative remapping, the $HGRCPATH source C:\libs\bar-lib\ revision +test absolute source path -- testing with a URL is important since +standard os.path.join wont treat that as an absolute path + + $ echo 'abs = http://example.net/abs' > .hgsub + $ hg debugsub + path abs + source http://example.net/abs + revision + + $ echo 'abs = /abs' > .hgsub + $ hg debugsub + path abs + source /abs + revision + test bad subpaths pattern $ cat > .hg/hgrc <