commit: save commit message so it's not destroyed by rollback.
(
issue1635)
Rationale: if a pretxncommit hook rejects this commit, the transaction
is rolled back and the user's commit message is irrevocably lost.
So save a copy in .hg/last-message.txt, just in case. Also handy if
the user deliberately rolls back a commit in order to amend it.
--- a/mercurial/localrepo.py Fri Aug 14 08:19:49 2009 -0400
+++ b/mercurial/localrepo.py Tue Nov 24 21:08:39 2009 -0500
@@ -835,6 +835,15 @@
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
--- a/tests/test-fncache.out Fri Aug 14 08:19:49 2009 -0400
+++ b/tests/test-fncache.out Tue Nov 24 21:08:39 2009 -0500
@@ -50,6 +50,7 @@
.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 @@
.hg
.hg/00changelog.i
.hg/dirstate
+.hg/last-message.txt
.hg/requires
.hg/store
.hg/store/00changelog.i
--- a/tests/test-inherit-mode.out Fri Aug 14 08:19:49 2009 -0400
+++ b/tests/test-inherit-mode.out Tue Nov 24 21:08:39 2009 -0500
@@ -14,6 +14,7 @@
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
--- a/tests/test-rollback Fri Aug 14 08:19:49 2009 -0400
+++ b/tests/test-rollback Tue Nov 24 21:08:39 2009 -0500
@@ -15,14 +15,25 @@
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
--- a/tests/test-rollback.out Fri Aug 14 08:19:49 2009 -0400
+++ b/tests/test-rollback.out Tue Nov 24 21:08:39 2009 -0500
@@ -20,8 +20,17 @@
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