# HG changeset patch
# User Yuya Nishihara <y...@tcha.org>
# Date 1546864986 -32400
#      Mon Jan 07 21:43:06 2019 +0900
# Node ID e39414322e34d799c2f22df815fae5b7efa839ff
# Parent  d3181b286250540ecae30e46518c0fbdd43b5bb9
amend: add -D/--currentdate option

It bumps the date field even if there's no other change. The help text is
copied from commands.graft().

Unlike graft, --date with --currentdate is disallowed, which I think is
saner behavior.

diff --git a/hgext/amend.py b/hgext/amend.py
--- a/hgext/amend.py
+++ b/hgext/amend.py
@@ -36,6 +36,8 @@ command = registrar.command(cmdtable)
      ('e', 'edit', None, _('invoke editor on commit messages')),
      ('i', 'interactive', None, _('use interactive mode')),
      ('n', 'note', '', _('store a note on the amend')),
+     ('D', 'currentdate', False,
+      _('record the current date as commit date')),
     ] + cmdutil.walkopts + cmdutil.commitopts + cmdutil.commitopts2,
     _('[OPTION]... [FILE]...'),
     helpcategory=command.CATEGORY_COMMITTING,
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2443,8 +2443,13 @@ def amend(ui, repo, old, extra, pats, op
         user = opts.get('user') or old.user()
 
         datemaydiffer = False  # date-only change should be ignored?
+        if opts.get('date') and opts.get('currentdate'):
+            raise error.Abort(_('--date and --currentdate are mutually '
+                                'exclusive'))
         if opts.get('date'):
             date = dateutil.parsedate(opts.get('date'))
+        elif opts.get('currentdate'):
+            date = dateutil.makedate()
         elif ui.configbool('rewrite', 'update-timestamp'):
             date = dateutil.makedate()
             datemaydiffer = True
diff --git a/tests/test-amend.t b/tests/test-amend.t
--- a/tests/test-amend.t
+++ b/tests/test-amend.t
@@ -438,3 +438,25 @@ When date option is applicable and updat
   user:        foobar
   date:        Thu Jan 01 00:01:00 1998 +0000
   summary:     commit 1
+
+Unlike rewrite.update-timestamp, -D/--currentdate always updates the timestamp
+
+  $ hg amend -D
+  $ hg log --limit 1
+  user:        foobar
+  date:        Thu Jan 01 00:00:04 1970 +0000
+  summary:     commit 1
+
+  $ hg amend -D --config rewrite.update-timestamp=True
+  $ hg log --limit 1
+  user:        foobar
+  date:        Thu Jan 01 00:00:05 1970 +0000
+  summary:     commit 1
+
+Bad combination of date options:
+
+  $ hg amend -D --date '0 0'
+  abort: --date and --currentdate are mutually exclusive
+  [255]
+
+  $ cd ..
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to