[PATCH STABLE] amend: force editor only if old message is reused (issue3698)

pierre-yves.david at logilab.fr pierre-yves.david at logilab.fr
Tue Nov 13 05:33:23 CST 2012


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1352805847 -3600
# Branch stable
# Node ID a13178442bd8bb4272d00b1e8119db27f16d3b4f
# Parent  ce2c709a8e908747376a3fda6059c1f81de321e7
amend: force editor only if old message is reused (issue3698)

This regression was added by 9732473aa24b. It triggered the editor even if
--message ot --logfile were provided.

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1713,11 +1713,13 @@ def amend(ui, repo, commitfunc, old, ext
                     except KeyError:
                         raise IOError
 
                 user = opts.get('user') or old.user()
                 date = opts.get('date') or old.date()
+            editmsg = False
             if not message:
+                editmsg = True
                 message = old.description()
 
             pureextra = extra.copy()
             extra['amend_source'] = old.hex()
 
@@ -1727,11 +1729,12 @@ def amend(ui, repo, commitfunc, old, ext
                                  files=files,
                                  filectxfn=filectxfn,
                                  user=user,
                                  date=date,
                                  extra=extra)
-            new._text = commitforceeditor(repo, new, [])
+            if editmsg:
+                new._text = commitforceeditor(repo, new, [])
 
             newdesc =  changelog.stripdesc(new.description())
             if ((not node)
                 and newdesc == old.description()
                 and user == old.user()
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
@@ -27,13 +27,14 @@ Nothing to amend:
   > [hooks]
   > pretxncommit.foo = sh -c "echo \\"pretxncommit \$HG_NODE\\"; hg id -r \$HG_NODE"
   > EOF
 
 Amending changeset with changes in working dir:
+(and check that --message does not trigger an editor)
 
   $ echo a >> a
-  $ hg ci --amend -m 'amend base1'
+  $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg commit --amend -m 'amend base1'
   pretxncommit 43f1ba15f28a50abf0aae529cf8a16bfced7b149
   43f1ba15f28a tip
   saved backup bundle to $TESTTMP/.hg/strip-backup/489edb5b847d-amend-backup.hg (glob)
   $ echo 'pretxncommit.foo = ' >> $HGRCPATH
   $ hg diff -c .
@@ -64,14 +65,15 @@ Add new file:
   adding b
   saved backup bundle to $TESTTMP/.hg/strip-backup/43f1ba15f28a-amend-backup.hg (glob)
 
 Remove file that was added in amended commit:
 (and test logfile option)
+(and test that logfile option do not trigger an editor)
 
   $ hg rm b
   $ echo 'amend base1 remove new file' > ../logfile
-  $ hg ci --amend -l ../logfile
+  $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg ci --amend --logfile ../logfile
   saved backup bundle to $TESTTMP/.hg/strip-backup/b8e3cb2b3882-amend-backup.hg (glob)
 
   $ hg cat b
   b: no such file in rev 74609c7f506e
   [1]


More information about the Mercurial-devel mailing list