diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -1194,13 +1194,16 @@ class localrepository(object): return l def _afterlock(self, callback): - """add a callback to the current repository lock. + """add a callback to be run when the repository is fully unlocked - The callback will be executed on lock release.""" - l = self._lockref and self._lockref() - if l: - l.postrelease.append(callback) - else: + The callback will be executed when the outermost lock is released + (with wlock being higher level than 'lock').""" + for ref in (self._wlockref, self._lockref): + l = ref and ref() + if l and l.held: + l.postrelease.append(callback) + break + else: # no lock have been found. callback() def lock(self, wait=True): diff --git a/tests/test-hook.t b/tests/test-hook.t --- a/tests/test-hook.t +++ b/tests/test-hook.t @@ -1,4 +1,5 @@ commit hooks can see env vars +(and post-transaction one are run unlocked) $ hg init a $ cd a @@ -16,6 +17,7 @@ commit hooks can see env vars > pretxnclose = sh -c "HG_LOCAL= HG_TAG= python \"$TESTDIR/printenv.py\" pretxnclose" > txnclose = sh -c "HG_LOCAL= HG_TAG= python \"$TESTDIR/printenv.py\" txnclose" > txnabort = sh -c "HG_LOCAL= HG_TAG= python \"$TESTDIR/printenv.py\" txnabort" + > txnclose.checklock = hg debuglock > /dev/null > EOF $ echo a > a $ hg add a