graft: add user, date, and tool options
authorMatt Mackall <mpm@selenic.com>
Wed, 12 Oct 2011 18:46:23 -0500
changeset 15240 bfb93963bb39
parent 15239 f5d9d0d0f588
child 15241 e4d135632f6d
graft: add user, date, and tool options
mercurial/commands.py
tests/test-debugcomplete.t
--- a/mercurial/commands.py	Wed Oct 12 18:46:03 2011 -0500
+++ b/mercurial/commands.py	Wed Oct 12 18:46:23 2011 -0500
@@ -2447,8 +2447,14 @@
     repo[None].forget(forget)
     return errs
 
-@command('graft',
-    [('e', 'edit', False, _('invoke editor on commit messages'))],
+@command(
+    'graft',
+    [('e', 'edit', False, _('invoke editor on commit messages')),
+    ('D', 'currentdate', False,
+     _('record the current date as commit date')),
+    ('U', 'currentuser', False,
+     _('record the current user as committer'), _('DATE'))]
+    + commitopts2 + mergetoolopts,
     _('[OPTION]... REVISION...'))
 def graft(ui, repo, rev, *revs, **opts):
     '''copy changes from other branches onto the current branch
@@ -2466,6 +2472,11 @@
 
     cmdutil.bailifchanged(repo)
 
+    if not opts.get('user') and opts.get('currentuser'):
+        opts['user'] = ui.username()
+    if not opts.get('date') and opts.get('currentdate'):
+        opts['date'] = "%d %d" % util.makedate()
+
     editor = None
     if opts.get('edit'):
         editor = cmdutil.commitforceeditor
@@ -2502,8 +2513,13 @@
         current = repo['.']
         ui.debug('grafting revision %s', ctx.rev())
         # perform the graft merge with p1(rev) as 'ancestor'
-        stats = mergemod.update(repo, ctx.node(), True, True, False,
-                             ctx.p1().node())
+        try:
+            # ui.forcemerge is an internal variable, do not document
+            repo.ui.setconfig('ui', 'forcemerge', opts.get('tool', ''))
+            stats = mergemod.update(repo, ctx.node(), True, True, False,
+                                    ctx.p1().node())
+        finally:
+            ui.setconfig('ui', 'forcemerge', '')
         # drop the second merge parent
         repo.dirstate.setparents(current.node(), nullid)
         repo.dirstate.write()
@@ -2515,8 +2531,14 @@
                              hint=_('use hg resolve and hg graft --continue'))
         # commit
         extra = {'source': ctx.hex()}
-        repo.commit(text=ctx.description(), user=ctx.user(),
-                    date=ctx.date(), extra=extra, editor=editor)
+        user = ctx.user()
+        if opts.get('user'):
+            user = opts['user']
+        date = ctx.date()
+        if opts.get('date'):
+            date = opts['date']
+        repo.commit(text=ctx.description(), user=user,
+                    date=date, extra=extra, editor=editor)
 
     return 0
 
--- a/tests/test-debugcomplete.t	Wed Oct 12 18:46:03 2011 -0500
+++ b/tests/test-debugcomplete.t	Wed Oct 12 18:46:23 2011 -0500
@@ -243,7 +243,7 @@
   debugsub: rev
   debugwalk: include, exclude
   debugwireargs: three, four, five, ssh, remotecmd, insecure
-  graft: edit
+  graft: edit, currentdate, currentuser, date, user, tool
   grep: print0, all, text, follow, ignore-case, files-with-matches, line-number, rev, user, date, include, exclude
   heads: rev, topo, active, closed, style, template
   help: extension, command