Skip to content
Snippets Groups Projects
Commit 5e27afeddaee authored by Yuya Nishihara's avatar Yuya Nishihara
Browse files

subrepo: add config option to reject any subrepo operations (SEC)

This is an alternative workaround for the issue5730.

Perhaps this is the simplest way of disabling subrepo operations. It does
nothing clever, but just aborts if Mercurial starts accessing to a subrepo.

I think Greg's patch is more useful since it allows us to at least check
out the parent repository. However, that would be confusing if the default
is flipped to checkout=False and subrepos are silently ignored.

I don't like the config name 'allowed', but I couldn't get any better name.
parent 071cbeba4212
No related branches found
No related tags found
No related merge requests found
......@@ -811,6 +811,9 @@
coreconfigitem('sparse', 'missingwarning',
default=True,
)
coreconfigitem('subrepos', 'allowed',
default=dynamicdefault, # to make backporting simpler
)
coreconfigitem('templates', '.*',
default=None,
generic=True,
......
......@@ -1893,6 +1893,19 @@
doesn't match the full path, an attempt is made to apply it on the
relative path alone. The rules are applied in definition order.
``subrepos``
------------
This section contains options that control the behavior of the
subrepositories feature. See also :hg:`help subrepos`.
``allowed``
Whether subrepository operation in the working directory is allowed.
When disabled, any commands including :hg:`update` will fail if
subrepositories are involved.
(default: True)
``templatealias``
-----------------
......
......@@ -365,6 +365,13 @@
if repo.wvfs.islink(path):
raise error.Abort(_("subrepo '%s' traverses symbolic link") % path)
def _checktype(ui, kind):
if not ui.configbool('subrepos', 'allowed', True):
raise error.Abort(_("subrepo not allowed"),
hint=_("see 'hg help config.subrepos' for details"))
if kind not in types:
raise error.Abort(_('unknown subrepo type %s') % kind)
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
......@@ -375,5 +382,6 @@
from . import hg as h
hg = h
_auditsubrepopath(ctx.repo(), path)
repo = ctx.repo()
_auditsubrepopath(repo, path)
state = ctx.substate[path]
......@@ -379,6 +387,5 @@
state = ctx.substate[path]
if state[2] not in types:
raise error.Abort(_('unknown subrepo type %s') % state[2])
_checktype(repo.ui, state[2])
if allowwdir:
state = (state[0], ctx.subrev(path), state[2])
return types[state[2]](ctx, path, state[:2], allowcreate)
......@@ -393,5 +400,6 @@
from . import hg as h
hg = h
_auditsubrepopath(ctx.repo(), path)
repo = ctx.repo()
_auditsubrepopath(repo, path)
state = ctx.substate[path]
......@@ -397,6 +405,5 @@
state = ctx.substate[path]
if state[2] not in types:
raise error.Abort(_('unknown subrepo type %s') % state[2])
_checktype(repo.ui, state[2])
subrev = ''
if state[2] == 'hg':
subrev = "0" * 40
......
......@@ -86,6 +86,25 @@
path s
source ../gitroot
revision 126f2a14290cd5ce061fdedc430170e8d39e1c5a
$ cd ..
clone with subrepo disabled (update should fail)
$ hg clone t -U tc2 --config subrepos.allowed=false
$ hg update -R tc2 --config subrepos.allowed=false
abort: subrepo not allowed
(see 'hg help config.subrepos' for details)
[255]
$ ls tc2
a
$ hg clone t tc3 --config subrepos.allowed=false
updating to branch default
abort: subrepo not allowed
(see 'hg help config.subrepos' for details)
[255]
$ ls tc3
a
update to previous substate
......@@ -89,6 +108,7 @@
update to previous substate
$ cd tc
$ hg update 1 -q
$ cat s/g
g
......
......@@ -484,6 +484,25 @@
path t
source t
revision 20a0db6fbf6c3d2836e6519a642ae929bfc67c0e
$ cd ..
clone with subrepo disabled (update should fail)
$ hg clone t -U tc2 --config subrepos.allowed=false
$ hg update -R tc2 --config subrepos.allowed=false
abort: subrepo not allowed
(see 'hg help config.subrepos' for details)
[255]
$ ls tc2
a
$ hg clone t tc3 --config subrepos.allowed=false
updating to branch default
abort: subrepo not allowed
(see 'hg help config.subrepos' for details)
[255]
$ ls tc3
a
push
......@@ -487,6 +506,7 @@
push
$ cd tc
$ echo bah > t/t
$ hg ci -m11
committing subrepository t
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment