[PATCH 7 of 7 STABLE] amend: save commit message into ".hg/last-message.txt"

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Tue Mar 18 11:18:45 CDT 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 434619dae569c40e6a8345616c5be180b1b87311
# Parent  5d22cadd1938d759a0997a1c12a869a80d7498b8
amend: save commit message into ".hg/last-message.txt"

Before this patch, commit message (may be manually edited) for "commit
--amend" is never saved into ".hg/last-message.txt", because it uses
"localrepository.commitctx()" instead of "localrepository.commit()":
saving into ".hg/last-message.txt" is executed only in the latter.

This patch saves commit message for "commit --amend" into
".hg/last-message.txt" just after user editing.

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

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1782,6 +1782,7 @@
                                  extra=extra)
             if editmsg:
                 new._text = commitforceeditor(repo, new, [])
+            repo.savecommitmessage(new.description())
 
             newdesc =  changelog.stripdesc(new.description())
             if ((not node)
diff --git a/tests/test-commit-amend.t b/tests/test-commit-amend.t
--- a/tests/test-commit-amend.t
+++ b/tests/test-commit-amend.t
@@ -165,6 +165,57 @@
   > cat $1
   > echo "another precious commit message" > "$1"
   > __EOF__
+
+at first, test saving last-message.txt
+
+  $ cat > .hg/hgrc << '__EOF__'
+  > [hooks]
+  > pretxncommit.test-saving-last-message = false
+  > __EOF__
+
+  $ rm -f .hg/last-message.txt
+  $ hg commit --amend -v -m "message given from command line"
+  amending changeset 5f357c7560ab
+  copying changeset 5f357c7560ab to ad120869acf0
+  a
+  running hook pretxncommit.test-saving-last-message: false
+  transaction abort!
+  rollback completed
+  abort: pretxncommit.test-saving-last-message hook exited with status 1
+  [255]
+  $ cat .hg/last-message.txt
+  message given from command line (no-eol)
+
+  $ rm -f .hg/last-message.txt
+  $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg commit --amend -v
+  amending changeset 5f357c7560ab
+  copying changeset 5f357c7560ab to ad120869acf0
+  no changes, new message
+  
+  
+  HG: Enter commit message.  Lines beginning with 'HG:' are removed.
+  HG: Leave message empty to abort commit.
+  HG: --
+  HG: user: foo
+  HG: branch 'default'
+  HG: changed a
+  a
+  running hook pretxncommit.test-saving-last-message: false
+  transaction abort!
+  rollback completed
+  abort: pretxncommit.test-saving-last-message hook exited with status 1
+  [255]
+
+  $ cat .hg/last-message.txt
+  another precious commit message
+
+  $ cat > .hg/hgrc << '__EOF__'
+  > [hooks]
+  > pretxncommit.test-saving-last-message =
+  > __EOF__
+
+then, test editing custom commit message
+
   $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg commit --amend -v
   amending changeset 5f357c7560ab
   copying changeset 5f357c7560ab to ad120869acf0


More information about the Mercurial-devel mailing list