Patchwork [4,of,4] amend: add -D/--currentdate option

login
register
mail settings
Submitter Yuya Nishihara
Date Jan. 7, 2019, 1:33 p.m.
Message ID <e39414322e34d799c2f2.1546867993@mimosa>
Download mbox | patch
Permalink /patch/37530/
State Accepted
Headers show

Comments

Yuya Nishihara - Jan. 7, 2019, 1:33 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@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.
Pulkit Goyal - Jan. 7, 2019, 2:23 p.m.
On Mon, Jan 7, 2019 at 7:11 PM Yuya Nishihara <yuya@tcha.org> wrote:

> # HG changeset patch
> # User Yuya Nishihara <yuya@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.
>

We should disallow that behavior in graft too IMO.
Augie Fackler - Jan. 8, 2019, 2:12 a.m.
On Mon, Jan 07, 2019 at 10:33:13PM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1546864986 -32400
> #      Mon Jan 07 21:43:06 2019 +0900
> # Node ID e39414322e34d799c2f22df815fae5b7efa839ff
> # Parent  d3181b286250540ecae30e46518c0fbdd43b5bb9
> amend: add -D/--currentdate option

queued, thanks

Patch

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 ..