diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -835,6 +835,15 @@ class localrepository(repo.repository): state[s] = (state[s][0], sr) subrepo.writestate(self, state) + # Save commit message in case this transaction gets rolled back + # (e.g. by a pretxncommit hook). (Save in text mode in case a + # Windows user wants to edit it with Notepad. Normalize + # trailing whitespace so the file always looks the same -- + # makes testing easier.) + msgfile = self.opener('last-message.txt', 'w') + msgfile.write(cctx._text.rstrip() + '\n') + msgfile.close() + ret = self.commitctx(cctx, True) # update dirstate and mergestate diff --git a/tests/test-fncache.out b/tests/test-fncache.out --- a/tests/test-fncache.out +++ b/tests/test-fncache.out @@ -50,6 +50,7 @@ adding tst.d/foo .hg/data/tst.d.hg .hg/data/tst.d.hg/foo.i .hg/dirstate +.hg/last-message.txt .hg/requires .hg/undo .hg/undo.branch @@ -59,6 +60,7 @@ adding tst.d/Foo .hg .hg/00changelog.i .hg/dirstate +.hg/last-message.txt .hg/requires .hg/store .hg/store/00changelog.i diff --git a/tests/test-inherit-mode.out b/tests/test-inherit-mode.out --- a/tests/test-inherit-mode.out +++ b/tests/test-inherit-mode.out @@ -14,6 +14,7 @@ 00770 ./.hg/store/ 00700 ./.hg/ 00600 ./.hg/00changelog.i 00660 ./.hg/dirstate +00660 ./.hg/last-message.txt 00600 ./.hg/requires 00770 ./.hg/store/ 00660 ./.hg/store/00changelog.i diff --git a/tests/test-rollback b/tests/test-rollback --- a/tests/test-rollback +++ b/tests/test-rollback @@ -15,14 +15,25 @@ hg parents hg status echo % Test issue 902 -hg commit -m "test" +hg commit -m "test2" hg branch test hg rollback hg branch +echo '% Test issue 1635 (commit message saved)' +echo '.hg/last-message.txt:' +cat .hg/last-message.txt + echo % Test rollback of hg before issue 902 was fixed -hg commit -m "test" +hg commit -m "test3" hg branch test rm .hg/undo.branch hg rollback hg branch + +echo '% rollback by pretxncommit saves commit message (issue 1635)' +echo a >> a +hg --config hooks.pretxncommit=/bin/false commit -m"precious commit message" + +echo '.hg/last-message.txt:' +cat .hg/last-message.txt diff --git a/tests/test-rollback.out b/tests/test-rollback.out --- a/tests/test-rollback.out +++ b/tests/test-rollback.out @@ -20,8 +20,17 @@ A a marked working directory as branch test rolling back last transaction default +% Test issue 1635 (commit message saved) +.hg/last-message.txt: +test2 % Test rollback of hg before issue 902 was fixed marked working directory as branch test rolling back last transaction Named branch could not be reset, current branch still is: test test +% rollback by pretxncommit saves commit message (issue 1635) +transaction abort! +rollback completed +abort: pretxncommit hook exited with status 1 +.hg/last-message.txt: +precious commit message