Patchwork D6464: commit: respect --no-edit in combination with --amend

login
register
mail settings
Submitter phabricator
Date May 30, 2019, 10:52 p.m.
Message ID <f15aecf025c2d6c9fc4e075ef7434c12@localhost.localdomain>
Download mbox | patch
Permalink /patch/40284/
State Not Applicable
Headers show

Comments

phabricator - May 30, 2019, 10:52 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG64ed405dd342: commit: respect --no-edit in combination with --amend (authored by spectral, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6464?vs=15306&id=15308

REVISION DETAIL
  https://phab.mercurial-scm.org/D6464

AFFECTED FILES
  mercurial/cmdutil.py
  tests/test-commit-amend.t

CHANGE DETAILS




To: spectral, #hg-reviewers, pulkit
Cc: mercurial-devel

Patch

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
@@ -943,17 +943,7 @@ 
 (We need a file change here since we won't have a message change)
   $ cp foo foo.orig
   $ echo hi >> foo
-FIXME: This shouldn't start the editor.
   $ HGEDITOR=cat hg commit --amend --no-edit
-  editor should be suppressed
-  
-  
-  HG: Enter commit message.  Lines beginning with 'HG:' are removed.
-  HG: Leave message empty to abort commit.
-  HG: --
-  HG: user: test
-  HG: branch 'silliness'
-  HG: added foo
   $ hg parents --template "{desc}\n"
   editor should be suppressed
   $ hg status -mar
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2583,12 +2583,18 @@ 
         message = logmessage(ui, opts)
 
         editform = mergeeditform(old, 'commit.amend')
-        editor = getcommiteditor(editform=editform,
-                                 **pycompat.strkwargs(opts))
 
         if not message:
-            editor = getcommiteditor(edit=True, editform=editform)
             message = old.description()
+            # Default if message isn't provided and --edit is not passed is to
+            # invoke editor, but allow --no-edit. If somehow we don't have any
+            # description, let's always start the editor.
+            doedit = not message or opts.get('edit') in [True, None]
+        else:
+            # Default if message is provided is to not invoke editor, but allow
+            # --edit.
+            doedit = opts.get('edit') is True
+        editor = getcommiteditor(edit=doedit, editform=editform)
 
         pureextra = extra.copy()
         extra['amend_source'] = old.hex()