changeset 41125:126101284e04

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.
author Yuya Nishihara <yuya@tcha.org>
date Mon, 07 Jan 2019 21:43:06 +0900
parents cffa8e0ba77a
children d8f5c615e811
files hgext/amend.py mercurial/cmdutil.py tests/test-amend.t
diffstat 3 files changed, 29 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/amend.py	Mon Jan 07 21:39:35 2019 +0900
+++ b/hgext/amend.py	Mon Jan 07 21:43:06 2019 +0900
@@ -36,6 +36,8 @@
      ('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,
--- a/mercurial/cmdutil.py	Mon Jan 07 21:39:35 2019 +0900
+++ b/mercurial/cmdutil.py	Mon Jan 07 21:43:06 2019 +0900
@@ -2443,8 +2443,13 @@
         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
--- a/tests/test-amend.t	Mon Jan 07 21:39:35 2019 +0900
+++ b/tests/test-amend.t	Mon Jan 07 21:43:06 2019 +0900
@@ -438,3 +438,25 @@
   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 ..