##// END OF EJS Templates
extension: add a `required` suboption to enforce the use of an extensions...
marmoute -
r49184:0d0ce252 default
parent child Browse files
Show More
@@ -1286,6 +1286,12 b' coreconfigitem('
1286 generic=True,
1286 generic=True,
1287 )
1287 )
1288 coreconfigitem(
1288 coreconfigitem(
1289 b'extensions',
1290 b'[^:]*:required',
1291 default=False,
1292 generic=True,
1293 )
1294 coreconfigitem(
1289 b'extdata',
1295 b'extdata',
1290 b'.*',
1296 b'.*',
1291 default=None,
1297 default=None,
@@ -314,6 +314,19 b' def loadall(ui, whitelist=None):'
314 else:
314 else:
315 error_msg = _(b'failed to import extension "%s": %s')
315 error_msg = _(b'failed to import extension "%s": %s')
316 error_msg %= (name, msg)
316 error_msg %= (name, msg)
317
318 ext_options = ui.configsuboptions(b"extensions", name)[1]
319 if stringutil.parsebool(ext_options.get(b"required", b'no')):
320 hint = None
321 if isinstance(inst, error.Hint) and inst.hint:
322 hint = inst.hint
323 if hint is None:
324 hint = _(
325 b"loading of this extension was required, "
326 b"see `hg help config.extensions` for details"
327 )
328 raise error.Abort(error_msg, hint=hint)
329 else:
317 ui.warn((b"*** %s\n") % error_msg)
330 ui.warn((b"*** %s\n") % error_msg)
318 if isinstance(inst, error.Hint) and inst.hint:
331 if isinstance(inst, error.Hint) and inst.hint:
319 ui.warn(_(b"*** (%s)\n") % inst.hint)
332 ui.warn(_(b"*** (%s)\n") % inst.hint)
@@ -850,6 +850,17 b' Example for ``~/.hgrc``::'
850 # (this extension will get loaded from the file specified)
850 # (this extension will get loaded from the file specified)
851 myfeature = ~/.hgext/myfeature.py
851 myfeature = ~/.hgext/myfeature.py
852
852
853 If an extension fails to load, a warning will be issued, and Mercurial will
854 proceed. To enforce that an extension must be loaded, one can set the `required`
855 suboption in the config::
856
857 [extensions]
858 myfeature = ~/.hgext/myfeature.py
859 myfeature:required = yes
860
861 To debug extension loading issue, one can add `--traceback` to their mercurial
862 invocation.
863
853
864
854 ``format``
865 ``format``
855 ----------
866 ----------
@@ -1944,3 +1944,94 b' Prohibit the use of unicode strings as t'
1944 hg: unknown command 'dummy'
1944 hg: unknown command 'dummy'
1945 (did you mean summary?)
1945 (did you mean summary?)
1946 [10]
1946 [10]
1947
1948 Check the mandatory extension feature
1949 -------------------------------------
1950
1951 $ hg init mandatory-extensions
1952 $ cat > $TESTTMP/mandatory-extensions/.hg/good.py << EOF
1953 > pass
1954 > EOF
1955 $ cat > $TESTTMP/mandatory-extensions/.hg/bad.py << EOF
1956 > raise RuntimeError("babar")
1957 > EOF
1958 $ cat > $TESTTMP/mandatory-extensions/.hg/syntax.py << EOF
1959 > def (
1960 > EOF
1961
1962 Check that the good one load :
1963
1964 $ cat > $TESTTMP/mandatory-extensions/.hg/hgrc << EOF
1965 > [extensions]
1966 > good = $TESTTMP/mandatory-extensions/.hg/good.py
1967 > EOF
1968
1969 $ hg -R mandatory-extensions id
1970 000000000000 tip
1971
1972 Make it mandatory to load
1973
1974 $ cat >> $TESTTMP/mandatory-extensions/.hg/hgrc << EOF
1975 > good:required = yes
1976 > EOF
1977
1978 $ hg -R mandatory-extensions id
1979 000000000000 tip
1980
1981 Check that the bad one does not load
1982
1983 $ cat >> $TESTTMP/mandatory-extensions/.hg/hgrc << EOF
1984 > bad = $TESTTMP/mandatory-extensions/.hg/bad.py
1985 > EOF
1986
1987 $ hg -R mandatory-extensions id
1988 *** failed to import extension "bad" from $TESTTMP/mandatory-extensions/.hg/bad.py: babar
1989 000000000000 tip
1990
1991 Make it mandatory to load
1992
1993 $ cat >> $TESTTMP/mandatory-extensions/.hg/hgrc << EOF
1994 > bad:required = yes
1995 > EOF
1996
1997 $ hg -R mandatory-extensions id
1998 abort: failed to import extension "bad" from $TESTTMP/mandatory-extensions/.hg/bad.py: babar
1999 (loading of this extension was required, see `hg help config.extensions` for details)
2000 [255]
2001
2002 Make it not mandatory to load
2003
2004 $ cat >> $TESTTMP/mandatory-extensions/.hg/hgrc << EOF
2005 > bad:required = no
2006 > EOF
2007
2008 $ hg -R mandatory-extensions id
2009 *** failed to import extension "bad" from $TESTTMP/mandatory-extensions/.hg/bad.py: babar
2010 000000000000 tip
2011
2012 Same check with the syntax error one
2013
2014 $ cat >> $TESTTMP/mandatory-extensions/.hg/hgrc << EOF
2015 > bad = !
2016 > syntax = $TESTTMP/mandatory-extensions/.hg/syntax.py
2017 > syntax:required = yes
2018 > EOF
2019
2020 $ hg -R mandatory-extensions id
2021 abort: failed to import extension "syntax" from $TESTTMP/mandatory-extensions/.hg/syntax.py: invalid syntax (*syntax.py, line 1) (glob)
2022 (loading of this extension was required, see `hg help config.extensions` for details)
2023 [255]
2024
2025 Same check with a missing one
2026
2027 $ cat >> $TESTTMP/mandatory-extensions/.hg/hgrc << EOF
2028 > syntax = !
2029 > syntax:required =
2030 > missing = foo/bar/baz/I/do/not/exist/
2031 > missing:required = yes
2032 > EOF
2033
2034 $ hg -R mandatory-extensions id
2035 abort: failed to import extension "missing" from foo/bar/baz/I/do/not/exist/: [Errno 2] $ENOENT$: 'foo/bar/baz/I/do/not/exist'
2036 (loading of this extension was required, see `hg help config.extensions` for details)
2037 [255]
General Comments 0
You need to be logged in to leave comments. Login now