D4876: amend: add config to skip amend if only date is changed (issue5828)

Zharaskhan (Zharaskhan) phabricator at mercurial-scm.org
Wed Oct 3 22:33:24 UTC 2018


Zharaskhan created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  When --date flag specified with `hg amend` and working copy is clean,
  `hg amend` amends, which is generally undesirable behavior.
  But it is commonly used to change date on each amend.
  I added experimental.amend.dateonly config option to not amend
  if only thing that changed is date.
  I also added tests for this.

REPOSITORY
  rHG Mercurial

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

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

CHANGE DETAILS

diff --git a/tests/test-amend.t b/tests/test-amend.t
--- a/tests/test-amend.t
+++ b/tests/test-amend.t
@@ -365,3 +365,40 @@
   $ hg amend
 
 #endif
+
+  $ hg status
+  $ hg diff
+  $ hg amend --date '1980-1-1 0:1'
+  $ hg export
+  # HG changeset patch
+  # User test
+  # Date 315532860 0
+  #      Tue Jan 01 00:01:00 1980 +0000
+  # Node ID 67c8ed970566d909b4759ad6db6048ea9080743b
+  # Parent  cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
+  b
+  
+  diff --git a/b b/b
+  new file mode 100644
+  --- /dev/null
+  +++ b/b
+  @@ -0,0 +1,1 @@
+  +fixed
+  $ hg amend --date '1990-1-1 0:1' --config experimental.amend.dateonly=True
+  nothing changed
+  [1]
+  $ hg export
+  # HG changeset patch
+  # User test
+  # Date 315532860 0
+  #      Tue Jan 01 00:01:00 1980 +0000
+  # Node ID 67c8ed970566d909b4759ad6db6048ea9080743b
+  # Parent  cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
+  b
+  
+  diff --git a/b b/b
+  new file mode 100644
+  --- /dev/null
+  +++ b/b
+  @@ -0,0 +1,1 @@
+  +fixed
diff --git a/mercurial/configitems.py b/mercurial/configitems.py
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -437,6 +437,9 @@
 coreconfigitem('email', 'to',
     default=None,
 )
+coreconfigitem('experimental', 'amend.dateonly',
+    default=False,
+)
 coreconfigitem('experimental', 'archivemetatemplate',
     default=dynamicdefault,
 )
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2558,13 +2558,17 @@
         if ((not changes)
             and newdesc == old.description()
             and user == old.user()
-            and date == old.date()
             and pureextra == old.extra()):
-            # nothing changed. continuing here would create a new node
-            # anyway because of the amend_source noise.
-            #
-            # This not what we expect from amend.
-            return old.node()
+
+            # If the date is same or
+            # the user doesn't want to create a date only change amend
+            if date == old.date() or ui.configbool('experimental',
+                                                   'amend.dateonly'):
+                # nothing changed. continuing here would create a new node
+                # anyway because of the amend_source noise.
+                #
+                # This not what we expect from amend.
+                return old.node()
 
         commitphase = None
         if opts.get('secret'):



To: Zharaskhan, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list