Show More
@@ -118,6 +118,20 b' def _reportimporterror(ui, err, failed, ' | |||
|
118 | 118 | if ui.debugflag: |
|
119 | 119 | ui.traceback() |
|
120 | 120 | |
|
121 | # attributes set by registrar.command | |
|
122 | _cmdfuncattrs = ('norepo', 'optionalrepo', 'inferrepo') | |
|
123 | ||
|
124 | def _validatecmdtable(cmdtable): | |
|
125 | """Check if extension commands have required attributes""" | |
|
126 | for c, e in cmdtable.iteritems(): | |
|
127 | f = e[0] | |
|
128 | missing = [a for a in _cmdfuncattrs if not util.safehasattr(f, a)] | |
|
129 | if not missing: | |
|
130 | continue | |
|
131 | raise error.ProgrammingError( | |
|
132 | 'missing attributes: %s' % ', '.join(missing), | |
|
133 | hint="use @command decorator to register '%s'" % c) | |
|
134 | ||
|
121 | 135 | def load(ui, name, path): |
|
122 | 136 | if name.startswith('hgext.') or name.startswith('hgext/'): |
|
123 | 137 | shortname = name[6:] |
@@ -139,6 +153,7 b' def load(ui, name, path):' | |||
|
139 | 153 | ui.warn(_('(third party extension %s requires version %s or newer ' |
|
140 | 154 | 'of Mercurial; disabling)\n') % (shortname, minver)) |
|
141 | 155 | return |
|
156 | _validatecmdtable(getattr(mod, 'cmdtable', {})) | |
|
142 | 157 | |
|
143 | 158 | _extensions[shortname] = mod |
|
144 | 159 | _order.append(shortname) |
@@ -1534,6 +1534,40 b' disabling in command line overlays with ' | |||
|
1534 | 1534 | |
|
1535 | 1535 | $ cd .. |
|
1536 | 1536 | |
|
1537 | Prohibit registration of commands that don't use @command (issue5137) | |
|
1538 | ||
|
1539 | $ hg init deprecated | |
|
1540 | $ cd deprecated | |
|
1541 | ||
|
1542 | $ cat <<EOF > deprecatedcmd.py | |
|
1543 | > def deprecatedcmd(repo, ui): | |
|
1544 | > pass | |
|
1545 | > cmdtable = { | |
|
1546 | > 'deprecatedcmd': (deprecatedcmd, [], ''), | |
|
1547 | > } | |
|
1548 | > EOF | |
|
1549 | $ cat <<EOF > .hg/hgrc | |
|
1550 | > [extensions] | |
|
1551 | > deprecatedcmd = `pwd`/deprecatedcmd.py | |
|
1552 | > mq = ! | |
|
1553 | > hgext.mq = ! | |
|
1554 | > hgext/mq = ! | |
|
1555 | > EOF | |
|
1556 | ||
|
1557 | $ hg deprecatedcmd > /dev/null | |
|
1558 | *** failed to import extension deprecatedcmd from $TESTTMP/deprecated/deprecatedcmd.py: missing attributes: norepo, optionalrepo, inferrepo | |
|
1559 | *** (use @command decorator to register 'deprecatedcmd') | |
|
1560 | hg: unknown command 'deprecatedcmd' | |
|
1561 | [255] | |
|
1562 | ||
|
1563 | the extension shouldn't be loaded at all so the mq works: | |
|
1564 | ||
|
1565 | $ hg qseries --config extensions.mq= > /dev/null | |
|
1566 | *** failed to import extension deprecatedcmd from $TESTTMP/deprecated/deprecatedcmd.py: missing attributes: norepo, optionalrepo, inferrepo | |
|
1567 | *** (use @command decorator to register 'deprecatedcmd') | |
|
1568 | ||
|
1569 | $ cd .. | |
|
1570 | ||
|
1537 | 1571 | Test synopsis and docstring extending |
|
1538 | 1572 | |
|
1539 | 1573 | $ hg init exthelp |
General Comments 0
You need to be logged in to leave comments.
Login now