Patchwork [STABLE,V2] amend: abort early if no username is configured with evolve enabled (issue4211)

login
register
mail settings
Submitter Matt Harbison
Date Oct. 29, 2014, 2:45 p.m.
Message ID <16fef3a9c606be947f65.1414593930@MATT7H-PC.attotech.com>
Download mbox | patch
Permalink /patch/6493/
State Accepted
Headers show

Comments

Matt Harbison - Oct. 29, 2014, 2:45 p.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1414551919 14400
#      Tue Oct 28 23:05:19 2014 -0400
# Branch stable
# Node ID 16fef3a9c606be947f65c04b9194851ab2af4deb
# Parent  ac494b087febf0e00a84ff2a699c0690be2c453c
amend: abort early if no username is configured with evolve enabled (issue4211)

Amend will reuse the original username if a new one is not provided with -U, but
obsolete.createmarkers() only considers ui.username() for the obsolete marker's
metadata.  Allowing the metadata field to be spoofed seems to defeat the point
of the field in the first place.  This covers 'evolve amend' and 'ci --amend'
with evolve enabled.

Without this, the transaction aborts but the parent changeset is set to -1.
Matt Mackall - Oct. 29, 2014, 8:01 p.m.
On Wed, 2014-10-29 at 10:45 -0400, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1414551919 14400
> #      Tue Oct 28 23:05:19 2014 -0400
> # Branch stable
> # Node ID 16fef3a9c606be947f65c04b9194851ab2af4deb
> # Parent  ac494b087febf0e00a84ff2a699c0690be2c453c
> amend: abort early if no username is configured with evolve enabled (issue4211)

Updated, thanks.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1454,6 +1454,11 @@  def commit(ui, repo, *pats, **opts):
         if not allowunstable and old.children():
             raise util.Abort(_('cannot amend changeset with children'))
 
+        # amend will reuse the existing user if not specified, but the obsolete
+        # marker creation requires that the current user's name is specified.
+        if obsolete.isenabled(repo, obsolete.createmarkersopt):
+            ui.username() # raise exception if username not set
+
         # commitfunc is used only for temporary amend commit by cmdutil.amend
         def commitfunc(ui, repo, message, match, opts):
             return repo.commit(message,
diff --git a/tests/test-obsolete.t b/tests/test-obsolete.t
--- a/tests/test-obsolete.t
+++ b/tests/test-obsolete.t
@@ -753,3 +753,18 @@  Test that removing a local tag does not 
   $ hg tags
   visible                            0:193e9254ce7e
   tip                                0:193e9254ce7e
+
+Test that amend with no ui.username doesn't reset the parent to -1 (issue4211)
+  $ HGUSER=
+  $ hg -q up
+  $ hg ci --amend --config ui.username= -m "empty user"
+  abort: no username supplied
+  (use "hg config --edit" to set your username)
+  [255]
+  $ hg sum
+  parent: 0:193e9254ce7e tip visible
+   A
+  branch: default
+  commit: (clean)
+  update: (current)
+