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

Matt Harbison matt_harbison at yahoo.com
Wed Oct 29 09:45:30 CDT 2014


# HG changeset patch
# User Matt Harbison <matt_harbison at 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.

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)
+


More information about the Mercurial-devel mailing list