| 1 |
Test basic extension support |
| 2 |
|
| 3 |
Setting PYTHONPATH can confuse virtual env (sigh) so we have to be careful when |
| 4 |
we update it. In addition, we have to handle the case where PYTHON is not |
| 5 |
already defined. So we create a "correct and ready to use" variable for the |
| 6 |
place where we need to touch it later in the tests. |
| 7 |
|
| 8 |
We preventively export PYTHONPATH otherwise setting it in later command won't |
| 9 |
be inherited by the Mercurial process. |
| 10 |
|
| 11 |
#if py311 |
| 12 |
$ PYTHONPATH_PREFIX="`$PYTHON -P -c \"import os, sys; print(os.pathsep.join(sys.path+['']))\"`" |
| 13 |
#else |
| 14 |
Python <= 3.10 does not have the -P option |
| 15 |
$ PYTHONPATH_PREFIX="`$PYTHON -c \"import os, sys; print(os.pathsep.join([p for p in sys.path if p]+['']))\"`" |
| 16 |
#endif |
| 17 |
$ export PYTHONPATH_PREFIX |
| 18 |
$ export PYTHONPATH |
| 19 |
|
| 20 |
$ cat > foobar.py <<EOF |
| 21 |
> import os |
| 22 |
> from mercurial import commands, exthelper, registrar |
| 23 |
> |
| 24 |
> eh = exthelper.exthelper() |
| 25 |
> eh.configitem(b'tests', b'foo', default=b"Foo") |
| 26 |
> |
| 27 |
> uisetup = eh.finaluisetup |
| 28 |
> uipopulate = eh.finaluipopulate |
| 29 |
> reposetup = eh.finalreposetup |
| 30 |
> cmdtable = eh.cmdtable |
| 31 |
> configtable = eh.configtable |
| 32 |
> |
| 33 |
> @eh.uisetup |
| 34 |
> def _uisetup(ui): |
| 35 |
> ui.debug(b"uisetup called [debug]\\n") |
| 36 |
> ui.write(b"uisetup called\\n") |
| 37 |
> ui.status(b"uisetup called [status]\\n") |
| 38 |
> ui.flush() |
| 39 |
> @eh.uipopulate |
| 40 |
> def _uipopulate(ui): |
| 41 |
> ui._populatecnt = getattr(ui, "_populatecnt", 0) + 1 |
| 42 |
> ui.write(b"uipopulate called (%d times)\n" % ui._populatecnt) |
| 43 |
> @eh.reposetup |
| 44 |
> def _reposetup(ui, repo): |
| 45 |
> ui.write(b"reposetup called for %s\\n" % os.path.basename(repo.root)) |
| 46 |
> ui.write(b"ui %s= repo.ui\\n" % (ui == repo.ui and b"=" or b"!")) |
| 47 |
> ui.flush() |
| 48 |
> @eh.command(b'foo', [], b'hg foo') |
| 49 |
> def foo(ui, *args, **kwargs): |
| 50 |
> foo = ui.config(b'tests', b'foo') |
| 51 |
> ui.write(foo) |
| 52 |
> ui.write(b"\\n") |
| 53 |
> @eh.command(b'bar', [], b'hg bar', norepo=True) |
| 54 |
> def bar(ui, *args, **kwargs): |
| 55 |
> ui.write(b"Bar\\n") |
| 56 |
> EOF |
| 57 |
$ abspath=`pwd`/foobar.py |
| 58 |
|
| 59 |
$ mkdir barfoo |
| 60 |
$ cp foobar.py barfoo/__init__.py |
| 61 |
$ barfoopath=`pwd`/barfoo |
| 62 |
|
| 63 |
$ hg init a |
| 64 |
$ cd a |
| 65 |
$ echo foo > file |
| 66 |
$ hg add file |
| 67 |
$ hg commit -m 'add file' |
| 68 |
|
| 69 |
$ echo '[extensions]' >> $HGRCPATH |
| 70 |
$ echo "foobar = $abspath" >> $HGRCPATH |
| 71 |
$ hg foo |
| 72 |
uisetup called |
| 73 |
uisetup called [status] |
| 74 |
uipopulate called (1 times) |
| 75 |
uipopulate called (1 times) |
| 76 |
uipopulate called (1 times) |
| 77 |
reposetup called for a |
| 78 |
ui == repo.ui |
| 79 |
uipopulate called (1 times) (chg !) |
| 80 |
uipopulate called (1 times) (chg !) |
| 81 |
uipopulate called (1 times) (chg !) |
| 82 |
uipopulate called (1 times) (chg !) |
| 83 |
uipopulate called (1 times) (chg !) |
| 84 |
reposetup called for a (chg !) |
| 85 |
ui == repo.ui (chg !) |
| 86 |
Foo |
| 87 |
$ hg foo --quiet |
| 88 |
uisetup called (no-chg !) |
| 89 |
uipopulate called (1 times) |
| 90 |
uipopulate called (1 times) |
| 91 |
uipopulate called (1 times) (chg !) |
| 92 |
uipopulate called (1 times) (chg !) |
| 93 |
uipopulate called (1 times) |
| 94 |
reposetup called for a |
| 95 |
ui == repo.ui |
| 96 |
Foo |
| 97 |
$ hg foo --debug |
| 98 |
uisetup called [debug] (no-chg !) |
| 99 |
uisetup called (no-chg !) |
| 100 |
uisetup called [status] (no-chg !) |
| 101 |
uipopulate called (1 times) |
| 102 |
uipopulate called (1 times) |
| 103 |
uipopulate called (1 times) (chg !) |
| 104 |
uipopulate called (1 times) (chg !) |
| 105 |
uipopulate called (1 times) |
| 106 |
reposetup called for a |
| 107 |
ui == repo.ui |
| 108 |
Foo |
| 109 |
|
| 110 |
$ cd .. |
| 111 |
$ hg clone a b |
| 112 |
uisetup called (no-chg !) |
| 113 |
uisetup called [status] (no-chg !) |
| 114 |
uipopulate called (1 times) |
| 115 |
uipopulate called (1 times) (chg !) |
| 116 |
uipopulate called (1 times) |
| 117 |
uipopulate called (1 times) |
| 118 |
uipopulate called (1 times) (chg !) |
| 119 |
reposetup called for a |
| 120 |
ui == repo.ui |
| 121 |
uipopulate called (1 times) |
| 122 |
uipopulate called (1 times) |
| 123 |
reposetup called for b |
| 124 |
ui == repo.ui |
| 125 |
updating to branch default |
| 126 |
1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 127 |
|
| 128 |
$ hg bar |
| 129 |
uisetup called (no-chg !) |
| 130 |
uisetup called [status] (no-chg !) |
| 131 |
uipopulate called (1 times) |
| 132 |
uipopulate called (1 times) |
| 133 |
uipopulate called (1 times) (chg !) |
| 134 |
uipopulate called (1 times) (chg !) |
| 135 |
Bar |
| 136 |
$ echo 'foobar = !' >> $HGRCPATH |
| 137 |
|
| 138 |
module/__init__.py-style |
| 139 |
|
| 140 |
$ echo "barfoo = $barfoopath" >> $HGRCPATH |
| 141 |
$ cd a |
| 142 |
$ hg foo |
| 143 |
uisetup called |
| 144 |
uisetup called [status] |
| 145 |
uipopulate called (1 times) |
| 146 |
uipopulate called (1 times) |
| 147 |
uipopulate called (1 times) |
| 148 |
reposetup called for a |
| 149 |
ui == repo.ui |
| 150 |
uipopulate called (1 times) (chg !) |
| 151 |
uipopulate called (1 times) (chg !) |
| 152 |
uipopulate called (1 times) (chg !) |
| 153 |
uipopulate called (1 times) (chg !) |
| 154 |
uipopulate called (1 times) (chg !) |
| 155 |
reposetup called for a (chg !) |
| 156 |
ui == repo.ui (chg !) |
| 157 |
Foo |
| 158 |
$ echo 'barfoo = !' >> $HGRCPATH |
| 159 |
|
| 160 |
Check that extensions are loaded in phases: |
| 161 |
|
| 162 |
$ cat > foo.py <<EOF |
| 163 |
> import os |
| 164 |
> from mercurial import exthelper |
| 165 |
> from mercurial.utils import procutil |
| 166 |
> |
| 167 |
> def write(msg): |
| 168 |
> procutil.stdout.write(msg) |
| 169 |
> procutil.stdout.flush() |
| 170 |
> |
| 171 |
> name = os.path.basename(__file__).rsplit('.', 1)[0] |
| 172 |
> bytesname = name.encode('utf-8') |
| 173 |
> write(b"1) %s imported\n" % bytesname) |
| 174 |
> eh = exthelper.exthelper() |
| 175 |
> @eh.uisetup |
| 176 |
> def _uisetup(ui): |
| 177 |
> write(b"2) %s uisetup\n" % bytesname) |
| 178 |
> @eh.extsetup |
| 179 |
> def _extsetup(ui): |
| 180 |
> write(b"3) %s extsetup\n" % bytesname) |
| 181 |
> @eh.uipopulate |
| 182 |
> def _uipopulate(ui): |
| 183 |
> write(b"4) %s uipopulate\n" % bytesname) |
| 184 |
> @eh.reposetup |
| 185 |
> def _reposetup(ui, repo): |
| 186 |
> write(b"5) %s reposetup\n" % bytesname) |
| 187 |
> |
| 188 |
> extsetup = eh.finalextsetup |
| 189 |
> reposetup = eh.finalreposetup |
| 190 |
> uipopulate = eh.finaluipopulate |
| 191 |
> uisetup = eh.finaluisetup |
| 192 |
> revsetpredicate = eh.revsetpredicate |
| 193 |
> |
| 194 |
> # custom predicate to check registration of functions at loading |
| 195 |
> from mercurial import ( |
| 196 |
> smartset, |
| 197 |
> ) |
| 198 |
> @eh.revsetpredicate(bytesname, safe=True) # safe=True for query via hgweb |
| 199 |
> def custompredicate(repo, subset, x): |
| 200 |
> return smartset.baseset([r for r in subset if r in {0}]) |
| 201 |
> EOF |
| 202 |
|
| 203 |
$ cp foo.py bar.py |
| 204 |
$ echo 'foo = foo.py' >> $HGRCPATH |
| 205 |
$ echo 'bar = bar.py' >> $HGRCPATH |
| 206 |
|
| 207 |
Check normal command's load order of extensions and registration of functions |
| 208 |
|
| 209 |
On chg server, extension should be first set up by the server. Then |
| 210 |
object-level setup should follow in the worker process. |
| 211 |
|
| 212 |
$ hg log -r "foo() and bar()" -q |
| 213 |
1) foo imported |
| 214 |
1) bar imported |
| 215 |
2) foo uisetup |
| 216 |
2) bar uisetup |
| 217 |
3) foo extsetup |
| 218 |
3) bar extsetup |
| 219 |
4) foo uipopulate |
| 220 |
4) bar uipopulate |
| 221 |
4) foo uipopulate |
| 222 |
4) bar uipopulate |
| 223 |
4) foo uipopulate |
| 224 |
4) bar uipopulate |
| 225 |
5) foo reposetup |
| 226 |
5) bar reposetup |
| 227 |
4) foo uipopulate (chg !) |
| 228 |
4) bar uipopulate (chg !) |
| 229 |
4) foo uipopulate (chg !) |
| 230 |
4) bar uipopulate (chg !) |
| 231 |
4) foo uipopulate (chg !) |
| 232 |
4) bar uipopulate (chg !) |
| 233 |
4) foo uipopulate (chg !) |
| 234 |
4) bar uipopulate (chg !) |
| 235 |
4) foo uipopulate (chg !) |
| 236 |
4) bar uipopulate (chg !) |
| 237 |
5) foo reposetup (chg !) |
| 238 |
5) bar reposetup (chg !) |
| 239 |
0:c24b9ac61126 |
| 240 |
|
| 241 |
Check hgweb's load order of extensions and registration of functions |
| 242 |
|
| 243 |
$ cat > hgweb.cgi <<EOF |
| 244 |
> #!$PYTHON |
| 245 |
> from mercurial import demandimport; demandimport.enable() |
| 246 |
> from mercurial.hgweb import hgweb |
| 247 |
> from mercurial.hgweb import wsgicgi |
| 248 |
> application = hgweb(b'.', b'test repo') |
| 249 |
> wsgicgi.launch(application) |
| 250 |
> EOF |
| 251 |
$ . "$TESTDIR/cgienv" |
| 252 |
|
| 253 |
$ PATH_INFO='/' SCRIPT_NAME='' "$PYTHON" hgweb.cgi \ |
| 254 |
> | grep '^[0-9]) ' # ignores HTML output |
| 255 |
1) foo imported |
| 256 |
1) bar imported |
| 257 |
2) foo uisetup |
| 258 |
2) bar uisetup |
| 259 |
3) foo extsetup |
| 260 |
3) bar extsetup |
| 261 |
4) foo uipopulate |
| 262 |
4) bar uipopulate |
| 263 |
4) foo uipopulate |
| 264 |
4) bar uipopulate |
| 265 |
5) foo reposetup |
| 266 |
5) bar reposetup |
| 267 |
|
| 268 |
(check that revset predicate foo() and bar() are available) |
| 269 |
|
| 270 |
#if msys |
| 271 |
$ PATH_INFO='//shortlog' |
| 272 |
#else |
| 273 |
$ PATH_INFO='/shortlog' |
| 274 |
#endif |
| 275 |
$ export PATH_INFO |
| 276 |
$ SCRIPT_NAME='' QUERY_STRING='rev=foo() and bar()' "$PYTHON" hgweb.cgi \ |
| 277 |
> | grep '<a href="/rev/[0-9a-z]*">' |
| 278 |
<a href="/rev/c24b9ac61126">add file</a> |
| 279 |
|
| 280 |
$ echo 'foo = !' >> $HGRCPATH |
| 281 |
$ echo 'bar = !' >> $HGRCPATH |
| 282 |
|
| 283 |
Check "from __future__ import absolute_import" support for external libraries |
| 284 |
|
| 285 |
(import-checker.py reports issues for some of heredoc python code |
| 286 |
fragments below, because import-checker.py does not know test specific |
| 287 |
package hierarchy. NO_CHECK_* should be used as a limit mark of |
| 288 |
heredoc, in order to make import-checker.py ignore them. For |
| 289 |
simplicity, all python code fragments below are generated with such |
| 290 |
limit mark, regardless of importing module or not.) |
| 291 |
|
| 292 |
|
| 293 |
$ mkdir $TESTTMP/libroot |
| 294 |
$ echo "s = 'libroot/ambig.py'" > $TESTTMP/libroot/ambig.py |
| 295 |
$ mkdir $TESTTMP/libroot/mod |
| 296 |
$ touch $TESTTMP/libroot/mod/__init__.py |
| 297 |
$ echo "s = 'libroot/mod/ambig.py'" > $TESTTMP/libroot/mod/ambig.py |
| 298 |
|
| 299 |
$ cat > $TESTTMP/libroot/mod/ambigabs.py <<NO_CHECK_EOF |
| 300 |
> import ambig # should load "libroot/ambig.py" |
| 301 |
> s = ambig.s |
| 302 |
> NO_CHECK_EOF |
| 303 |
$ cat > loadabs.py <<NO_CHECK_EOF |
| 304 |
> import mod.ambigabs as ambigabs |
| 305 |
> def extsetup(ui): |
| 306 |
> print('ambigabs.s=%s' % ambigabs.s, flush=True) |
| 307 |
> NO_CHECK_EOF |
| 308 |
$ (PYTHONPATH=${PYTHONPATH_PREFIX}${TESTTMP}/libroot; hg --config extensions.loadabs=loadabs.py root) |
| 309 |
ambigabs.s=libroot/ambig.py |
| 310 |
$TESTTMP/a |
| 311 |
|
| 312 |
Check absolute/relative import of extension specific modules |
| 313 |
|
| 314 |
$ mkdir $TESTTMP/extroot |
| 315 |
$ cat > $TESTTMP/extroot/bar.py <<NO_CHECK_EOF |
| 316 |
> s = b'this is extroot.bar' |
| 317 |
> NO_CHECK_EOF |
| 318 |
$ mkdir $TESTTMP/extroot/sub1 |
| 319 |
$ cat > $TESTTMP/extroot/sub1/__init__.py <<NO_CHECK_EOF |
| 320 |
> s = b'this is extroot.sub1.__init__' |
| 321 |
> NO_CHECK_EOF |
| 322 |
$ cat > $TESTTMP/extroot/sub1/baz.py <<NO_CHECK_EOF |
| 323 |
> s = b'this is extroot.sub1.baz' |
| 324 |
> NO_CHECK_EOF |
| 325 |
$ cat > $TESTTMP/extroot/__init__.py <<NO_CHECK_EOF |
| 326 |
> s = b'this is extroot.__init__' |
| 327 |
> from . import foo |
| 328 |
> def extsetup(ui): |
| 329 |
> ui.write(b'(extroot) ', foo.func(), b'\n') |
| 330 |
> ui.flush() |
| 331 |
> NO_CHECK_EOF |
| 332 |
|
| 333 |
$ cat > $TESTTMP/extroot/foo.py <<NO_CHECK_EOF |
| 334 |
> # test absolute import |
| 335 |
> buf = [] |
| 336 |
> def func(): |
| 337 |
> # "not locals" case |
| 338 |
> import extroot.bar |
| 339 |
> buf.append(b'import extroot.bar in func(): %s' % extroot.bar.s) |
| 340 |
> return b'\n(extroot) '.join(buf) |
| 341 |
> # b"fromlist == ('*',)" case |
| 342 |
> from extroot.bar import * |
| 343 |
> buf.append(b'from extroot.bar import *: %s' % s) |
| 344 |
> # "not fromlist" and "if '.' in name" case |
| 345 |
> import extroot.sub1.baz |
| 346 |
> buf.append(b'import extroot.sub1.baz: %s' % extroot.sub1.baz.s) |
| 347 |
> # "not fromlist" and NOT "if '.' in name" case |
| 348 |
> import extroot |
| 349 |
> buf.append(b'import extroot: %s' % extroot.s) |
| 350 |
> # NOT "not fromlist" and NOT "level != -1" case |
| 351 |
> from extroot.bar import s |
| 352 |
> buf.append(b'from extroot.bar import s: %s' % s) |
| 353 |
> NO_CHECK_EOF |
| 354 |
$ (PYTHONPATH=${PYTHONPATH_PREFIX}${TESTTMP}; hg --config extensions.extroot=$TESTTMP/extroot root) |
| 355 |
(extroot) from extroot.bar import *: this is extroot.bar |
| 356 |
(extroot) import extroot.sub1.baz: this is extroot.sub1.baz |
| 357 |
(extroot) import extroot: this is extroot.__init__ |
| 358 |
(extroot) from extroot.bar import s: this is extroot.bar |
| 359 |
(extroot) import extroot.bar in func(): this is extroot.bar |
| 360 |
$TESTTMP/a |
| 361 |
|
| 362 |
#if demandimport |
| 363 |
|
| 364 |
Examine whether module loading is delayed until actual referring, even |
| 365 |
though module is imported with "absolute_import" feature. |
| 366 |
|
| 367 |
Files below in each packages are used for described purpose: |
| 368 |
|
| 369 |
- "called": examine whether "from MODULE import ATTR" works correctly |
| 370 |
- "unused": examine whether loading is delayed correctly |
| 371 |
- "used": examine whether "from PACKAGE import MODULE" works correctly |
| 372 |
|
| 373 |
Package hierarchy is needed to examine whether demand importing works |
| 374 |
as expected for "from SUB.PACK.AGE import MODULE". |
| 375 |
|
| 376 |
Setup "external library" to be imported with "absolute_import" |
| 377 |
feature. |
| 378 |
|
| 379 |
$ mkdir -p $TESTTMP/extlibroot/lsub1/lsub2 |
| 380 |
$ touch $TESTTMP/extlibroot/__init__.py |
| 381 |
$ touch $TESTTMP/extlibroot/lsub1/__init__.py |
| 382 |
$ touch $TESTTMP/extlibroot/lsub1/lsub2/__init__.py |
| 383 |
|
| 384 |
$ cat > $TESTTMP/extlibroot/lsub1/lsub2/called.py <<NO_CHECK_EOF |
| 385 |
> def func(): |
| 386 |
> return b"this is extlibroot.lsub1.lsub2.called.func()" |
| 387 |
> NO_CHECK_EOF |
| 388 |
$ cat > $TESTTMP/extlibroot/lsub1/lsub2/unused.py <<NO_CHECK_EOF |
| 389 |
> raise Exception("extlibroot.lsub1.lsub2.unused is loaded unintentionally") |
| 390 |
> NO_CHECK_EOF |
| 391 |
$ cat > $TESTTMP/extlibroot/lsub1/lsub2/used.py <<NO_CHECK_EOF |
| 392 |
> detail = b"this is extlibroot.lsub1.lsub2.used" |
| 393 |
> NO_CHECK_EOF |
| 394 |
|
| 395 |
Setup sub-package of "external library", which causes instantiation of |
| 396 |
demandmod in "recurse down the module chain" code path. Relative |
| 397 |
importing with "absolute_import" feature isn't tested, because "level |
| 398 |
>=1 " doesn't cause instantiation of demandmod. |
| 399 |
|
| 400 |
$ mkdir -p $TESTTMP/extlibroot/recursedown/abs |
| 401 |
$ cat > $TESTTMP/extlibroot/recursedown/abs/used.py <<NO_CHECK_EOF |
| 402 |
> detail = b"this is extlibroot.recursedown.abs.used" |
| 403 |
> NO_CHECK_EOF |
| 404 |
$ cat > $TESTTMP/extlibroot/recursedown/abs/__init__.py <<NO_CHECK_EOF |
| 405 |
> from extlibroot.recursedown.abs.used import detail |
| 406 |
> NO_CHECK_EOF |
| 407 |
|
| 408 |
$ mkdir -p $TESTTMP/extlibroot/recursedown/legacy |
| 409 |
$ cat > $TESTTMP/extlibroot/recursedown/legacy/used.py <<NO_CHECK_EOF |
| 410 |
> detail = b"this is extlibroot.recursedown.legacy.used" |
| 411 |
> NO_CHECK_EOF |
| 412 |
$ cat > $TESTTMP/extlibroot/recursedown/legacy/__init__.py <<NO_CHECK_EOF |
| 413 |
> # legacy style (level == -1) import |
| 414 |
> from extlibroot.recursedown.legacy.used import detail |
| 415 |
> NO_CHECK_EOF |
| 416 |
|
| 417 |
$ cat > $TESTTMP/extlibroot/recursedown/__init__.py <<NO_CHECK_EOF |
| 418 |
> from extlibroot.recursedown.abs import detail as absdetail |
| 419 |
> from .legacy import detail as legacydetail |
| 420 |
> NO_CHECK_EOF |
| 421 |
|
| 422 |
Setup package that re-exports an attribute of its submodule as the same |
| 423 |
name. This leaves 'shadowing.used' pointing to 'used.detail', but still |
| 424 |
the submodule 'used' should be somehow accessible. (issue5617) |
| 425 |
|
| 426 |
$ mkdir -p $TESTTMP/extlibroot/shadowing |
| 427 |
$ cat > $TESTTMP/extlibroot/shadowing/used.py <<NO_CHECK_EOF |
| 428 |
> detail = b"this is extlibroot.shadowing.used" |
| 429 |
> NO_CHECK_EOF |
| 430 |
$ cat > $TESTTMP/extlibroot/shadowing/proxied.py <<NO_CHECK_EOF |
| 431 |
> from extlibroot.shadowing.used import detail |
| 432 |
> NO_CHECK_EOF |
| 433 |
$ cat > $TESTTMP/extlibroot/shadowing/__init__.py <<NO_CHECK_EOF |
| 434 |
> from .used import detail as used |
| 435 |
> NO_CHECK_EOF |
| 436 |
|
| 437 |
Setup extension local modules to be imported with "absolute_import" |
| 438 |
feature. |
| 439 |
|
| 440 |
$ mkdir -p $TESTTMP/absextroot/xsub1/xsub2 |
| 441 |
$ touch $TESTTMP/absextroot/xsub1/__init__.py |
| 442 |
$ touch $TESTTMP/absextroot/xsub1/xsub2/__init__.py |
| 443 |
|
| 444 |
$ cat > $TESTTMP/absextroot/xsub1/xsub2/called.py <<NO_CHECK_EOF |
| 445 |
> def func(): |
| 446 |
> return b"this is absextroot.xsub1.xsub2.called.func()" |
| 447 |
> NO_CHECK_EOF |
| 448 |
$ cat > $TESTTMP/absextroot/xsub1/xsub2/unused.py <<NO_CHECK_EOF |
| 449 |
> raise Exception("absextroot.xsub1.xsub2.unused is loaded unintentionally") |
| 450 |
> NO_CHECK_EOF |
| 451 |
$ cat > $TESTTMP/absextroot/xsub1/xsub2/used.py <<NO_CHECK_EOF |
| 452 |
> detail = b"this is absextroot.xsub1.xsub2.used" |
| 453 |
> NO_CHECK_EOF |
| 454 |
|
| 455 |
Setup extension local modules to examine whether demand importing |
| 456 |
works as expected in "level > 1" case. |
| 457 |
|
| 458 |
$ cat > $TESTTMP/absextroot/relimportee.py <<NO_CHECK_EOF |
| 459 |
> detail = b"this is absextroot.relimportee" |
| 460 |
> NO_CHECK_EOF |
| 461 |
$ cat > $TESTTMP/absextroot/xsub1/xsub2/relimporter.py <<NO_CHECK_EOF |
| 462 |
> from mercurial import pycompat |
| 463 |
> from ... import relimportee |
| 464 |
> detail = b"this relimporter imports %r" % ( |
| 465 |
> pycompat.bytestr(relimportee.detail)) |
| 466 |
> NO_CHECK_EOF |
| 467 |
|
| 468 |
Setup modules, which actually import extension local modules at |
| 469 |
runtime. |
| 470 |
|
| 471 |
$ cat > $TESTTMP/absextroot/absolute.py << NO_CHECK_EOF |
| 472 |
> |
| 473 |
> # import extension local modules absolutely (level = 0) |
| 474 |
> from absextroot.xsub1.xsub2 import used, unused |
| 475 |
> from absextroot.xsub1.xsub2.called import func |
| 476 |
> |
| 477 |
> def getresult(): |
| 478 |
> result = [] |
| 479 |
> result.append(used.detail) |
| 480 |
> result.append(func()) |
| 481 |
> return result |
| 482 |
> NO_CHECK_EOF |
| 483 |
|
| 484 |
$ cat > $TESTTMP/absextroot/relative.py << NO_CHECK_EOF |
| 485 |
> |
| 486 |
> # import extension local modules relatively (level == 1) |
| 487 |
> from .xsub1.xsub2 import used, unused |
| 488 |
> from .xsub1.xsub2.called import func |
| 489 |
> |
| 490 |
> # import a module, which implies "importing with level > 1" |
| 491 |
> from .xsub1.xsub2 import relimporter |
| 492 |
> |
| 493 |
> def getresult(): |
| 494 |
> result = [] |
| 495 |
> result.append(used.detail) |
| 496 |
> result.append(func()) |
| 497 |
> result.append(relimporter.detail) |
| 498 |
> return result |
| 499 |
> NO_CHECK_EOF |
| 500 |
|
| 501 |
Setup main procedure of extension. |
| 502 |
|
| 503 |
$ cat > $TESTTMP/absextroot/__init__.py <<NO_CHECK_EOF |
| 504 |
> from mercurial import registrar |
| 505 |
> cmdtable = {} |
| 506 |
> command = registrar.command(cmdtable) |
| 507 |
> |
| 508 |
> # "absolute" and "relative" shouldn't be imported before actual |
| 509 |
> # command execution, because (1) they import same modules, and (2) |
| 510 |
> # preceding import (= instantiate "demandmod" object instead of |
| 511 |
> # real "module" object) might hide problem of succeeding import. |
| 512 |
> |
| 513 |
> @command(b'showabsolute', [], norepo=True) |
| 514 |
> def showabsolute(ui, *args, **opts): |
| 515 |
> from absextroot import absolute |
| 516 |
> ui.write(b'ABS: %s\n' % b'\nABS: '.join(absolute.getresult())) |
| 517 |
> |
| 518 |
> @command(b'showrelative', [], norepo=True) |
| 519 |
> def showrelative(ui, *args, **opts): |
| 520 |
> from . import relative |
| 521 |
> ui.write(b'REL: %s\n' % b'\nREL: '.join(relative.getresult())) |
| 522 |
> |
| 523 |
> # import modules from external library |
| 524 |
> from extlibroot.lsub1.lsub2 import used as lused, unused as lunused |
| 525 |
> from extlibroot.lsub1.lsub2.called import func as lfunc |
| 526 |
> from extlibroot.recursedown import absdetail, legacydetail |
| 527 |
> from extlibroot.shadowing import proxied |
| 528 |
> |
| 529 |
> def uisetup(ui): |
| 530 |
> result = [] |
| 531 |
> result.append(lused.detail) |
| 532 |
> result.append(lfunc()) |
| 533 |
> result.append(absdetail) |
| 534 |
> result.append(legacydetail) |
| 535 |
> result.append(proxied.detail) |
| 536 |
> ui.write(b'LIB: %s\n' % b'\nLIB: '.join(result)) |
| 537 |
> NO_CHECK_EOF |
| 538 |
|
| 539 |
Examine module importing. |
| 540 |
|
| 541 |
$ (PYTHONPATH=${PYTHONPATH_PREFIX}${TESTTMP}; hg --config extensions.absextroot=$TESTTMP/absextroot showabsolute) |
| 542 |
LIB: this is extlibroot.lsub1.lsub2.used |
| 543 |
LIB: this is extlibroot.lsub1.lsub2.called.func() |
| 544 |
LIB: this is extlibroot.recursedown.abs.used |
| 545 |
LIB: this is extlibroot.recursedown.legacy.used |
| 546 |
LIB: this is extlibroot.shadowing.used |
| 547 |
ABS: this is absextroot.xsub1.xsub2.used |
| 548 |
ABS: this is absextroot.xsub1.xsub2.called.func() |
| 549 |
|
| 550 |
$ (PYTHONPATH=${PYTHONPATH_PREFIX}${TESTTMP}; hg --config extensions.absextroot=$TESTTMP/absextroot showrelative) |
| 551 |
LIB: this is extlibroot.lsub1.lsub2.used |
| 552 |
LIB: this is extlibroot.lsub1.lsub2.called.func() |
| 553 |
LIB: this is extlibroot.recursedown.abs.used |
| 554 |
LIB: this is extlibroot.recursedown.legacy.used |
| 555 |
LIB: this is extlibroot.shadowing.used |
| 556 |
REL: this is absextroot.xsub1.xsub2.used |
| 557 |
REL: this is absextroot.xsub1.xsub2.called.func() |
| 558 |
REL: this relimporter imports 'this is absextroot.relimportee' |
| 559 |
|
| 560 |
Examine whether sub-module is imported relatively as expected. |
| 561 |
|
| 562 |
See also issue5208 for detail about example case on Python 3.x. |
| 563 |
|
| 564 |
$ f -q $TESTTMP/extlibroot/lsub1/lsub2/notexist.py |
| 565 |
$TESTTMP/extlibroot/lsub1/lsub2/notexist.py: file not found |
| 566 |
|
| 567 |
$ cat > $TESTTMP/notexist.py <<NO_CHECK_EOF |
| 568 |
> text = 'notexist.py at root is loaded unintentionally\n' |
| 569 |
> NO_CHECK_EOF |
| 570 |
|
| 571 |
$ cat > $TESTTMP/checkrelativity.py <<NO_CHECK_EOF |
| 572 |
> from mercurial import registrar |
| 573 |
> cmdtable = {} |
| 574 |
> command = registrar.command(cmdtable) |
| 575 |
> |
| 576 |
> # demand import avoids failure of importing notexist here, but only on |
| 577 |
> # Python 2. |
| 578 |
> import extlibroot.lsub1.lsub2.notexist |
| 579 |
> |
| 580 |
> @command(b'checkrelativity', [], norepo=True) |
| 581 |
> def checkrelativity(ui, *args, **opts): |
| 582 |
> try: |
| 583 |
> ui.write(extlibroot.lsub1.lsub2.notexist.text) |
| 584 |
> return 1 # unintentional success |
| 585 |
> except ImportError: |
| 586 |
> pass # intentional failure |
| 587 |
> NO_CHECK_EOF |
| 588 |
|
| 589 |
Python 3's lazy importer verifies modules exist before returning the lazy |
| 590 |
module stub. Our custom lazy importer for Python 2 always returns a stub. |
| 591 |
|
| 592 |
$ (PYTHONPATH=${PYTHONPATH_PREFIX}${TESTTMP}; hg --config extensions.checkrelativity=$TESTTMP/checkrelativity.py checkrelativity) || true |
| 593 |
*** failed to import extension "checkrelativity" from $TESTTMP/checkrelativity.py: No module named 'extlibroot.lsub1.lsub2.notexist' |
| 594 |
hg: unknown command 'checkrelativity' |
| 595 |
(use 'hg help' for a list of commands) |
| 596 |
|
| 597 |
#endif |
| 598 |
|
| 599 |
(Here, module importing tests are finished. Therefore, use other than |
| 600 |
NO_CHECK_* limit mark for heredoc python files, in order to apply |
| 601 |
import-checker.py or so on their contents) |
| 602 |
|
| 603 |
Make sure a broken uisetup doesn't globally break hg: |
| 604 |
$ cat > $TESTTMP/baduisetup.py <<EOF |
| 605 |
> def uisetup(ui): |
| 606 |
> 1 / 0 |
| 607 |
> EOF |
| 608 |
|
| 609 |
Even though the extension fails during uisetup, hg is still basically usable: |
| 610 |
$ hg --config extensions.baduisetup=$TESTTMP/baduisetup.py version |
| 611 |
Traceback (most recent call last): |
| 612 |
File "*/mercurial/extensions.py", line *, in _runuisetup (glob) (no-pyoxidizer !) |
| 613 |
File "mercurial.extensions", line *, in _runuisetup (glob) (pyoxidizer !) |
| 614 |
uisetup(ui) |
| 615 |
~~~~~~~^^^^ (py313 !) |
| 616 |
File "$TESTTMP/baduisetup.py", line 2, in uisetup |
| 617 |
1 / 0 |
| 618 |
~~^~~ (py311 !) |
| 619 |
ZeroDivisionError: * by zero (glob) |
| 620 |
*** failed to set up extension baduisetup: * by zero (glob) |
| 621 |
Mercurial Distributed SCM (version *) (glob) |
| 622 |
(see https://mercurial-scm.org for more information) |
| 623 |
|
| 624 |
Copyright (C) 2005-* Olivia Mackall and others (glob) |
| 625 |
This is free software; see the source for copying conditions. There is NO |
| 626 |
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 627 |
|
| 628 |
$ cd .. |
| 629 |
|
| 630 |
hide outer repo |
| 631 |
$ hg init |
| 632 |
|
| 633 |
$ cat > empty.py <<EOF |
| 634 |
> '''empty cmdtable |
| 635 |
> ''' |
| 636 |
> cmdtable = {} |
| 637 |
> EOF |
| 638 |
$ emptypath=`pwd`/empty.py |
| 639 |
$ echo "empty = $emptypath" >> $HGRCPATH |
| 640 |
$ hg help empty |
| 641 |
empty extension - empty cmdtable |
| 642 |
|
| 643 |
no commands defined |
| 644 |
|
| 645 |
|
| 646 |
$ echo 'empty = !' >> $HGRCPATH |
| 647 |
|
| 648 |
$ cat > debugextension.py <<EOF |
| 649 |
> '''only debugcommands |
| 650 |
> ''' |
| 651 |
> from mercurial import registrar |
| 652 |
> cmdtable = {} |
| 653 |
> command = registrar.command(cmdtable) |
| 654 |
> @command(b'debugfoobar', [], b'hg debugfoobar') |
| 655 |
> def debugfoobar(ui, repo, *args, **opts): |
| 656 |
> "yet another debug command" |
| 657 |
> @command(b'foo', [], b'hg foo') |
| 658 |
> def foo(ui, repo, *args, **opts): |
| 659 |
> """yet another foo command |
| 660 |
> This command has been DEPRECATED since forever. |
| 661 |
> """ |
| 662 |
> EOF |
| 663 |
$ debugpath=`pwd`/debugextension.py |
| 664 |
$ echo "debugextension = $debugpath" >> $HGRCPATH |
| 665 |
|
| 666 |
$ hg help debugextension |
| 667 |
hg debugextensions |
| 668 |
|
| 669 |
show information about active extensions |
| 670 |
|
| 671 |
options: |
| 672 |
|
| 673 |
-T --template TEMPLATE display with template |
| 674 |
|
| 675 |
(some details hidden, use --verbose to show complete help) |
| 676 |
|
| 677 |
|
| 678 |
$ hg --verbose help debugextension |
| 679 |
hg debugextensions |
| 680 |
|
| 681 |
show information about active extensions |
| 682 |
|
| 683 |
options: |
| 684 |
|
| 685 |
-T --template TEMPLATE display with template |
| 686 |
|
| 687 |
global options ([+] can be repeated): |
| 688 |
|
| 689 |
-R --repository REPO repository root directory or name of overlay bundle |
| 690 |
file |
| 691 |
--cwd DIR change working directory |
| 692 |
-y --noninteractive do not prompt, automatically pick the first choice |
| 693 |
for all prompts |
| 694 |
-q --quiet suppress output |
| 695 |
-v --verbose enable additional output |
| 696 |
--color TYPE when to colorize (boolean, always, auto, never, or |
| 697 |
debug) |
| 698 |
--config CONFIG [+] set/override config option (use |
| 699 |
'section.name=value') |
| 700 |
--config-file HGRC [+] load config file to set/override config options |
| 701 |
--debug enable debugging output |
| 702 |
--debugger start debugger |
| 703 |
--encoding ENCODE set the charset encoding (default: ascii) |
| 704 |
--encodingmode MODE set the charset encoding mode (default: strict) |
| 705 |
--traceback always print a traceback on exception |
| 706 |
--time time how long the command takes |
| 707 |
--profile print command execution profile |
| 708 |
--version output version information and exit |
| 709 |
-h --help display help and exit |
| 710 |
--hidden consider hidden changesets |
| 711 |
--pager TYPE when to paginate (boolean, always, auto, or never) |
| 712 |
(default: auto) |
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
$ hg --debug help debugextension |
| 720 |
hg debugextensions |
| 721 |
|
| 722 |
show information about active extensions |
| 723 |
|
| 724 |
options: |
| 725 |
|
| 726 |
-T --template TEMPLATE display with template |
| 727 |
|
| 728 |
global options ([+] can be repeated): |
| 729 |
|
| 730 |
-R --repository REPO repository root directory or name of overlay bundle |
| 731 |
file |
| 732 |
--cwd DIR change working directory |
| 733 |
-y --noninteractive do not prompt, automatically pick the first choice |
| 734 |
for all prompts |
| 735 |
-q --quiet suppress output |
| 736 |
-v --verbose enable additional output |
| 737 |
--color TYPE when to colorize (boolean, always, auto, never, or |
| 738 |
debug) |
| 739 |
--config CONFIG [+] set/override config option (use |
| 740 |
'section.name=value') |
| 741 |
--config-file HGRC [+] load config file to set/override config options |
| 742 |
--debug enable debugging output |
| 743 |
--debugger start debugger |
| 744 |
--encoding ENCODE set the charset encoding (default: ascii) |
| 745 |
--encodingmode MODE set the charset encoding mode (default: strict) |
| 746 |
--traceback always print a traceback on exception |
| 747 |
--time time how long the command takes |
| 748 |
--profile print command execution profile |
| 749 |
--version output version information and exit |
| 750 |
-h --help display help and exit |
| 751 |
--hidden consider hidden changesets |
| 752 |
--pager TYPE when to paginate (boolean, always, auto, or never) |
| 753 |
(default: auto) |
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
$ echo 'debugextension = !' >> $HGRCPATH |
| 760 |
|
| 761 |
Asking for help about a deprecated extension should do something useful: |
| 762 |
|
| 763 |
$ hg help glog |
| 764 |
'glog' is provided by the following extension: |
| 765 |
|
| 766 |
graphlog command to view revision graphs from a shell (DEPRECATED) |
| 767 |
|
| 768 |
(use 'hg help extensions' for information on enabling extensions) |
| 769 |
|
| 770 |
Extension module help vs command help: |
| 771 |
|
| 772 |
$ echo 'extdiff =' >> $HGRCPATH |
| 773 |
$ hg help extdiff |
| 774 |
hg extdiff [OPT]... [FILE]... |
| 775 |
|
| 776 |
use external program to diff repository (or selected files) |
| 777 |
|
| 778 |
Show differences between revisions for the specified files, using an external |
| 779 |
program. The default program used is diff, with default options "-Npru". |
| 780 |
|
| 781 |
To select a different program, use the -p/--program option. The program will |
| 782 |
be passed the names of two directories to compare, unless the --per-file |
| 783 |
option is specified (see below). To pass additional options to the program, |
| 784 |
use -o/--option. These will be passed before the names of the directories or |
| 785 |
files to compare. |
| 786 |
|
| 787 |
The --from, --to, and --change options work the same way they do for 'hg |
| 788 |
diff'. |
| 789 |
|
| 790 |
The --per-file option runs the external program repeatedly on each file to |
| 791 |
diff, instead of once on two directories. By default, this happens one by one, |
| 792 |
where the next file diff is open in the external program only once the |
| 793 |
previous external program (for the previous file diff) has exited. If the |
| 794 |
external program has a graphical interface, it can open all the file diffs at |
| 795 |
once instead of one by one. See 'hg help -e extdiff' for information about how |
| 796 |
to tell Mercurial that a given program has a graphical interface. |
| 797 |
|
| 798 |
The --confirm option will prompt the user before each invocation of the |
| 799 |
external program. It is ignored if --per-file isn't specified. |
| 800 |
|
| 801 |
(use 'hg help -e extdiff' to show help for the extdiff extension) |
| 802 |
|
| 803 |
options ([+] can be repeated): |
| 804 |
|
| 805 |
-p --program CMD comparison program to run |
| 806 |
-o --option OPT [+] pass option to comparison program |
| 807 |
--from REV1 revision to diff from |
| 808 |
--to REV2 revision to diff to |
| 809 |
-c --change REV change made by revision |
| 810 |
--per-file compare each file instead of revision snapshots |
| 811 |
--confirm prompt user before each external program invocation |
| 812 |
--patch compare patches for two revisions |
| 813 |
-I --include PATTERN [+] include names matching the given patterns |
| 814 |
-X --exclude PATTERN [+] exclude names matching the given patterns |
| 815 |
-S --subrepos recurse into subrepositories |
| 816 |
|
| 817 |
(some details hidden, use --verbose to show complete help) |
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
$ hg help --extension extdiff |
| 829 |
extdiff extension - command to allow external programs to compare revisions |
| 830 |
|
| 831 |
The extdiff Mercurial extension allows you to use external programs to compare |
| 832 |
revisions, or revision with working directory. The external diff programs are |
| 833 |
called with a configurable set of options and two non-option arguments: paths |
| 834 |
to directories containing snapshots of files to compare. |
| 835 |
|
| 836 |
If there is more than one file being compared and the "child" revision is the |
| 837 |
working directory, any modifications made in the external diff program will be |
| 838 |
copied back to the working directory from the temporary directory. |
| 839 |
|
| 840 |
The extdiff extension also allows you to configure new diff commands, so you |
| 841 |
do not need to type 'hg extdiff -p kdiff3' always. |
| 842 |
|
| 843 |
[extdiff] |
| 844 |
# add new command that runs GNU diff(1) in 'context diff' mode |
| 845 |
cdiff = gdiff -Nprc5 |
| 846 |
## or the old way: |
| 847 |
#cmd.cdiff = gdiff |
| 848 |
#opts.cdiff = -Nprc5 |
| 849 |
|
| 850 |
# add new command called meld, runs meld (no need to name twice). If |
| 851 |
# the meld executable is not available, the meld tool in [merge-tools] |
| 852 |
# will be used, if available |
| 853 |
meld = |
| 854 |
|
| 855 |
# add new command called vimdiff, runs gvimdiff with DirDiff plugin |
| 856 |
# (see http://www.vim.org/scripts/script.php?script_id=102) Non |
| 857 |
# English user, be sure to put "let g:DirDiffDynamicDiffText = 1" in |
| 858 |
# your .vimrc |
| 859 |
vimdiff = gvim -f "+next" \ |
| 860 |
"+execute 'DirDiff' fnameescape(argv(0)) fnameescape(argv(1))" |
| 861 |
|
| 862 |
Tool arguments can include variables that are expanded at runtime: |
| 863 |
|
| 864 |
$parent1, $plabel1 - filename, descriptive label of first parent |
| 865 |
$child, $clabel - filename, descriptive label of child revision |
| 866 |
$parent2, $plabel2 - filename, descriptive label of second parent |
| 867 |
$root - repository root |
| 868 |
$parent is an alias for $parent1. |
| 869 |
|
| 870 |
The extdiff extension will look in your [diff-tools] and [merge-tools] |
| 871 |
sections for diff tool arguments, when none are specified in [extdiff]. |
| 872 |
|
| 873 |
[extdiff] |
| 874 |
kdiff3 = |
| 875 |
|
| 876 |
[diff-tools] |
| 877 |
kdiff3.diffargs=--L1 '$plabel1' --L2 '$clabel' $parent $child |
| 878 |
|
| 879 |
If a program has a graphical interface, it might be interesting to tell |
| 880 |
Mercurial about it. It will prevent the program from being mistakenly used in |
| 881 |
a terminal-only environment (such as an SSH terminal session), and will make |
| 882 |
'hg extdiff --per-file' open multiple file diffs at once instead of one by one |
| 883 |
(if you still want to open file diffs one by one, you can use the --confirm |
| 884 |
option). |
| 885 |
|
| 886 |
Declaring that a tool has a graphical interface can be done with the "gui" |
| 887 |
flag next to where "diffargs" are specified: |
| 888 |
|
| 889 |
[diff-tools] |
| 890 |
kdiff3.diffargs=--L1 '$plabel1' --L2 '$clabel' $parent $child |
| 891 |
kdiff3.gui = true |
| 892 |
|
| 893 |
You can use -I/-X and list of file or directory names like normal 'hg diff' |
| 894 |
command. The extdiff extension makes snapshots of only needed files, so |
| 895 |
running the external diff program will actually be pretty fast (at least |
| 896 |
faster than having to compare the entire tree). |
| 897 |
|
| 898 |
list of commands: |
| 899 |
|
| 900 |
extdiff use external program to diff repository (or selected files) |
| 901 |
|
| 902 |
(use 'hg help -v -e extdiff' to show built-in aliases and global options) |
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
$ echo 'extdiff = !' >> $HGRCPATH |
| 920 |
|
| 921 |
Test help topic with same name as extension |
| 922 |
|
| 923 |
$ cat > multirevs.py <<EOF |
| 924 |
> from mercurial import commands, registrar |
| 925 |
> cmdtable = {} |
| 926 |
> command = registrar.command(cmdtable) |
| 927 |
> """multirevs extension |
| 928 |
> Big multi-line module docstring.""" |
| 929 |
> @command(b'multirevs', [], b'ARG', norepo=True) |
| 930 |
> def multirevs(ui, repo, arg, *args, **opts): |
| 931 |
> """multirevs command""" |
| 932 |
> EOF |
| 933 |
$ echo "multirevs = multirevs.py" >> $HGRCPATH |
| 934 |
|
| 935 |
$ hg help multirevs | tail |
| 936 |
used): |
| 937 |
|
| 938 |
hg update :@ |
| 939 |
|
| 940 |
- Show diff between tags 1.3 and 1.5 (this works because the first and the |
| 941 |
last revisions of the revset are used): |
| 942 |
|
| 943 |
hg diff -r 1.3::1.5 |
| 944 |
|
| 945 |
use 'hg help -c multirevs' to see help for the multirevs command |
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
$ hg help -c multirevs |
| 953 |
hg multirevs ARG |
| 954 |
|
| 955 |
multirevs command |
| 956 |
|
| 957 |
(some details hidden, use --verbose to show complete help) |
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
$ hg multirevs |
| 962 |
hg multirevs: invalid arguments |
| 963 |
hg multirevs ARG |
| 964 |
|
| 965 |
multirevs command |
| 966 |
|
| 967 |
(use 'hg multirevs -h' to show more help) |
| 968 |
[10] |
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
$ echo "multirevs = !" >> $HGRCPATH |
| 973 |
|
| 974 |
Issue811: Problem loading extensions twice (by site and by user) |
| 975 |
|
| 976 |
$ cat <<EOF >> $HGRCPATH |
| 977 |
> mq = |
| 978 |
> strip = |
| 979 |
> hgext.mq = |
| 980 |
> hgext/mq = |
| 981 |
> EOF |
| 982 |
|
| 983 |
Show extensions: |
| 984 |
(note that mq force load strip, also checking it's not loaded twice) |
| 985 |
|
| 986 |
#if no-extraextensions |
| 987 |
$ hg debugextensions |
| 988 |
mq |
| 989 |
strip |
| 990 |
#endif |
| 991 |
|
| 992 |
For extensions, which name matches one of its commands, help |
| 993 |
message should ask '-v -e' to get list of built-in aliases |
| 994 |
along with extension help itself |
| 995 |
|
| 996 |
$ mkdir $TESTTMP/d |
| 997 |
$ cat > $TESTTMP/d/dodo.py <<EOF |
| 998 |
> """ |
| 999 |
> This is an awesome 'dodo' extension. It does nothing and |
| 1000 |
> writes 'Foo foo' |
| 1001 |
> """ |
| 1002 |
> from mercurial import commands, registrar |
| 1003 |
> cmdtable = {} |
| 1004 |
> command = registrar.command(cmdtable) |
| 1005 |
> @command(b'dodo', [], b'hg dodo') |
| 1006 |
> def dodo(ui, *args, **kwargs): |
| 1007 |
> """Does nothing""" |
| 1008 |
> ui.write(b"I do nothing. Yay\\n") |
| 1009 |
> @command(b'foofoo', [], b'hg foofoo') |
| 1010 |
> def foofoo(ui, *args, **kwargs): |
| 1011 |
> """Writes 'Foo foo'""" |
| 1012 |
> ui.write(b"Foo foo\\n") |
| 1013 |
> EOF |
| 1014 |
$ dodopath=$TESTTMP/d/dodo.py |
| 1015 |
|
| 1016 |
$ echo "dodo = $dodopath" >> $HGRCPATH |
| 1017 |
|
| 1018 |
Make sure that user is asked to enter '-v -e' to get list of built-in aliases |
| 1019 |
$ hg help -e dodo |
| 1020 |
dodo extension - |
| 1021 |
|
| 1022 |
This is an awesome 'dodo' extension. It does nothing and writes 'Foo foo' |
| 1023 |
|
| 1024 |
list of commands: |
| 1025 |
|
| 1026 |
dodo Does nothing |
| 1027 |
foofoo Writes 'Foo foo' |
| 1028 |
|
| 1029 |
(use 'hg help -v -e dodo' to show built-in aliases and global options) |
| 1030 |
|
| 1031 |
Make sure that '-v -e' prints list of built-in aliases along with |
| 1032 |
extension help itself |
| 1033 |
$ hg help -v -e dodo |
| 1034 |
dodo extension - |
| 1035 |
|
| 1036 |
This is an awesome 'dodo' extension. It does nothing and writes 'Foo foo' |
| 1037 |
|
| 1038 |
list of commands: |
| 1039 |
|
| 1040 |
dodo Does nothing |
| 1041 |
foofoo Writes 'Foo foo' |
| 1042 |
|
| 1043 |
global options ([+] can be repeated): |
| 1044 |
|
| 1045 |
-R --repository REPO repository root directory or name of overlay bundle |
| 1046 |
file |
| 1047 |
--cwd DIR change working directory |
| 1048 |
-y --noninteractive do not prompt, automatically pick the first choice |
| 1049 |
for all prompts |
| 1050 |
-q --quiet suppress output |
| 1051 |
-v --verbose enable additional output |
| 1052 |
--color TYPE when to colorize (boolean, always, auto, never, or |
| 1053 |
debug) |
| 1054 |
--config CONFIG [+] set/override config option (use |
| 1055 |
'section.name=value') |
| 1056 |
--config-file HGRC [+] load config file to set/override config options |
| 1057 |
--debug enable debugging output |
| 1058 |
--debugger start debugger |
| 1059 |
--encoding ENCODE set the charset encoding (default: ascii) |
| 1060 |
--encodingmode MODE set the charset encoding mode (default: strict) |
| 1061 |
--traceback always print a traceback on exception |
| 1062 |
--time time how long the command takes |
| 1063 |
--profile print command execution profile |
| 1064 |
--version output version information and exit |
| 1065 |
-h --help display help and exit |
| 1066 |
--hidden consider hidden changesets |
| 1067 |
--pager TYPE when to paginate (boolean, always, auto, or never) |
| 1068 |
(default: auto) |
| 1069 |
|
| 1070 |
Make sure that single '-v' option shows help and built-ins only for 'dodo' command |
| 1071 |
$ hg help -v dodo |
| 1072 |
hg dodo |
| 1073 |
|
| 1074 |
Does nothing |
| 1075 |
|
| 1076 |
(use 'hg help -e dodo' to show help for the dodo extension) |
| 1077 |
|
| 1078 |
options: |
| 1079 |
|
| 1080 |
--mq operate on patch repository |
| 1081 |
|
| 1082 |
global options ([+] can be repeated): |
| 1083 |
|
| 1084 |
-R --repository REPO repository root directory or name of overlay bundle |
| 1085 |
file |
| 1086 |
--cwd DIR change working directory |
| 1087 |
-y --noninteractive do not prompt, automatically pick the first choice |
| 1088 |
for all prompts |
| 1089 |
-q --quiet suppress output |
| 1090 |
-v --verbose enable additional output |
| 1091 |
--color TYPE when to colorize (boolean, always, auto, never, or |
| 1092 |
debug) |
| 1093 |
--config CONFIG [+] set/override config option (use |
| 1094 |
'section.name=value') |
| 1095 |
--config-file HGRC [+] load config file to set/override config options |
| 1096 |
--debug enable debugging output |
| 1097 |
--debugger start debugger |
| 1098 |
--encoding ENCODE set the charset encoding (default: ascii) |
| 1099 |
--encodingmode MODE set the charset encoding mode (default: strict) |
| 1100 |
--traceback always print a traceback on exception |
| 1101 |
--time time how long the command takes |
| 1102 |
--profile print command execution profile |
| 1103 |
--version output version information and exit |
| 1104 |
-h --help display help and exit |
| 1105 |
--hidden consider hidden changesets |
| 1106 |
--pager TYPE when to paginate (boolean, always, auto, or never) |
| 1107 |
(default: auto) |
| 1108 |
|
| 1109 |
In case when extension name doesn't match any of its commands, |
| 1110 |
help message should ask for '-v' to get list of built-in aliases |
| 1111 |
along with extension help |
| 1112 |
$ cat > $TESTTMP/d/dudu.py <<EOF |
| 1113 |
> """ |
| 1114 |
> This is an awesome 'dudu' extension. It does something and |
| 1115 |
> also writes 'Beep beep' |
| 1116 |
> """ |
| 1117 |
> from mercurial import commands, registrar |
| 1118 |
> cmdtable = {} |
| 1119 |
> command = registrar.command(cmdtable) |
| 1120 |
> @command(b'something', [], b'hg something') |
| 1121 |
> def something(ui, *args, **kwargs): |
| 1122 |
> """Does something""" |
| 1123 |
> ui.write(b"I do something. Yaaay\\n") |
| 1124 |
> @command(b'beep', [], b'hg beep') |
| 1125 |
> def beep(ui, *args, **kwargs): |
| 1126 |
> """Writes 'Beep beep'""" |
| 1127 |
> ui.write(b"Beep beep\\n") |
| 1128 |
> EOF |
| 1129 |
$ dudupath=$TESTTMP/d/dudu.py |
| 1130 |
|
| 1131 |
$ echo "dudu = $dudupath" >> $HGRCPATH |
| 1132 |
|
| 1133 |
$ hg help -e dudu |
| 1134 |
dudu extension - |
| 1135 |
|
| 1136 |
This is an awesome 'dudu' extension. It does something and also writes 'Beep |
| 1137 |
beep' |
| 1138 |
|
| 1139 |
list of commands: |
| 1140 |
|
| 1141 |
beep Writes 'Beep beep' |
| 1142 |
something Does something |
| 1143 |
|
| 1144 |
(use 'hg help -v dudu' to show built-in aliases and global options) |
| 1145 |
|
| 1146 |
In case when extension name doesn't match any of its commands, |
| 1147 |
help options '-v' and '-v -e' should be equivalent |
| 1148 |
$ hg help -v dudu |
| 1149 |
dudu extension - |
| 1150 |
|
| 1151 |
This is an awesome 'dudu' extension. It does something and also writes 'Beep |
| 1152 |
beep' |
| 1153 |
|
| 1154 |
list of commands: |
| 1155 |
|
| 1156 |
beep Writes 'Beep beep' |
| 1157 |
something Does something |
| 1158 |
|
| 1159 |
global options ([+] can be repeated): |
| 1160 |
|
| 1161 |
-R --repository REPO repository root directory or name of overlay bundle |
| 1162 |
file |
| 1163 |
--cwd DIR change working directory |
| 1164 |
-y --noninteractive do not prompt, automatically pick the first choice |
| 1165 |
for all prompts |
| 1166 |
-q --quiet suppress output |
| 1167 |
-v --verbose enable additional output |
| 1168 |
--color TYPE when to colorize (boolean, always, auto, never, or |
| 1169 |
debug) |
| 1170 |
--config CONFIG [+] set/override config option (use |
| 1171 |
'section.name=value') |
| 1172 |
--config-file HGRC [+] load config file to set/override config options |
| 1173 |
--debug enable debugging output |
| 1174 |
--debugger start debugger |
| 1175 |
--encoding ENCODE set the charset encoding (default: ascii) |
| 1176 |
--encodingmode MODE set the charset encoding mode (default: strict) |
| 1177 |
--traceback always print a traceback on exception |
| 1178 |
--time time how long the command takes |
| 1179 |
--profile print command execution profile |
| 1180 |
--version output version information and exit |
| 1181 |
-h --help display help and exit |
| 1182 |
--hidden consider hidden changesets |
| 1183 |
--pager TYPE when to paginate (boolean, always, auto, or never) |
| 1184 |
(default: auto) |
| 1185 |
|
| 1186 |
$ hg help -v -e dudu |
| 1187 |
dudu extension - |
| 1188 |
|
| 1189 |
This is an awesome 'dudu' extension. It does something and also writes 'Beep |
| 1190 |
beep' |
| 1191 |
|
| 1192 |
list of commands: |
| 1193 |
|
| 1194 |
beep Writes 'Beep beep' |
| 1195 |
something Does something |
| 1196 |
|
| 1197 |
global options ([+] can be repeated): |
| 1198 |
|
| 1199 |
-R --repository REPO repository root directory or name of overlay bundle |
| 1200 |
file |
| 1201 |
--cwd DIR change working directory |
| 1202 |
-y --noninteractive do not prompt, automatically pick the first choice |
| 1203 |
for all prompts |
| 1204 |
-q --quiet suppress output |
| 1205 |
-v --verbose enable additional output |
| 1206 |
--color TYPE when to colorize (boolean, always, auto, never, or |
| 1207 |
debug) |
| 1208 |
--config CONFIG [+] set/override config option (use |
| 1209 |
'section.name=value') |
| 1210 |
--config-file HGRC [+] load config file to set/override config options |
| 1211 |
--debug enable debugging output |
| 1212 |
--debugger start debugger |
| 1213 |
--encoding ENCODE set the charset encoding (default: ascii) |
| 1214 |
--encodingmode MODE set the charset encoding mode (default: strict) |
| 1215 |
--traceback always print a traceback on exception |
| 1216 |
--time time how long the command takes |
| 1217 |
--profile print command execution profile |
| 1218 |
--version output version information and exit |
| 1219 |
-h --help display help and exit |
| 1220 |
--hidden consider hidden changesets |
| 1221 |
--pager TYPE when to paginate (boolean, always, auto, or never) |
| 1222 |
(default: auto) |
| 1223 |
|
| 1224 |
Disabled extension commands: |
| 1225 |
|
| 1226 |
$ ORGHGRCPATH=$HGRCPATH |
| 1227 |
$ HGRCPATH= |
| 1228 |
$ export HGRCPATH |
| 1229 |
$ hg help email |
| 1230 |
'email' is provided by the following extension: |
| 1231 |
|
| 1232 |
patchbomb command to send changesets as (a series of) patch emails |
| 1233 |
|
| 1234 |
(use 'hg help extensions' for information on enabling extensions) |
| 1235 |
|
| 1236 |
|
| 1237 |
$ hg qdel |
| 1238 |
hg: unknown command 'qdel' |
| 1239 |
'qdelete' is provided by the following extension: |
| 1240 |
|
| 1241 |
mq manage a stack of patches |
| 1242 |
|
| 1243 |
(use 'hg help extensions' for information on enabling extensions) |
| 1244 |
[255] |
| 1245 |
|
| 1246 |
|
| 1247 |
$ hg churn |
| 1248 |
hg: unknown command 'churn' |
| 1249 |
'churn' is provided by the following extension: |
| 1250 |
|
| 1251 |
churn command to display statistics about repository history |
| 1252 |
|
| 1253 |
(use 'hg help extensions' for information on enabling extensions) |
| 1254 |
[255] |
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
Disabled extensions: |
| 1259 |
|
| 1260 |
$ hg help churn |
| 1261 |
churn extension - command to display statistics about repository history |
| 1262 |
|
| 1263 |
(use 'hg help extensions' for information on enabling extensions) |
| 1264 |
|
| 1265 |
$ hg help patchbomb |
| 1266 |
patchbomb extension - command to send changesets as (a series of) patch emails |
| 1267 |
|
| 1268 |
The series is started off with a "[PATCH 0 of N]" introduction, which |
| 1269 |
describes the series as a whole. |
| 1270 |
|
| 1271 |
Each patch email has a Subject line of "[PATCH M of N] ...", using the first |
| 1272 |
line of the changeset description as the subject text. The message contains |
| 1273 |
two or three body parts: |
| 1274 |
|
| 1275 |
- The changeset description. |
| 1276 |
- [Optional] The result of running diffstat on the patch. |
| 1277 |
- The patch itself, as generated by 'hg export'. |
| 1278 |
|
| 1279 |
Each message refers to the first in the series using the In-Reply-To and |
| 1280 |
References headers, so they will show up as a sequence in threaded mail and |
| 1281 |
news readers, and in mail archives. |
| 1282 |
|
| 1283 |
To configure other defaults, add a section like this to your configuration |
| 1284 |
file: |
| 1285 |
|
| 1286 |
[email] |
| 1287 |
from = My Name <my@email> |
| 1288 |
to = recipient1, recipient2, ... |
| 1289 |
cc = cc1, cc2, ... |
| 1290 |
bcc = bcc1, bcc2, ... |
| 1291 |
reply-to = address1, address2, ... |
| 1292 |
|
| 1293 |
Use "[patchbomb]" as configuration section name if you need to override global |
| 1294 |
"[email]" address settings. |
| 1295 |
|
| 1296 |
Then you can use the 'hg email' command to mail a series of changesets as a |
| 1297 |
patchbomb. |
| 1298 |
|
| 1299 |
You can also either configure the method option in the email section to be a |
| 1300 |
sendmail compatible mailer or fill out the [smtp] section so that the |
| 1301 |
patchbomb extension can automatically send patchbombs directly from the |
| 1302 |
commandline. See the [email] and [smtp] sections in hgrc(5) for details. |
| 1303 |
|
| 1304 |
By default, 'hg email' will prompt for a "To" or "CC" header if you do not |
| 1305 |
supply one via configuration or the command line. You can override this to |
| 1306 |
never prompt by configuring an empty value: |
| 1307 |
|
| 1308 |
[email] |
| 1309 |
cc = |
| 1310 |
|
| 1311 |
You can control the default inclusion of an introduction message with the |
| 1312 |
"patchbomb.intro" configuration option. The configuration is always |
| 1313 |
overwritten by command line flags like --intro and --desc: |
| 1314 |
|
| 1315 |
[patchbomb] |
| 1316 |
intro=auto # include introduction message if more than 1 patch (default) |
| 1317 |
intro=never # never include an introduction message |
| 1318 |
intro=always # always include an introduction message |
| 1319 |
|
| 1320 |
You can specify a template for flags to be added in subject prefixes. Flags |
| 1321 |
specified by --flag option are exported as "{flags}" keyword: |
| 1322 |
|
| 1323 |
[patchbomb] |
| 1324 |
flagtemplate = "{separate(' ', |
| 1325 |
ifeq(branch, 'default', '', branch|upper), |
| 1326 |
flags)}" |
| 1327 |
|
| 1328 |
You can set patchbomb to always ask for confirmation by setting |
| 1329 |
"patchbomb.confirm" to true. |
| 1330 |
|
| 1331 |
(use 'hg help extensions' for information on enabling extensions) |
| 1332 |
|
| 1333 |
|
| 1334 |
Help can find unimported extensions |
| 1335 |
----------------------------------- |
| 1336 |
|
| 1337 |
XXX-PYOXIDIZER since the frozen binary does not have source directory tree, |
| 1338 |
this make the checking for actual file under `hgext` a bit complicated. In |
| 1339 |
addition these tests do some strange dance to ensure some other module are the |
| 1340 |
first in `sys.path` (since the current install path is always in front |
| 1341 |
otherwise) that are fragile and that does not match reality in the field. So |
| 1342 |
for now we disable this test untill a deeper rework of that logic is done. |
| 1343 |
|
| 1344 |
#if no-pyoxidizer |
| 1345 |
|
| 1346 |
Broken disabled extension and command: |
| 1347 |
|
| 1348 |
$ mkdir hgext |
| 1349 |
$ echo > hgext/__init__.py |
| 1350 |
$ cat > hgext/broken.py <<NO_CHECK_EOF |
| 1351 |
> "broken extension' |
| 1352 |
> NO_CHECK_EOF |
| 1353 |
$ cat > path.py <<EOF |
| 1354 |
> import os |
| 1355 |
> import sys |
| 1356 |
> sys.path.insert(0, os.environ['HGEXTPATH']) |
| 1357 |
> EOF |
| 1358 |
$ HGEXTPATH=`pwd` |
| 1359 |
$ export HGEXTPATH |
| 1360 |
|
| 1361 |
$ hg --config extensions.path=./path.py help broken |
| 1362 |
broken extension - (no help text available) |
| 1363 |
|
| 1364 |
(use 'hg help extensions' for information on enabling extensions) |
| 1365 |
|
| 1366 |
|
| 1367 |
$ cat > hgext/forest.py <<EOF |
| 1368 |
> cmdtable = None |
| 1369 |
> @command() |
| 1370 |
> def f(): |
| 1371 |
> pass |
| 1372 |
> @command(123) |
| 1373 |
> def g(): |
| 1374 |
> pass |
| 1375 |
> EOF |
| 1376 |
$ hg --config extensions.path=./path.py help foo |
| 1377 |
abort: no such help topic: foo |
| 1378 |
(try 'hg help --keyword foo') |
| 1379 |
[255] |
| 1380 |
|
| 1381 |
#endif |
| 1382 |
|
| 1383 |
--- |
| 1384 |
|
| 1385 |
$ cat > throw.py <<EOF |
| 1386 |
> from mercurial import commands, registrar, util |
| 1387 |
> cmdtable = {} |
| 1388 |
> command = registrar.command(cmdtable) |
| 1389 |
> class Bogon(Exception): pass |
| 1390 |
> # NB: version should be bytes; simulating extension not ported to py3 |
| 1391 |
> __version__ = '1.0.0' |
| 1392 |
> @command(b'throw', [], b'hg throw', norepo=True) |
| 1393 |
> def throw(ui, **opts): |
| 1394 |
> """throws an exception""" |
| 1395 |
> raise Bogon() |
| 1396 |
> EOF |
| 1397 |
|
| 1398 |
Test extension without proper byteification of key attributes doesn't crash when |
| 1399 |
accessed. |
| 1400 |
|
| 1401 |
$ hg version -v --config extensions.throw=throw.py | grep '^ ' |
| 1402 |
throw external 1.0.0 |
| 1403 |
|
| 1404 |
No declared supported version, extension complains: |
| 1405 |
$ hg --config extensions.throw=throw.py throw 2>&1 | grep -E '^\*\*' |
| 1406 |
** Unknown exception encountered with possibly-broken third-party extension "throw" 1.0.0 |
| 1407 |
** which supports versions unknown of Mercurial. |
| 1408 |
** Please disable "throw" and try your action again. |
| 1409 |
** If that fixes the bug please report it to the extension author. |
| 1410 |
** Python * (glob) |
| 1411 |
** Mercurial Distributed SCM * (glob) |
| 1412 |
** Extensions loaded: throw 1.0.0 |
| 1413 |
|
| 1414 |
empty declaration of supported version, extension complains (but doesn't choke if |
| 1415 |
the value is improperly a str instead of bytes): |
| 1416 |
$ echo "testedwith = ''" >> throw.py |
| 1417 |
$ hg --config extensions.throw=throw.py throw 2>&1 | grep -E '^\*\*' |
| 1418 |
** Unknown exception encountered with possibly-broken third-party extension "throw" 1.0.0 |
| 1419 |
** which supports versions unknown of Mercurial. |
| 1420 |
** Please disable "throw" and try your action again. |
| 1421 |
** If that fixes the bug please report it to the extension author. |
| 1422 |
** Python * (glob) |
| 1423 |
** Mercurial Distributed SCM (*) (glob) |
| 1424 |
** Extensions loaded: throw 1.0.0 |
| 1425 |
|
| 1426 |
If the extension specifies a buglink, show that (but don't choke if the value is |
| 1427 |
improperly a str instead of bytes): |
| 1428 |
$ echo 'buglink = "http://example.com/bts"' >> throw.py |
| 1429 |
$ rm -f throw.pyc throw.pyo |
| 1430 |
$ rm -Rf __pycache__ |
| 1431 |
$ hg --config extensions.throw=throw.py throw 2>&1 | grep -E '^\*\*' |
| 1432 |
** Unknown exception encountered with possibly-broken third-party extension "throw" 1.0.0 |
| 1433 |
** which supports versions unknown of Mercurial. |
| 1434 |
** Please disable "throw" and try your action again. |
| 1435 |
** If that fixes the bug please report it to http://example.com/bts |
| 1436 |
** Python * (glob) |
| 1437 |
** Mercurial Distributed SCM (*) (glob) |
| 1438 |
** Extensions loaded: throw 1.0.0 |
| 1439 |
|
| 1440 |
If the extensions declare outdated versions, accuse the older extension first: |
| 1441 |
$ echo "from mercurial import util" >> older.py |
| 1442 |
$ echo "util.version = lambda:b'2.2'" >> older.py |
| 1443 |
$ echo "testedwith = b'1.9.3'" >> older.py |
| 1444 |
$ echo "testedwith = b'2.1.1'" >> throw.py |
| 1445 |
$ rm -f throw.pyc throw.pyo |
| 1446 |
$ rm -Rf __pycache__ |
| 1447 |
$ hg --config extensions.throw=throw.py --config extensions.older=older.py \ |
| 1448 |
> throw 2>&1 | grep -E '^\*\*' |
| 1449 |
** Unknown exception encountered with possibly-broken third-party extension "older" (version N/A) |
| 1450 |
** which supports versions 1.9 of Mercurial. |
| 1451 |
** Please disable "older" and try your action again. |
| 1452 |
** If that fixes the bug please report it to the extension author. |
| 1453 |
** Python * (glob) |
| 1454 |
** Mercurial Distributed SCM (version 2.2) |
| 1455 |
** Extensions loaded: older, throw 1.0.0 |
| 1456 |
|
| 1457 |
One extension only tested with older, one only with newer versions: |
| 1458 |
$ echo "util.version = lambda:b'2.1'" >> older.py |
| 1459 |
$ rm -f older.pyc older.pyo |
| 1460 |
$ rm -Rf __pycache__ |
| 1461 |
$ hg --config extensions.throw=throw.py --config extensions.older=older.py \ |
| 1462 |
> throw 2>&1 | grep -E '^\*\*' |
| 1463 |
** Unknown exception encountered with possibly-broken third-party extension "older" (version N/A) |
| 1464 |
** which supports versions 1.9 of Mercurial. |
| 1465 |
** Please disable "older" and try your action again. |
| 1466 |
** If that fixes the bug please report it to the extension author. |
| 1467 |
** Python * (glob) |
| 1468 |
** Mercurial Distributed SCM (version 2.1) |
| 1469 |
** Extensions loaded: older, throw 1.0.0 |
| 1470 |
|
| 1471 |
Older extension is tested with current version, the other only with newer: |
| 1472 |
$ echo "util.version = lambda:b'1.9.3'" >> older.py |
| 1473 |
$ rm -f older.pyc older.pyo |
| 1474 |
$ rm -Rf __pycache__ |
| 1475 |
$ hg --config extensions.throw=throw.py --config extensions.older=older.py \ |
| 1476 |
> throw 2>&1 | grep -E '^\*\*' |
| 1477 |
** Unknown exception encountered with possibly-broken third-party extension "throw" 1.0.0 |
| 1478 |
** which supports versions 2.1 of Mercurial. |
| 1479 |
** Please disable "throw" and try your action again. |
| 1480 |
** If that fixes the bug please report it to http://example.com/bts |
| 1481 |
** Python * (glob) |
| 1482 |
** Mercurial Distributed SCM (version 1.9.3) |
| 1483 |
** Extensions loaded: older, throw 1.0.0 |
| 1484 |
|
| 1485 |
Ability to point to a different point |
| 1486 |
$ hg --config extensions.throw=throw.py --config extensions.older=older.py \ |
| 1487 |
> --config ui.supportcontact='Your Local Goat Lenders' throw 2>&1 | grep -E '^\*\*' |
| 1488 |
** unknown exception encountered, please report by visiting |
| 1489 |
** Your Local Goat Lenders |
| 1490 |
** Python * (glob) |
| 1491 |
** Mercurial Distributed SCM (*) (glob) |
| 1492 |
** Extensions loaded: older, throw 1.0.0 |
| 1493 |
|
| 1494 |
Declare the version as supporting this hg version, show regular bts link: |
| 1495 |
$ hgver=`hg debuginstall -T '{hgver}'` |
| 1496 |
$ echo 'testedwith = """'"$hgver"'"""' >> throw.py |
| 1497 |
$ if [ -z "$hgver" ]; then |
| 1498 |
> echo "unable to fetch a mercurial version. Make sure __version__ is correct"; |
| 1499 |
> fi |
| 1500 |
$ rm -f throw.pyc throw.pyo |
| 1501 |
$ rm -Rf __pycache__ |
| 1502 |
$ hg --config extensions.throw=throw.py throw 2>&1 | grep -E '^\*\*' |
| 1503 |
** unknown exception encountered, please report by visiting |
| 1504 |
** https://foss.heptapod.net/mercurial/mercurial-devel/-/issues |
| 1505 |
** Python * (glob) |
| 1506 |
** Mercurial Distributed SCM (*) (glob) |
| 1507 |
** Extensions loaded: throw 1.0.0 |
| 1508 |
|
| 1509 |
Patch version is ignored during compatibility check |
| 1510 |
$ echo "testedwith = b'3.2'" >> throw.py |
| 1511 |
$ echo "util.version = lambda:b'3.2.2'" >> throw.py |
| 1512 |
$ rm -f throw.pyc throw.pyo |
| 1513 |
$ rm -Rf __pycache__ |
| 1514 |
$ hg --config extensions.throw=throw.py throw 2>&1 | grep -E '^\*\*' |
| 1515 |
** unknown exception encountered, please report by visiting |
| 1516 |
** https://foss.heptapod.net/mercurial/mercurial-devel/-/issues |
| 1517 |
** Python * (glob) |
| 1518 |
** Mercurial Distributed SCM (*) (glob) |
| 1519 |
** Extensions loaded: throw 1.0.0 |
| 1520 |
|
| 1521 |
Test version number support in 'hg version': |
| 1522 |
$ echo '__version__ = (1, 2, 3)' >> throw.py |
| 1523 |
$ rm -f throw.pyc throw.pyo |
| 1524 |
$ rm -Rf __pycache__ |
| 1525 |
$ hg version -v |
| 1526 |
Mercurial Distributed SCM (version *) (glob) |
| 1527 |
(see https://mercurial-scm.org for more information) |
| 1528 |
|
| 1529 |
Copyright (C) 2005-* Olivia Mackall and others (glob) |
| 1530 |
This is free software; see the source for copying conditions. There is NO |
| 1531 |
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 1532 |
|
| 1533 |
Enabled extensions: |
| 1534 |
|
| 1535 |
|
| 1536 |
$ hg version -v --config extensions.throw=throw.py |
| 1537 |
Mercurial Distributed SCM (version *) (glob) |
| 1538 |
(see https://mercurial-scm.org for more information) |
| 1539 |
|
| 1540 |
Copyright (C) 2005-* Olivia Mackall and others (glob) |
| 1541 |
This is free software; see the source for copying conditions. There is NO |
| 1542 |
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 1543 |
|
| 1544 |
Enabled extensions: |
| 1545 |
|
| 1546 |
throw external 1.2.3 |
| 1547 |
$ echo 'getversion = lambda: b"1.twentythree"' >> throw.py |
| 1548 |
$ rm -f throw.pyc throw.pyo |
| 1549 |
$ rm -Rf __pycache__ |
| 1550 |
$ hg version -v --config extensions.throw=throw.py --config extensions.strip= |
| 1551 |
Mercurial Distributed SCM (version *) (glob) |
| 1552 |
(see https://mercurial-scm.org for more information) |
| 1553 |
|
| 1554 |
Copyright (C) 2005-* Olivia Mackall and others (glob) |
| 1555 |
This is free software; see the source for copying conditions. There is NO |
| 1556 |
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 1557 |
|
| 1558 |
Enabled extensions: |
| 1559 |
|
| 1560 |
strip internal |
| 1561 |
throw external 1.twentythree |
| 1562 |
|
| 1563 |
$ hg version -q --config extensions.throw=throw.py |
| 1564 |
Mercurial Distributed SCM (version *) (glob) |
| 1565 |
|
| 1566 |
Test template output: |
| 1567 |
|
| 1568 |
$ hg version --config extensions.strip= -T'{extensions}' |
| 1569 |
strip |
| 1570 |
|
| 1571 |
Test JSON output of version: |
| 1572 |
|
| 1573 |
$ hg version -Tjson |
| 1574 |
[ |
| 1575 |
{ |
| 1576 |
"extensions": [], |
| 1577 |
"ver": "*" (glob) |
| 1578 |
} |
| 1579 |
] |
| 1580 |
|
| 1581 |
$ hg version --config extensions.throw=throw.py -Tjson |
| 1582 |
[ |
| 1583 |
{ |
| 1584 |
"extensions": [{"bundled": false, "name": "throw", "ver": "1.twentythree"}], |
| 1585 |
"ver": "3.2.2" |
| 1586 |
} |
| 1587 |
] |
| 1588 |
|
| 1589 |
$ hg version --config extensions.strip= -Tjson |
| 1590 |
[ |
| 1591 |
{ |
| 1592 |
"extensions": [{"bundled": true, "name": "strip", "ver": null}], |
| 1593 |
"ver": "*" (glob) |
| 1594 |
} |
| 1595 |
] |
| 1596 |
|
| 1597 |
Test template output of version: |
| 1598 |
|
| 1599 |
$ hg version --config extensions.throw=throw.py --config extensions.strip= \ |
| 1600 |
> -T'{extensions % "{name} {pad(ver, 16)} ({if(bundled, "internal", "external")})\n"}' |
| 1601 |
strip (internal) |
| 1602 |
throw 1.twentythree (external) |
| 1603 |
|
| 1604 |
Refuse to load extensions with minimum version requirements |
| 1605 |
|
| 1606 |
$ cat > minversion1.py << EOF |
| 1607 |
> from mercurial import util |
| 1608 |
> util.version = lambda: b'3.5.2' |
| 1609 |
> minimumhgversion = b'3.6' |
| 1610 |
> EOF |
| 1611 |
$ hg --config extensions.minversion=minversion1.py version |
| 1612 |
(third party extension minversion requires version 3.6 or newer of Mercurial (current: 3.5.2); disabling) |
| 1613 |
Mercurial Distributed SCM (version 3.5.2) |
| 1614 |
(see https://mercurial-scm.org for more information) |
| 1615 |
|
| 1616 |
Copyright (C) 2005-* Olivia Mackall and others (glob) |
| 1617 |
This is free software; see the source for copying conditions. There is NO |
| 1618 |
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 1619 |
|
| 1620 |
$ cat > minversion2.py << EOF |
| 1621 |
> from mercurial import util |
| 1622 |
> util.version = lambda: b'3.6' |
| 1623 |
> minimumhgversion = b'3.7' |
| 1624 |
> EOF |
| 1625 |
$ hg --config extensions.minversion=minversion2.py version 2>&1 | grep -E '\(third' |
| 1626 |
(third party extension minversion requires version 3.7 or newer of Mercurial (current: 3.6); disabling) |
| 1627 |
|
| 1628 |
Can load version that is only off by point release |
| 1629 |
|
| 1630 |
$ cat > minversion2.py << EOF |
| 1631 |
> from mercurial import util |
| 1632 |
> util.version = lambda: b'3.6.1' |
| 1633 |
> minimumhgversion = b'3.6' |
| 1634 |
> EOF |
| 1635 |
$ hg --config extensions.minversion=minversion3.py version 2>&1 | grep -E '\(third' |
| 1636 |
[1] |
| 1637 |
|
| 1638 |
Can load minimum version identical to current |
| 1639 |
|
| 1640 |
$ cat > minversion3.py << EOF |
| 1641 |
> from mercurial import util |
| 1642 |
> util.version = lambda: b'3.5' |
| 1643 |
> minimumhgversion = b'3.5' |
| 1644 |
> EOF |
| 1645 |
$ hg --config extensions.minversion=minversion3.py version 2>&1 | grep -E '\(third' |
| 1646 |
[1] |
| 1647 |
|
| 1648 |
Don't explode on py3 with a bad version number (both str vs bytes, and not enough |
| 1649 |
parts) |
| 1650 |
|
| 1651 |
$ cat > minversion4.py << EOF |
| 1652 |
> from mercurial import util |
| 1653 |
> util.version = lambda: b'3.5' |
| 1654 |
> minimumhgversion = '3' |
| 1655 |
> EOF |
| 1656 |
$ hg --config extensions.minversion=minversion4.py version -v |
| 1657 |
Mercurial Distributed SCM (version 3.5) |
| 1658 |
(see https://mercurial-scm.org for more information) |
| 1659 |
|
| 1660 |
Copyright (C) 2005-* Olivia Mackall and others (glob) |
| 1661 |
This is free software; see the source for copying conditions. There is NO |
| 1662 |
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 1663 |
|
| 1664 |
Enabled extensions: |
| 1665 |
|
| 1666 |
minversion external |
| 1667 |
|
| 1668 |
Restore HGRCPATH |
| 1669 |
|
| 1670 |
$ HGRCPATH=$ORGHGRCPATH |
| 1671 |
$ export HGRCPATH |
| 1672 |
|
| 1673 |
Commands handling multiple repositories at a time should invoke only |
| 1674 |
"reposetup()" of extensions enabling in the target repository. |
| 1675 |
|
| 1676 |
$ mkdir reposetup-test |
| 1677 |
$ cd reposetup-test |
| 1678 |
|
| 1679 |
$ cat > $TESTTMP/reposetuptest.py <<EOF |
| 1680 |
> from mercurial import extensions |
| 1681 |
> def reposetup(ui, repo): |
| 1682 |
> ui.write(b'reposetup() for %s\n' % (repo.root)) |
| 1683 |
> ui.flush() |
| 1684 |
> EOF |
| 1685 |
$ hg init src |
| 1686 |
$ echo a > src/a |
| 1687 |
$ hg -R src commit -Am '#0 at src/a' |
| 1688 |
adding a |
| 1689 |
$ echo '[extensions]' >> src/.hg/hgrc |
| 1690 |
$ echo '# enable extension locally' >> src/.hg/hgrc |
| 1691 |
$ echo "reposetuptest = $TESTTMP/reposetuptest.py" >> src/.hg/hgrc |
| 1692 |
$ hg -R src status |
| 1693 |
reposetup() for $TESTTMP/reposetup-test/src |
| 1694 |
reposetup() for $TESTTMP/reposetup-test/src (chg !) |
| 1695 |
|
| 1696 |
#if no-extraextensions |
| 1697 |
$ hg --cwd src debugextensions |
| 1698 |
reposetup() for $TESTTMP/reposetup-test/src |
| 1699 |
dodo (untested!) |
| 1700 |
dudu (untested!) |
| 1701 |
mq |
| 1702 |
reposetuptest (untested!) |
| 1703 |
strip |
| 1704 |
#endif |
| 1705 |
|
| 1706 |
$ hg clone -U src clone-dst1 |
| 1707 |
reposetup() for $TESTTMP/reposetup-test/src |
| 1708 |
$ hg init push-dst1 |
| 1709 |
$ hg -q -R src push push-dst1 |
| 1710 |
reposetup() for $TESTTMP/reposetup-test/src |
| 1711 |
$ hg init pull-src1 |
| 1712 |
$ hg -q -R pull-src1 pull src |
| 1713 |
reposetup() for $TESTTMP/reposetup-test/src |
| 1714 |
|
| 1715 |
$ cat <<EOF >> $HGRCPATH |
| 1716 |
> [extensions] |
| 1717 |
> # disable extension globally and explicitly |
| 1718 |
> reposetuptest = ! |
| 1719 |
> EOF |
| 1720 |
$ hg clone -U src clone-dst2 |
| 1721 |
reposetup() for $TESTTMP/reposetup-test/src |
| 1722 |
$ hg init push-dst2 |
| 1723 |
$ hg -q -R src push push-dst2 |
| 1724 |
reposetup() for $TESTTMP/reposetup-test/src |
| 1725 |
$ hg init pull-src2 |
| 1726 |
$ hg -q -R pull-src2 pull src |
| 1727 |
reposetup() for $TESTTMP/reposetup-test/src |
| 1728 |
|
| 1729 |
$ cat <<EOF >> $HGRCPATH |
| 1730 |
> [extensions] |
| 1731 |
> # enable extension globally |
| 1732 |
> reposetuptest = $TESTTMP/reposetuptest.py |
| 1733 |
> EOF |
| 1734 |
$ hg clone -U src clone-dst3 |
| 1735 |
reposetup() for $TESTTMP/reposetup-test/src |
| 1736 |
reposetup() for $TESTTMP/reposetup-test/clone-dst3 |
| 1737 |
$ hg init push-dst3 |
| 1738 |
reposetup() for $TESTTMP/reposetup-test/push-dst3 |
| 1739 |
$ hg -q -R src push push-dst3 |
| 1740 |
reposetup() for $TESTTMP/reposetup-test/src |
| 1741 |
reposetup() for $TESTTMP/reposetup-test/push-dst3 |
| 1742 |
$ hg init pull-src3 |
| 1743 |
reposetup() for $TESTTMP/reposetup-test/pull-src3 |
| 1744 |
$ hg -q -R pull-src3 pull src |
| 1745 |
reposetup() for $TESTTMP/reposetup-test/pull-src3 |
| 1746 |
reposetup() for $TESTTMP/reposetup-test/src |
| 1747 |
|
| 1748 |
$ echo '[extensions]' >> src/.hg/hgrc |
| 1749 |
$ echo '# disable extension locally' >> src/.hg/hgrc |
| 1750 |
$ echo 'reposetuptest = !' >> src/.hg/hgrc |
| 1751 |
$ hg clone -U src clone-dst4 |
| 1752 |
reposetup() for $TESTTMP/reposetup-test/clone-dst4 |
| 1753 |
$ hg init push-dst4 |
| 1754 |
reposetup() for $TESTTMP/reposetup-test/push-dst4 |
| 1755 |
$ hg -q -R src push push-dst4 |
| 1756 |
reposetup() for $TESTTMP/reposetup-test/push-dst4 |
| 1757 |
$ hg init pull-src4 |
| 1758 |
reposetup() for $TESTTMP/reposetup-test/pull-src4 |
| 1759 |
$ hg -q -R pull-src4 pull src |
| 1760 |
reposetup() for $TESTTMP/reposetup-test/pull-src4 |
| 1761 |
|
| 1762 |
disabling in command line overlays with all configuration |
| 1763 |
$ hg --config extensions.reposetuptest=! clone -U src clone-dst5 |
| 1764 |
$ hg --config extensions.reposetuptest=! init push-dst5 |
| 1765 |
$ hg --config extensions.reposetuptest=! -q -R src push push-dst5 |
| 1766 |
$ hg --config extensions.reposetuptest=! init pull-src5 |
| 1767 |
$ hg --config extensions.reposetuptest=! -q -R pull-src5 pull src |
| 1768 |
|
| 1769 |
$ cat <<EOF >> $HGRCPATH |
| 1770 |
> [extensions] |
| 1771 |
> # disable extension globally and explicitly |
| 1772 |
> reposetuptest = ! |
| 1773 |
> EOF |
| 1774 |
$ hg init parent |
| 1775 |
$ hg init parent/sub1 |
| 1776 |
$ echo 1 > parent/sub1/1 |
| 1777 |
$ hg -R parent/sub1 commit -Am '#0 at parent/sub1' |
| 1778 |
adding 1 |
| 1779 |
$ hg init parent/sub2 |
| 1780 |
$ hg init parent/sub2/sub21 |
| 1781 |
$ echo 21 > parent/sub2/sub21/21 |
| 1782 |
$ hg -R parent/sub2/sub21 commit -Am '#0 at parent/sub2/sub21' |
| 1783 |
adding 21 |
| 1784 |
$ cat > parent/sub2/.hgsub <<EOF |
| 1785 |
> sub21 = sub21 |
| 1786 |
> EOF |
| 1787 |
$ hg -R parent/sub2 commit -Am '#0 at parent/sub2' |
| 1788 |
adding .hgsub |
| 1789 |
$ hg init parent/sub3 |
| 1790 |
$ echo 3 > parent/sub3/3 |
| 1791 |
$ hg -R parent/sub3 commit -Am '#0 at parent/sub3' |
| 1792 |
adding 3 |
| 1793 |
$ cat > parent/.hgsub <<EOF |
| 1794 |
> sub1 = sub1 |
| 1795 |
> sub2 = sub2 |
| 1796 |
> sub3 = sub3 |
| 1797 |
> EOF |
| 1798 |
$ hg -R parent commit -Am '#0 at parent' |
| 1799 |
adding .hgsub |
| 1800 |
$ echo '[extensions]' >> parent/.hg/hgrc |
| 1801 |
$ echo '# enable extension locally' >> parent/.hg/hgrc |
| 1802 |
$ echo "reposetuptest = $TESTTMP/reposetuptest.py" >> parent/.hg/hgrc |
| 1803 |
$ cp parent/.hg/hgrc parent/sub2/.hg/hgrc |
| 1804 |
$ hg -R parent status -S -A |
| 1805 |
reposetup() for $TESTTMP/reposetup-test/parent |
| 1806 |
reposetup() for $TESTTMP/reposetup-test/parent/sub2 |
| 1807 |
C .hgsub |
| 1808 |
C .hgsubstate |
| 1809 |
C sub1/1 |
| 1810 |
C sub2/.hgsub |
| 1811 |
C sub2/.hgsubstate |
| 1812 |
C sub2/sub21/21 |
| 1813 |
C sub3/3 |
| 1814 |
|
| 1815 |
$ cd .. |
| 1816 |
|
| 1817 |
Prohibit registration of commands that don't use @command (issue5137) |
| 1818 |
|
| 1819 |
$ hg init deprecated |
| 1820 |
$ cd deprecated |
| 1821 |
|
| 1822 |
$ cat <<EOF > deprecatedcmd.py |
| 1823 |
> def deprecatedcmd(repo, ui): |
| 1824 |
> pass |
| 1825 |
> cmdtable = { |
| 1826 |
> b'deprecatedcmd': (deprecatedcmd, [], b''), |
| 1827 |
> } |
| 1828 |
> EOF |
| 1829 |
$ cat <<EOF > .hg/hgrc |
| 1830 |
> [extensions] |
| 1831 |
> deprecatedcmd = `pwd`/deprecatedcmd.py |
| 1832 |
> mq = ! |
| 1833 |
> hgext.mq = ! |
| 1834 |
> hgext/mq = ! |
| 1835 |
> EOF |
| 1836 |
|
| 1837 |
$ hg deprecatedcmd > /dev/null |
| 1838 |
*** failed to import extension "deprecatedcmd" from $TESTTMP/deprecated/deprecatedcmd.py: missing attributes: norepo, optionalrepo, inferrepo |
| 1839 |
*** (use @command decorator to register 'deprecatedcmd') |
| 1840 |
hg: unknown command 'deprecatedcmd' |
| 1841 |
(use 'hg help' for a list of commands) |
| 1842 |
[10] |
| 1843 |
|
| 1844 |
the extension shouldn't be loaded at all so the mq works: |
| 1845 |
|
| 1846 |
$ hg qseries --config extensions.mq= > /dev/null |
| 1847 |
*** failed to import extension "deprecatedcmd" from $TESTTMP/deprecated/deprecatedcmd.py: missing attributes: norepo, optionalrepo, inferrepo |
| 1848 |
*** (use @command decorator to register 'deprecatedcmd') |
| 1849 |
|
| 1850 |
$ cd .. |
| 1851 |
|
| 1852 |
Test synopsis and docstring extending |
| 1853 |
|
| 1854 |
$ hg init exthelp |
| 1855 |
$ cat > exthelp.py <<EOF |
| 1856 |
> from mercurial import commands, extensions |
| 1857 |
> def exbookmarks(orig, *args, **opts): |
| 1858 |
> return orig(*args, **opts) |
| 1859 |
> def uisetup(ui): |
| 1860 |
> synopsis = b' GREPME [--foo] [-x]' |
| 1861 |
> docstring = '\nGREPME make sure that this is in the help!' |
| 1862 |
> extensions.wrapcommand(commands.table, b'bookmarks', exbookmarks, |
| 1863 |
> synopsis, docstring) |
| 1864 |
> EOF |
| 1865 |
$ abspath=`pwd`/exthelp.py |
| 1866 |
$ echo '[extensions]' >> $HGRCPATH |
| 1867 |
$ echo "exthelp = $abspath" >> $HGRCPATH |
| 1868 |
$ cd exthelp |
| 1869 |
$ hg help bookmarks | grep GREPME |
| 1870 |
hg bookmarks [OPTIONS]... [NAME]... GREPME [--foo] [-x] |
| 1871 |
GREPME make sure that this is in the help! |
| 1872 |
$ cd .. |
| 1873 |
|
| 1874 |
Prohibit the use of unicode strings as the default value of options |
| 1875 |
|
| 1876 |
$ hg init $TESTTMP/opt-unicode-default |
| 1877 |
|
| 1878 |
$ cat > $TESTTMP/test_unicode_default_value.py << EOF |
| 1879 |
> from mercurial import registrar |
| 1880 |
> cmdtable = {} |
| 1881 |
> command = registrar.command(cmdtable) |
| 1882 |
> @command(b'dummy', [(b'', b'opt', u'value', u'help')], 'ext [OPTIONS]') |
| 1883 |
> def ext(*args, **opts): |
| 1884 |
> print(opts[b'opt'], flush=True) |
| 1885 |
> EOF |
| 1886 |
$ cat > $TESTTMP/opt-unicode-default/.hg/hgrc << EOF |
| 1887 |
> [extensions] |
| 1888 |
> test_unicode_default_value = $TESTTMP/test_unicode_default_value.py |
| 1889 |
> EOF |
| 1890 |
$ hg -R $TESTTMP/opt-unicode-default dummy |
| 1891 |
*** failed to import extension "test_unicode_default_value" from $TESTTMP/test_unicode_default_value.py: unicode 'value' found in cmdtable.dummy |
| 1892 |
*** (use b'' to make it byte string) |
| 1893 |
hg: unknown command 'dummy' |
| 1894 |
(did you mean summary?) |
| 1895 |
[10] |
| 1896 |
|
| 1897 |
Check the mandatory extension feature |
| 1898 |
------------------------------------- |
| 1899 |
|
| 1900 |
$ hg init mandatory-extensions |
| 1901 |
$ cat > $TESTTMP/mandatory-extensions/.hg/good.py << EOF |
| 1902 |
> pass |
| 1903 |
> EOF |
| 1904 |
$ cat > $TESTTMP/mandatory-extensions/.hg/bad.py << EOF |
| 1905 |
> raise RuntimeError("babar") |
| 1906 |
> EOF |
| 1907 |
$ cat > $TESTTMP/mandatory-extensions/.hg/syntax.py << EOF |
| 1908 |
> def ( |
| 1909 |
> EOF |
| 1910 |
|
| 1911 |
Check that the good one load : |
| 1912 |
|
| 1913 |
$ cat > $TESTTMP/mandatory-extensions/.hg/hgrc << EOF |
| 1914 |
> [extensions] |
| 1915 |
> good = $TESTTMP/mandatory-extensions/.hg/good.py |
| 1916 |
> EOF |
| 1917 |
|
| 1918 |
$ hg -R mandatory-extensions id |
| 1919 |
000000000000 tip |
| 1920 |
|
| 1921 |
Make it mandatory to load |
| 1922 |
|
| 1923 |
$ cat >> $TESTTMP/mandatory-extensions/.hg/hgrc << EOF |
| 1924 |
> good:required = yes |
| 1925 |
> EOF |
| 1926 |
|
| 1927 |
$ hg -R mandatory-extensions id |
| 1928 |
000000000000 tip |
| 1929 |
|
| 1930 |
Check that the bad one does not load |
| 1931 |
|
| 1932 |
$ cat >> $TESTTMP/mandatory-extensions/.hg/hgrc << EOF |
| 1933 |
> bad = $TESTTMP/mandatory-extensions/.hg/bad.py |
| 1934 |
> EOF |
| 1935 |
|
| 1936 |
$ hg -R mandatory-extensions id |
| 1937 |
*** failed to import extension "bad" from $TESTTMP/mandatory-extensions/.hg/bad.py: babar |
| 1938 |
000000000000 tip |
| 1939 |
|
| 1940 |
Make it mandatory to load |
| 1941 |
|
| 1942 |
$ cat >> $TESTTMP/mandatory-extensions/.hg/hgrc << EOF |
| 1943 |
> bad:required = yes |
| 1944 |
> EOF |
| 1945 |
|
| 1946 |
$ hg -R mandatory-extensions id |
| 1947 |
abort: failed to import extension "bad" from $TESTTMP/mandatory-extensions/.hg/bad.py: babar |
| 1948 |
(loading of this extension was required, see `hg help config.extensions` for details) |
| 1949 |
[255] |
| 1950 |
|
| 1951 |
Make it not mandatory to load |
| 1952 |
|
| 1953 |
$ cat >> $TESTTMP/mandatory-extensions/.hg/hgrc << EOF |
| 1954 |
> bad:required = no |
| 1955 |
> EOF |
| 1956 |
|
| 1957 |
$ hg -R mandatory-extensions id |
| 1958 |
*** failed to import extension "bad" from $TESTTMP/mandatory-extensions/.hg/bad.py: babar |
| 1959 |
000000000000 tip |
| 1960 |
|
| 1961 |
Same check with the syntax error one |
| 1962 |
|
| 1963 |
$ cat >> $TESTTMP/mandatory-extensions/.hg/hgrc << EOF |
| 1964 |
> bad = ! |
| 1965 |
> syntax = $TESTTMP/mandatory-extensions/.hg/syntax.py |
| 1966 |
> syntax:required = yes |
| 1967 |
> EOF |
| 1968 |
|
| 1969 |
$ hg -R mandatory-extensions id |
| 1970 |
abort: failed to import extension "syntax" from $TESTTMP/mandatory-extensions/.hg/syntax.py: invalid syntax (*syntax.py, line 1) (glob) |
| 1971 |
(loading of this extension was required, see `hg help config.extensions` for details) |
| 1972 |
[255] |
| 1973 |
|
| 1974 |
Same check with a missing one |
| 1975 |
|
| 1976 |
$ cat >> $TESTTMP/mandatory-extensions/.hg/hgrc << EOF |
| 1977 |
> syntax = ! |
| 1978 |
> syntax:required = |
| 1979 |
> missing = foo/bar/baz/I/do/not/exist/ |
| 1980 |
> missing:required = yes |
| 1981 |
> EOF |
| 1982 |
|
| 1983 |
$ hg -R mandatory-extensions id |
| 1984 |
abort: failed to import extension "missing" from foo/bar/baz/I/do/not/exist/: [Errno 2] $ENOENT$: 'foo/bar/baz/I/do/not/exist' |
| 1985 |
(loading of this extension was required, see `hg help config.extensions` for details) |
| 1986 |
[255] |
| 1987 |
|
| 1988 |
Have a "default" setting for the suboption: |
| 1989 |
|
| 1990 |
$ cat > $TESTTMP/mandatory-extensions/.hg/hgrc << EOF |
| 1991 |
> [extensions] |
| 1992 |
> bad = $TESTTMP/mandatory-extensions/.hg/bad.py |
| 1993 |
> bad:required = no |
| 1994 |
> good = $TESTTMP/mandatory-extensions/.hg/good.py |
| 1995 |
> syntax = $TESTTMP/mandatory-extensions/.hg/syntax.py |
| 1996 |
> *:required = yes |
| 1997 |
> EOF |
| 1998 |
|
| 1999 |
$ hg -R mandatory-extensions id |
| 2000 |
*** failed to import extension "bad" from $TESTTMP/mandatory-extensions/.hg/bad.py: babar |
| 2001 |
abort: failed to import extension "syntax" from $TESTTMP/mandatory-extensions/.hg/syntax.py: invalid syntax (*syntax.py, line 1) (glob) |
| 2002 |
(loading of this extension was required, see `hg help config.extensions` for details) |
| 2003 |
[255] |