# HG changeset patch # User Sietse Brouwer # Date 1449103101 -3600 # Node ID 10695f8f3323e745a2603f6f2ff7d11956c58e7b # Parent f20533623833d960241cd32aa45ba5d31bf310c3 dirstate: don't write repo.currenttransaction to repo.dirstate if repo is None (issue4983) Some hooks, such as post-init and post-clone, do not get a repo parameter in their environment. If there is no repo, there is no repo.currenttransaction(); attempting to retrieve it anyway was causing crashes. Now currenttransaction is only retrieved and written if the repo is not None. diff -r f20533623833 -r 10695f8f3323 mercurial/hook.py --- a/mercurial/hook.py Wed Dec 02 14:20:13 2015 -0800 +++ b/mercurial/hook.py Thu Dec 03 01:38:21 2015 +0100 @@ -120,10 +120,11 @@ env = {} # make in-memory changes visible to external process - tr = repo.currenttransaction() - repo.dirstate.write(tr) - if tr and tr.writepending(): - env['HG_PENDING'] = repo.root + if repo is not None: + tr = repo.currenttransaction() + repo.dirstate.write(tr) + if tr and tr.writepending(): + env['HG_PENDING'] = repo.root for k, v in args.iteritems(): if callable(v): diff -r f20533623833 -r 10695f8f3323 tests/test-hook.t --- a/tests/test-hook.t Wed Dec 02 14:20:13 2015 -0800 +++ b/tests/test-hook.t Thu Dec 03 01:38:21 2015 +0100 @@ -681,10 +681,19 @@ $ hg tag -f foo ['a', 'foo', 'tip'] +post-init hooks must not crash (issue4983) +This also creates the `to` repo for the next test block. + + $ cd .. + $ cat << EOF >> hgrc-with-post-init-hook + > [hooks] + > post-init = printenv.py post-init + > EOF + $ HGRCPATH=hgrc-with-post-init-hook hg init to + post-init hook: HG_ARGS=init to HG_OPTS={'insecure': None, 'remotecmd': '', 'ssh': ''} HG_PATS=['to'] HG_RESULT=0 + new commits must be visible in pretxnchangegroup (issue3428) - $ cd .. - $ hg init to $ echo '[hooks]' >> to/.hg/hgrc $ echo 'prechangegroup = hg --traceback tip' >> to/.hg/hgrc $ echo 'pretxnchangegroup = hg --traceback tip' >> to/.hg/hgrc