diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -825,6 +825,7 @@ class localrepository(repo.repository): extra, changes) if editor: cctx._text = editor(self, cctx, subs) + edited = (text != cctx._text) # commit subs if subs: @@ -844,7 +845,14 @@ class localrepository(repo.repository): msgfile.write(cctx._text.rstrip() + '\n') msgfile.close() - ret = self.commitctx(cctx, True) + try: + ret = self.commitctx(cctx, True) + except: + if edited: + msgfn = self.pathto(msgfile.name[len(self.root)+1:]) + self.ui.write( + _('note: commit message saved in %s\n') % msgfn) + raise # update dirstate and mergestate for f in changes[0] + changes[1]: diff --git a/tests/test-rollback b/tests/test-rollback --- a/tests/test-rollback +++ b/tests/test-rollback @@ -34,6 +34,15 @@ 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 + +echo '% same thing, but run $EDITOR' +cat > $HGTMP/editor <<'__EOF__' +#!/bin/sh +echo "another precious commit message" > "$1" +__EOF__ +chmod +x $HGTMP/editor +HGEDITOR=$HGTMP/editor hg --config hooks.pretxncommit=/bin/false commit +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 @@ -34,3 +34,10 @@ rollback completed abort: pretxncommit hook exited with status 1 .hg/last-message.txt: precious commit message +% same thing, but run $EDITOR +transaction abort! +rollback completed +note: commit message saved in .hg/last-message.txt +abort: pretxncommit hook exited with status 1 +.hg/last-message.txt: +another precious commit message