D6827: uncommit: add support to modify the commit message and date

mharbison72 (Matt Harbison) phabricator at mercurial-scm.org
Sun Sep 8 03:31:40 UTC 2019


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

REVISION SUMMARY
  Currently, the evolve extension's version of this command supports it.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  hgext/uncommit.py
  tests/test-uncommit.t

CHANGE DETAILS

diff --git a/tests/test-uncommit.t b/tests/test-uncommit.t
--- a/tests/test-uncommit.t
+++ b/tests/test-uncommit.t
@@ -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...
 
diff --git a/hgext/uncommit.py b/hgext/uncommit.py
--- a/hgext/uncommit.py
+++ b/hgext/uncommit.py
@@ -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



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


More information about the Mercurial-devel mailing list