Show More
@@ -37,10 +37,18 b' def _pythonhook(ui, repo, name, hname, f' | |||
|
37 | 37 | try: |
|
38 | 38 | obj = __import__(modname) |
|
39 | 39 | except ImportError: |
|
40 | e1 = sys.exc_type, sys.exc_value, sys.exc_traceback | |
|
40 | 41 | try: |
|
41 | 42 | # extensions are loaded with hgext_ prefix |
|
42 | 43 | obj = __import__("hgext_%s" % modname) |
|
43 | 44 | except ImportError: |
|
45 | e2 = sys.exc_type, sys.exc_value, sys.exc_traceback | |
|
46 | if ui.tracebackflag: | |
|
47 | ui.warn(_('exception from first failed import attempt:\n')) | |
|
48 | ui.traceback(e1) | |
|
49 | if ui.tracebackflag: | |
|
50 | ui.warn(_('exception from second failed import attempt:\n')) | |
|
51 | ui.traceback(e2) | |
|
44 | 52 | raise util.Abort(_('%s hook is invalid ' |
|
45 | 53 | '(import of "%s" failed)') % |
|
46 | 54 | (hname, modname)) |
@@ -15,7 +15,7 b' import config, util, error' | |||
|
15 | 15 | class ui(object): |
|
16 | 16 | def __init__(self, src=None): |
|
17 | 17 | self._buffers = [] |
|
18 |
self.quiet = self.verbose = self.debugflag = self. |
|
|
18 | self.quiet = self.verbose = self.debugflag = self.tracebackflag = False | |
|
19 | 19 | self._reportuntrusted = True |
|
20 | 20 | self._ocfg = config.config() # overlay |
|
21 | 21 | self._tcfg = config.config() # trusted |
@@ -101,7 +101,7 b' class ui(object):' | |||
|
101 | 101 | if self.verbose and self.quiet: |
|
102 | 102 | self.quiet = self.verbose = False |
|
103 | 103 | self._reportuntrusted = self.configbool("ui", "report_untrusted", True) |
|
104 |
self. |
|
|
104 | self.tracebackflag = self.configbool('ui', 'traceback', False) | |
|
105 | 105 | |
|
106 | 106 | # update trust information |
|
107 | 107 | self._trustusers.update(self.configlist('trusted', 'users')) |
@@ -337,13 +337,16 b' class ui(object):' | |||
|
337 | 337 | |
|
338 | 338 | return t |
|
339 | 339 | |
|
340 | def traceback(self): | |
|
340 | def traceback(self, exc=None): | |
|
341 | 341 | '''print exception traceback if traceback printing enabled. |
|
342 | 342 | only to call in exception handler. returns true if traceback |
|
343 | 343 | printed.''' |
|
344 |
if self. |
|
|
345 |
|
|
|
346 | return self._traceback | |
|
344 | if self.tracebackflag: | |
|
345 | if exc: | |
|
346 | traceback.print_exception(exc[0], exc[1], exc[2]) | |
|
347 | else: | |
|
348 | traceback.print_exc() | |
|
349 | return self.tracebackflag | |
|
347 | 350 | |
|
348 | 351 | def geteditor(self): |
|
349 | 352 | '''return editor to use''' |
@@ -248,4 +248,18 b' echo "pre-commit.test = python:`pwd`/tes' | |||
|
248 | 248 | cd ../repo |
|
249 | 249 | hg commit |
|
250 | 250 | |
|
251 | cd ../../b | |
|
252 | echo '# make sure --traceback works on hook import failure' | |
|
253 | cat > importfail.py <<EOF | |
|
254 | import somebogusmodule | |
|
255 | # dereference something in the module to force demandimport to load it | |
|
256 | somebogusmodule.whatever | |
|
257 | EOF | |
|
258 | ||
|
259 | echo '[hooks]' > .hg/hgrc | |
|
260 | echo 'precommit.importfail = python:importfail.whatever' >> .hg/hgrc | |
|
261 | ||
|
262 | echo a >> a | |
|
263 | hg --traceback commit -Ama 2>&1 | grep '^\(exception\|Traceback\|ImportError\)' | |
|
264 | ||
|
251 | 265 | exit 0 |
@@ -163,3 +163,11 b' hooks.commit.auto=<function autohook>' | |||
|
163 | 163 | # test python hook configured with python:[file]:[hook] syntax |
|
164 | 164 | hook works |
|
165 | 165 | nothing changed |
|
166 | # make sure --traceback works on hook import failure | |
|
167 | exception from first failed import attempt: | |
|
168 | Traceback (most recent call last): | |
|
169 | ImportError: No module named somebogusmodule | |
|
170 | exception from second failed import attempt: | |
|
171 | Traceback (most recent call last): | |
|
172 | ImportError: No module named hgext_importfail | |
|
173 | Traceback (most recent call last): |
General Comments 0
You need to be logged in to leave comments.
Login now