changeset 149:04800fda7af5

rebase: preserve local branch names. Note: this commit introduces a dependency on Mercurial 1.1.1 or later.
author Augie Fackler <durin42@gmail.com>
date Mon, 22 Dec 2008 21:20:10 -0600
parents 0c5f6420a8b5
children 58ae90a65f41
files README tests/test_utility_commands.py utility_commands.py
diffstat 3 files changed, 36 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/README
+++ b/README
@@ -12,7 +12,7 @@ Subversion.
 Installation
 ------------
 You need to have Subversion installed with the SWIG Python bindings from Subversion 1.5 or later.
-You need Mercurial 1.1 or later.
+You need Mercurial 1.1.1 or later.
 
 .. _mercurial: http://selenic.com/repo/hg
 .. _mercurial-stable: http://selenic.com/repo/hg-stable
--- a/tests/test_utility_commands.py
+++ b/tests/test_utility_commands.py
@@ -1,7 +1,10 @@
+import os
 import urllib # for url quoting
 
 from mercurial import ui
 from mercurial import hg
+from mercurial import revlog
+from mercurial import context
 
 import utility_commands
 import fetch_command
@@ -49,6 +52,32 @@ class UtilityTests(test_util.TestBase):
         expected = 'file://%s\n' % urllib.quote(self.repo_path)
         self.assertEqual(u.stream.getvalue(), expected)
 
+    def test_rebase(self):
+        self._load_fixture_and_fetch('two_revs.svndump')
+        parents = (self.repo[0].node(), revlog.nullid, )
+        def filectxfn(repo, memctx, path):
+            return context.memfilectx(path=path,
+                                      data='added',
+                                      islink=False,
+                                      isexec=False,
+                                      copied=False)
+        ctx = context.memctx(self.repo,
+                             parents,
+                             'automated test',
+                             ['added_bogus_file', 'other_added_file', ],
+                             filectxfn,
+                             'testy',
+                             '2008-12-21 16:32:00 -0500',
+                             {'branch': 'localbranch', })
+        self.repo.commitctx(ctx)
+        self.assertEqual(self.repo['tip'].branch(), 'localbranch')
+        beforerebasehash = self.repo['tip'].node()
+        hg.update(self.repo, 'tip')
+        utility_commands.rebase_commits(ui.ui(), self.repo, os.path.dirname(self.repo.path))
+        self.assertEqual(self.repo['tip'].branch(), 'localbranch')
+        self.assertEqual(self.repo['tip'].parents()[0].parents()[0], self.repo[0])
+        self.assertNotEqual(beforerebasehash, self.repo['tip'].node())
+
     def test_url_is_normalized(self):
         """Verify url gets normalized on initial clone.
         """
--- a/utility_commands.py
+++ b/utility_commands.py
@@ -86,6 +86,10 @@ def rebase_commits(ui, repo, hg_repo_pat
     rebase on top of the current top of Subversion work, you should probably run
     'hg svn pull' before running this.
     """
+    def extrafn(ctx, extra):
+        """defined here so we can add things easily.
+        """
+        extra['branch'] = ctx.branch()
     hge = hg_delta_editor.HgChangeReceiver(hg_repo_path,
                                            ui_=ui)
     svn_commit_hashes = dict(zip(hge.revmap.itervalues(),
@@ -115,7 +119,8 @@ def rebase_commits(ui, repo, hg_repo_pat
         return 0
     # TODO this is really hacky, there must be a more direct way
     return rebase.rebase(ui, repo, dest=node.hex(target_rev.node()),
-                         base=node.hex(repo.parents()[0].node()))
+                         base=node.hex(repo.parents()[0].node()),
+                         extrafn=extrafn)
 
 
 @util.register_subcommand('outgoing')