uncommit: add support to modify the commit message and date
authorMatt Harbison <matt_harbison@yahoo.com>
Sat, 07 Sep 2019 13:44:29 -0400
changeset 42902 ff1ff2aae132
parent 42901 75bd5990d8fe
child 42903 66048f6b5d0d
uncommit: add support to modify the commit message and date Currently, the evolve extension's version of this command supports it. Differential Revision: https://phab.mercurial-scm.org/D6827
hgext/uncommit.py
tests/test-uncommit.t
--- a/hgext/uncommit.py	Fri Jun 14 17:50:04 2019 +0100
+++ b/hgext/uncommit.py	Sat Sep 07 13:44:29 2019 -0400
@@ -55,7 +55,8 @@
 # leave the attribute unspecified.
 testedwith = 'ships-with-hg-core'
 
-def _commitfiltered(repo, ctx, match, keepcommit):
+def _commitfiltered(repo, ctx, match, keepcommit, message=None, user=None,
+                    date=None):
     """Recommit ctx with changed files not in match. Return the new
     node identifier, or None if nothing changed.
     """
@@ -90,13 +91,20 @@
     if not files:
         repo.ui.status(_("note: keeping empty commit\n"))
 
+    if message is None:
+        message = ctx.description()
+    if not user:
+        user = ctx.user()
+    if not date:
+        date = ctx.date()
+
     new = context.memctx(repo,
                          parents=[base.node(), node.nullid],
-                         text=ctx.description(),
+                         text=message,
                          files=files,
                          filectxfn=filectxfn,
-                         user=ctx.user(),
-                         date=ctx.date(),
+                         user=user,
+                         date=date,
                          extra=ctx.extra())
     return repo.commitctx(new)
 
@@ -104,7 +112,7 @@
     [('', 'keep', None, _('allow an empty commit after uncommiting')),
      ('', 'allow-dirty-working-copy', False,
     _('allow uncommit with outstanding changes'))
-    ] + commands.walkopts,
+    ] + commands.walkopts + commands.commitopts + commands.commitopts2,
     _('[OPTION]... [FILE]...'),
     helpcategory=command.CATEGORY_CHANGE_MANAGEMENT)
 def uncommit(ui, repo, *pats, **opts):
@@ -162,13 +170,19 @@
                                   % scmutil.getuipathfn(repo)(f), hint=hint)
 
         with repo.transaction('uncommit'):
+            if not (opts[b'message'] or opts[b'logfile']):
+                opts[b'message'] = old.description()
+            message = cmdutil.logmessage(ui, pycompat.byteskwargs(opts))
+
             keepcommit = pats
             if not keepcommit:
                 if opts.get('keep') is not None:
                     keepcommit = opts.get('keep')
                 else:
                     keepcommit = ui.configbool('experimental', 'uncommit.keep')
-            newid = _commitfiltered(repo, old, match, keepcommit)
+            newid = _commitfiltered(repo, old, match, keepcommit,
+                                    message=message, user=opts.get(b'user'),
+                                    date=opts.get(b'date'))
             if newid is None:
                 ui.status(_("nothing to uncommit\n"))
                 return 1
--- a/tests/test-uncommit.t	Fri Jun 14 17:50:04 2019 +0100
+++ b/tests/test-uncommit.t	Sat Sep 07 13:44:29 2019 -0400
@@ -38,6 +38,10 @@
       --allow-dirty-working-copy allow uncommit with outstanding changes
    -I --include PATTERN [+]      include names matching the given patterns
    -X --exclude PATTERN [+]      exclude names matching the given patterns
+   -m --message TEXT             use text as commit message
+   -l --logfile FILE             read commit message from file
+   -d --date DATE                record the specified date as commit date
+   -u --user USER                record the specified user as committer
   
   (some details hidden, use --verbose to show complete help)
 
@@ -531,9 +535,18 @@
   $ mkdir dir
   $ echo 1 > dir/file.txt
   $ hg ci -Aqm 'add file in directory'
-  $ hg uncommit dir
+  $ hg uncommit dir -m 'uncommit with message' -u 'different user' \
+  >                 -d 'Jun 30 12:12:12 1980 +0000'
   $ hg status
   A dir/file.txt
+  $ hg log -r .
+  changeset:   8:b4dd26dc42e0
+  tag:         tip
+  parent:      6:2278a4c24330
+  user:        different user
+  date:        Mon Jun 30 12:12:12 1980 +0000
+  summary:     uncommit with message
+  
 
 `uncommit <dir>` and `cd <dir> && uncommit .` behave the same...