[PATCH] commit: add --reuse-message for keeping the old commit message during amend

Durham Goode durham at fb.com
Sat Feb 9 05:35:15 CST 2013


# HG changeset patch
# User Durham Goode <durham at fb.com>
# Date 1360352769 28800
# Node ID 96e2d74e5f7b32221480fc7932c9555c84f10670
# Parent  e2b176cf28e374eb146c3e131871631ab9ace537
commit: add --reuse-message for keeping the old commit message during amend

When people do 'hg commit --amend', most of the time they don't want to change
the commit message.  This adds a flag to do that without prompting the user.

I imagine most people will use it in an alias such as:

  amend=commit --amend --reuse-message

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1702,7 +1702,7 @@
                 date = opts.get('date') or old.date()
             editmsg = False
             if not message:
-                editmsg = True
+                editmsg = not opts.get('reuse_message')
                 message = old.description()
 
             pureextra = extra.copy()
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1241,6 +1241,8 @@
     ('', 'close-branch', None,
      _('mark a branch as closed, hiding it from the branch list')),
     ('', 'amend', None, _('amend the parent of the working dir')),
+    ('', 'reuse-message', None,
+      _('used with amend to reuse the previous commit message')),
     ] + walkopts + commitopts + commitopts2 + subrepoopts,
     _('[OPTION]... [FILE]...'))
 def commit(ui, repo, *pats, **opts):
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
@@ -518,3 +518,14 @@
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     babar
   
+
+Test amend with reuse-message flag
+---------------------------------------------------------------------
+Verify that the editor doesn't appear
+  $ hg rm a
+  $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg ci --amend --reuse-message
+  $ hg log -r . --template "Description: {desc}\n" --stat
+  Description: a''
+   a |  7 -------
+   1 files changed, 0 insertions(+), 7 deletions(-)
+  
diff --git a/tests/test-debugcomplete.t b/tests/test-debugcomplete.t
--- a/tests/test-debugcomplete.t
+++ b/tests/test-debugcomplete.t
@@ -197,7 +197,7 @@
   add: include, exclude, subrepos, dry-run
   annotate: rev, follow, no-follow, text, user, file, date, number, changeset, line-number, ignore-all-space, ignore-space-change, ignore-blank-lines, include, exclude
   clone: noupdate, updaterev, rev, branch, pull, uncompressed, ssh, remotecmd, insecure
-  commit: addremove, close-branch, amend, include, exclude, message, logfile, date, user, subrepos
+  commit: addremove, close-branch, amend, reuse-message, include, exclude, message, logfile, date, user, subrepos
   diff: rev, change, text, git, nodates, show-function, reverse, ignore-all-space, ignore-space-change, ignore-blank-lines, unified, stat, include, exclude, subrepos
   export: output, switch-parent, rev, text, git, nodates
   forget: include, exclude
diff --git a/tests/test-qrecord.t b/tests/test-qrecord.t
--- a/tests/test-qrecord.t
+++ b/tests/test-qrecord.t
@@ -61,6 +61,7 @@
       --close-branch        mark a branch as closed, hiding it from the branch
                             list
       --amend               amend the parent of the working dir
+      --reuse-message       used with amend to reuse the previous commit message
    -I --include PATTERN [+] include names matching the given patterns
    -X --exclude PATTERN [+] exclude names matching the given patterns
    -m --message TEXT        use text as commit message


More information about the Mercurial-devel mailing list