Rev 9: Finish up the archive_branch() functionality. in http://bzr.arbash-meinel.com/plugins/raf

John Arbash Meinel john at arbash-meinel.com
Wed Jan 14 23:18:04 GMT 2009


At http://bzr.arbash-meinel.com/plugins/raf

------------------------------------------------------------
revno: 9
revision-id: john at arbash-meinel.com-20090114231747-tlxkuqt8qsvl25ro
parent: john at arbash-meinel.com-20090114221405-m8dhhjec4faew4b1
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: raf
timestamp: Wed 2009-01-14 17:17:47 -0600
message:
  Finish up the archive_branch() functionality.
  
  This includes a couple blackbox tests.
  For now, we only support archiving when the branch is in the same filesystem.
-------------- next part --------------
=== modified file '__init__.py'
--- a/__init__.py	2009-01-14 22:14:05 +0000
+++ b/__init__.py	2009-01-14 23:17:47 +0000
@@ -93,6 +93,10 @@
                 raise errors.BzrCommandError('There are %d unmerged revisions'
                     ' in\n  %s\nthat are not in\n  %s.'
                     % (len(unmerged_revs), b, target_b))
+        archive_branch.archive_branch(b, archive_trans, archived_url)
+        if wt is not None:
+            # We have a checkout, so we need to point it to the new location
+            wt.branch.set_bound_location(archived_url)
 
 commands.register_command(cmd_archive_branch)
 

=== modified file 'archive_branch.py'
--- a/archive_branch.py	2009-01-14 22:09:38 +0000
+++ b/archive_branch.py	2009-01-14 23:17:47 +0000
@@ -107,3 +107,14 @@
 
 def archive_branch(b, archive_trans, archived_url):
     """Move this branch into the archive."""
+    relative_url = urlutils.relative_url(b.base, archived_url)
+    if relative_url == archived_url:
+        # The URLs do not share a prefix. Consider handling this case via a
+        # "bzr branch original archived", "rm -rf original"
+        raise errors.BzrCommandError('The branch being archived must be'
+            ' on the same filesystem as the archive.'
+            '\n  %s\nis not in the same place as\n  %s'
+            % (b.base, archived_url))
+        assert False, "The branch source must share part of the target."
+
+    b.bzrdir.root_transport.rename('.', relative_url)

=== modified file 'test_archive_branch.py'
--- a/test_archive_branch.py	2009-01-14 22:09:38 +0000
+++ b/test_archive_branch.py	2009-01-14 23:17:47 +0000
@@ -19,8 +19,10 @@
 import os
 
 from bzrlib import (
+    branch,
     errors,
     tests,
+    transport,
     )
 from bzrlib.plugins.raf import (
     archive_branch,
@@ -154,3 +156,22 @@
             self.assertEqual(b.base, target_b.base)
         finally:
             plugin_raf.DEFAULT_TARGET_BRANCH = orig_default
+
+
+class TestArchiveBranch(tests.TestCaseWithTransport):
+
+    def setUp(self):
+        super(TestArchiveBranch, self).setUp()
+        self.build_tree(['archive/'])
+        self.archive_url = self.get_url('archive')
+
+    def test_archive_simple(self):
+        b = self.make_branch('a_branch')
+        archived_url = self.archive_url + '/a_branch-01'
+        archive_trans = transport.get_transport(self.archive_url)
+        archive_branch.archive_branch(b, archive_trans, archived_url)
+
+        self.failIfExists('a_branch')
+        self.failUnlessExists('archive/a_branch-01')
+        # We should be able to open the final branch
+        branch.Branch.open('archive/a_branch-01')

=== modified file 'test_blackbox_archive_branch.py'
--- a/test_blackbox_archive_branch.py	2009-01-14 22:09:38 +0000
+++ b/test_blackbox_archive_branch.py	2009-01-14 23:17:47 +0000
@@ -17,6 +17,8 @@
 """Tests for the UI commands provided by the RAF plugin."""
 
 from bzrlib import (
+    branch,
+    errors,
     tests,
     )
 from bzrlib.plugins import raf
@@ -50,9 +52,32 @@
         extra_bzrdir = self.target_branch.bzrdir.sprout('feature')
         extra_tree = extra_bzrdir.open_workingtree()
         extra_tree.commit('unmerged', rev_id='unmerged-rev')
+        # We don't need to hold them open
+        del extra_tree, extra_bzrdir
 
         # It should fail because there are extra revisions
         self.run_bzr_error(['There are 1 unmerged revisions'],
                            'archive-branch feature')
+        # feature should still be there
+        branch.Branch.open('feature')
+
         # Unless we tell it not to check
         self.run_bzr('archive-branch feature --no-check')
+        # feature should not be there anymore
+        self.assertRaises(errors.NotBranchError, branch.Branch.open, 'feature')
+        # And should be in the new location
+        branch.Branch.open('archive/feature-01')
+
+    def test_archive_checkout(self):
+        feature_branch = self.target_branch.bzrdir.sprout('feature').open_branch()
+        checkout = feature_branch.create_checkout('checkout')
+        # If we run 'archive-branch' in a checkout, the feature branch should
+        # be archived, and the checkout should be pointed to the new location
+        self.run_bzr('archive-branch', working_dir='checkout')
+
+        self.assertRaises(errors.NotBranchError, branch.Branch.open, 'feature')
+        archived_b = branch.Branch.open('archive/feature-01')
+        self.assertEqual(archived_b.base.rstrip('/'),
+                         checkout.branch.get_bound_location())
+        master = checkout.branch.get_master_branch()
+        self.assertEqual(archived_b.base, master.base)



More information about the bazaar-commits mailing list