[PATCH 1 of 7 STABLE] localrepo: save manually edited commit message as soon as possible

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Tue Mar 18 16:18:39 UTC 2014


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1395158861 -32400
#      Wed Mar 19 01:07:41 2014 +0900
# Branch stable
# Node ID f042d4b263f47d8a2a9e37a3ca25e9bed5675a6f
# Parent  b0153cb8b64efb546cbf3bd6bba5a6770ab2563f
localrepo: save manually edited commit message as soon as possible

Before this patch, "localrepository.commit()" invokes specified
"editor" to edit commit message manually, and saves it after checking
sub-repositories.

This may lose manually edited commit message, if unexpected exception
is raised while checking (or commiting recursively) sub-repositories.

This patch saves manually edited commit message as soon as possible.

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1270,6 +1270,11 @@
                 cctx._text = editor(self, cctx, subs)
             edited = (text != cctx._text)
 
+            # Save commit message in case this transaction gets rolled back
+            # (e.g. by a pretxncommit hook).  Leave the content alone on
+            # the assumption that the user will use the same editor again.
+            msgfn = self.savecommitmessage(cctx._text)
+
             # commit subs and write new state
             if subs:
                 for s in sorted(commitsubs):
@@ -1280,11 +1285,6 @@
                     newstate[s] = (newstate[s][0], sr)
                 subrepo.writestate(self, newstate)
 
-            # Save commit message in case this transaction gets rolled back
-            # (e.g. by a pretxncommit hook).  Leave the content alone on
-            # the assumption that the user will use the same editor again.
-            msgfn = self.savecommitmessage(cctx._text)
-
             p1, p2 = self.dirstate.parents()
             hookp1, hookp2 = hex(p1), (p2 != nullid and hex(p2) or '')
             try:
diff --git a/tests/test-commit.t b/tests/test-commit.t
--- a/tests/test-commit.t
+++ b/tests/test-commit.t
@@ -284,6 +284,52 @@
   HG: removed removed
   abort: empty commit message
   [255]
+
+test saving last-message.txt
+
+  $ hg init sub
+  $ echo a > sub/a
+  $ hg -R sub add sub/a
+  $ cat > sub/.hg/hgrc <<EOF
+  > [hooks]
+  > precommit.test-saving-last-message = false
+  > EOF
+
+  $ echo 'sub = sub' > .hgsub
+  $ hg add .hgsub
+
+  $ cat > $TESTDIR/editor.sh <<EOF
+  > echo "==== before editing:"
+  > cat \$1
+  > echo "===="
+  > echo "test saving last-message.txt" >> \$1
+  > EOF
+
+  $ rm -f .hg/last-message.txt
+  $ HGEDITOR="sh $TESTDIR/editor.sh" hg commit -S -q
+  ==== before editing:
+  
+  
+  HG: Enter commit message.  Lines beginning with 'HG:' are removed.
+  HG: Leave message empty to abort commit.
+  HG: --
+  HG: user: test
+  HG: branch 'default'
+  HG: bookmark 'currentbookmark'
+  HG: subrepo sub
+  HG: added .hgsub
+  HG: added added
+  HG: changed .hgsubstate
+  HG: changed changed
+  HG: removed removed
+  ====
+  abort: precommit.test-saving-last-message hook exited with status 1 (in subrepo sub)
+  [255]
+  $ cat .hg/last-message.txt
+  
+  
+  test saving last-message.txt
+
   $ cd ..
 
 


More information about the Mercurial-devel mailing list