changeset 13661:ee349e228835

rebase: add -m/--message to rebase --collapse (issue2389) When collapsing changesets with rebase, you get a chance to edit the commit message manually, but there is no way to pass this message from the command line. This patch adds a `--message` (with short form `-m`) and `--logfile` (with short form `-m`) options to the rebase command. These options suppresses the generation of the default commit message, and instead use the message provided in the option (in case of `-m`) or in the file it points to (in case of `-l`). If you use this option without the `--collapse` option, it will raise an error. Options documentation edited by Patrick Mezard <pmezard@gmail.com>
author Radomir Dopieralski <sheep@stxnext.pl>
date Tue, 15 Mar 2011 18:33:36 +0100
parents a56c1b2bff18
children 80d6e1f63ed9
files hgext/rebase.py tests/test-rebase-collapse.t
diffstat 2 files changed, 51 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/rebase.py	Tue Mar 15 17:50:02 2011 -0400
+++ b/hgext/rebase.py	Tue Mar 15 18:33:36 2011 +0100
@@ -90,6 +90,7 @@
         contf = opts.get('continue')
         abortf = opts.get('abort')
         collapsef = opts.get('collapse', False)
+        collapsemsg = cmdutil.logmessage(opts)
         extrafn = opts.get('extrafn') # internal, used by e.g. hgsubversion
         keepf = opts.get('keep', False)
         keepbranchesf = opts.get('keepbranches', False)
@@ -98,6 +99,10 @@
         # other extensions
         keepopen = opts.get('keepopen', False)
 
+        if collapsemsg and not collapsef:
+            raise util.Abort(
+                _('message can only be specified with collapse'))
+
         if contf or abortf:
             if contf and abortf:
                 raise util.Abort(_('cannot use both abort and continue'))
@@ -189,11 +194,14 @@
         if collapsef and not keepopen:
             p1, p2 = defineparents(repo, min(state), target,
                                                         state, targetancestors)
-            commitmsg = 'Collapsed revision'
-            for rebased in state:
-                if rebased not in skipped and state[rebased] != nullmerge:
-                    commitmsg += '\n* %s' % repo[rebased].description()
-            commitmsg = ui.edit(commitmsg, repo.ui.username())
+            if collapsemsg:
+                commitmsg = collapsemsg
+            else:
+                commitmsg = 'Collapsed revision'
+                for rebased in state:
+                    if rebased not in skipped and state[rebased] != nullmerge:
+                        commitmsg += '\n* %s' % repo[rebased].description()
+                commitmsg = ui.edit(commitmsg, repo.ui.username())
             newrev = concludenode(repo, rev, p1, external, commitmsg=commitmsg,
                                   extrafn=extrafn)
 
@@ -564,6 +572,10 @@
         ('d', 'dest', '',
          _('rebase onto the specified changeset'), _('REV')),
         ('', 'collapse', False, _('collapse the rebased changesets')),
+        ('m', 'message', '',
+         _('use text as collapse commit message'), _('TEXT')),
+        ('l', 'logfile', '',
+         _('read collapse commit message from file'), _('FILE')),
         ('', 'keep', False, _('keep original changesets')),
         ('', 'keepbranches', False, _('keep original branch names')),
         ('', 'detach', False, _('force detaching of source from its original '
--- a/tests/test-rebase-collapse.t	Tue Mar 15 17:50:02 2011 -0400
+++ b/tests/test-rebase-collapse.t	Tue Mar 15 18:33:36 2011 +0100
@@ -137,6 +137,40 @@
 
   $ cd ..
 
+Rebasing G onto H with custom message:
+
+  $ hg clone -q -u . a a3
+  $ cd a3
+
+  $ hg rebase --base 6 -m 'custom message'
+  abort: message can only be specified with collapse
+  [255]
+
+  $ hg rebase --base 6 --collapse -m 'custom message'
+  saved backup bundle to $TESTTMP/a3/.hg/strip-backup/*-backup.hg (glob)
+
+  $ hg tglog
+  @  6: 'custom message'
+  |
+  o  5: 'H'
+  |
+  o  4: 'F'
+  |
+  | o  3: 'D'
+  | |
+  | o  2: 'C'
+  | |
+  | o  1: 'B'
+  |/
+  o  0: 'A'
+  
+  $ hg manifest
+  A
+  E
+  F
+  H
+
+  $ cd ..
 
 Create repo b: