uncommit: add support for --message and --logfile
authorPierre-Yves David <pierre-yves.david@octobus.net>
Tue, 11 Jul 2017 11:58:07 +0200
changeset 2727 f7d44441dfd3
parent 2726 70004f0847a2
child 2728 3c371aa16cb9
uncommit: add support for --message and --logfile This is long overdue.
hgext3rd/evolve/evocommands.py
tests/test-tutorial.t
tests/test-uncommit.t
--- a/hgext3rd/evolve/evocommands.py	Tue Jul 11 11:12:23 2017 +0200
+++ b/hgext3rd/evolve/evocommands.py	Tue Jul 11 11:58:07 2017 +0200
@@ -116,7 +116,7 @@
         touched.update(files)
     return touched
 
-def _commitfiltered(repo, ctx, match, target=None):
+def _commitfiltered(repo, ctx, match, target=None, message=None):
     """Recommit ctx with changed files not in match. Return the new
     node identifier, or None if nothing changed.
     """
@@ -156,9 +156,11 @@
                                   copied=copied.get(path))
         return mctx
 
+    if message is None:
+        message = ctx.description()
     new = context.memctx(repo,
                          parents=[base.node(), node.nullid],
-                         text=ctx.description(),
+                         text=message,
                          files=files,
                          filectxfn=filectxfn,
                          user=ctx.user(),
@@ -216,7 +218,7 @@
     '^uncommit',
     [('a', 'all', None, _('uncommit all changes when no arguments given')),
      ('r', 'rev', '', _('revert commit content to REV instead')),
-     ] + commands.walkopts,
+     ] + commands.walkopts + commitopts,
     _('[OPTION]... [NAME]'))
 def uncommit(ui, repo, *pats, **opts):
     """move changes from parent revision to working directory
@@ -272,7 +274,11 @@
         includeorexclude = opts.get('include') or opts.get('exclude')
         if (pats or includeorexclude or opts.get('all')):
             match = scmutil.match(old, pats, opts)
-            newid = _commitfiltered(repo, old, match, target=rev)
+            if not (opts['message'] or opts['logfile']):
+                opts['message'] = old.description()
+            message = cmdutil.logmessage(ui, opts)
+            newid = _commitfiltered(repo, old, match, target=rev,
+                                    message=message)
         if newid is None:
             raise error.Abort(_('nothing to uncommit'),
                               hint=_("use --all to uncommit all files"))
--- a/tests/test-tutorial.t	Tue Jul 11 11:12:23 2017 +0200
+++ b/tests/test-tutorial.t	Tue Jul 11 11:58:07 2017 +0200
@@ -461,6 +461,8 @@
    -r --rev VALUE           revert commit content to REV instead
    -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
   
   (some details hidden, use --verbose to show complete help)
 
--- a/tests/test-uncommit.t	Tue Jul 11 11:12:23 2017 +0200
+++ b/tests/test-uncommit.t	Tue Jul 11 11:58:07 2017 +0200
@@ -362,3 +362,25 @@
   $ hg cat b --rev .
   b
   b
+
+Test message update
+
+  $ hg log -r .
+  changeset:   12:912ed871207c
+  branch:      bar
+  tag:         tip
+  parent:      7:4f1c269eab68
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     touncommit
+  
+  $ hg uncommit -m 'to-uncommit' d
+  $ hg log -r .
+  changeset:   13:dfe358c8c130
+  branch:      bar
+  tag:         tip
+  parent:      7:4f1c269eab68
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     to-uncommit
+