diff --git a/mercurial/changelog.py b/mercurial/changelog.py --- a/mercurial/changelog.py +++ b/mercurial/changelog.py @@ -273,7 +273,11 @@ class changelog(revlog.revlog): if self._delaybuf: # make a temporary copy of the index fp1 = self._realopener(self.indexfile) - fp2 = self._realopener(self.indexfile + ".a", "w") + pendingfilename = self.indexfile + ".a" + # register as a temp file to ensure cleanup on failure + tr.registertmp(pendingfilename) + # write existing data + fp2 = self._realopener(pendingfilename, "w") fp2.write(fp1.read()) # add pending data fp2.write("".join(self._delaybuf)) diff --git a/tests/test-hook.t b/tests/test-hook.t --- a/tests/test-hook.t +++ b/tests/test-hook.t @@ -148,6 +148,19 @@ more there after $ hg -q tip 4:539e4b31b6dc +(Check that no 'changelog.i.a' file were left behind) + + $ ls -1 .hg/store/ + 00changelog.i + 00manifest.i + data + fncache + journal.phaseroots + phaseroots + undo + undo.phaseroots + + precommit hook can prevent commit $ echo "precommit.forbid = python \"$TESTDIR/printenv.py\" precommit.forbid 1" >> .hg/hgrc