Patchwork [5,of,7,STABLE] qfold: save manually edited commit message into ".hg/last-message.txt"

login
register
mail settings
Submitter Katsunori FUJIWARA
Date March 18, 2014, 4:18 p.m.
Message ID <1e686e55780c1e233d54.1395159523@juju>
Download mbox | patch
Permalink /patch/3961/
State Accepted
Commit 1e686e55780c1e233d54c79c044c9a5c0ffa65ea
Headers show

Comments

Katsunori FUJIWARA - March 18, 2014, 4:18 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1395158861 -32400
#      Wed Mar 19 01:07:41 2014 +0900
# Branch stable
# Node ID 1e686e55780c1e233d54c79c044c9a5c0ffa65ea
# Parent  57d0c8c3b9478a0d52ad0c2c87e2d09e9e2bfd4b
qfold: save manually edited commit message into ".hg/last-message.txt"

Before this patch, manually edited commit message for "hg qfold -e"
isn't saved into ".hg/last-message.txt" until it is saved by
"localrepository.savecommitmessage()" in "localrepository.commit()".

This may lose such commit message, if unexpected exception is raised.

This patch saves manually edited commit message for "hg qfold -e" into
".hg/last-message.txt" just after user editing. This patch doesn't
save the message specified by -m/-l options as same as other commands.

This is the simplest implementation to fix on stable. Editing and
saving commit message should be centralized into the framework of
"localrepository.commit()" with "editor" argument in the future.

This patch uses repository wrapping class for exception raising before
saving commit message in "localrepository.commit()" easily and
certainly, because such exception requires corner case condition.

Patch

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -2576,6 +2576,7 @@ 
 
     if opts.get('edit'):
         message = ui.edit(message, user or ui.username())
+        repo.savecommitmessage(message)
 
     diffopts = q.patchopts(q.diffopts(), *patches)
     wlock = repo.wlock()
diff --git a/tests/test-mq-qfold.t b/tests/test-mq-qfold.t
--- a/tests/test-mq-qfold.t
+++ b/tests/test-mq-qfold.t
@@ -140,5 +140,41 @@ 
    b
   +b
 
+Test saving last-message.txt:
+
+  $ hg qrefresh -m "original message"
+
+  $ cat > $TESTDIR/commitfailure.py <<EOF
+  > from mercurial import util
+  > def reposetup(ui, repo):
+  >     class commitfailure(repo.__class__):
+  >         def commit(self, *args, **kwargs):
+  >             raise util.Abort('emulating unexpected abort')
+  >     repo.__class__ = commitfailure
+  > EOF
+
+  $ cat > .hg/hgrc <<EOF
+  > [extensions]
+  > commitfailure = $TESTDIR/commitfailure.py
+  > EOF
+
+  $ cat > $TESTDIR/editor.sh << EOF
+  > echo "==== before editing"
+  > cat \$1
+  > echo "===="
+  > (echo; echo "test saving last-message.txt") >> \$1
+  > EOF
+
+  $ rm -f .hg/last-message.txt
+  $ HGEDITOR="sh $TESTDIR/editor.sh" hg qfold -e p3
+  ==== before editing
+  original message====
+  refresh interrupted while patch was popped! (revert --all, qpush to recover)
+  abort: emulating unexpected abort
+  [255]
+  $ cat .hg/last-message.txt
+  original message
+  test saving last-message.txt
+
   $ cd ..