Rev 2371: (John Arbash Meinel) Fix bug #93854, make 'bzr checkout' create branches in the same format as the source. in http://bzr.arbash-meinel.com/branches/bzr/0.15-dev/checkout_uses_branch_format_93854

John Arbash Meinel john at arbash-meinel.com
Thu Mar 22 19:42:33 GMT 2007


At http://bzr.arbash-meinel.com/branches/bzr/0.15-dev/checkout_uses_branch_format_93854

------------------------------------------------------------
revno: 2371
revision-id: john at arbash-meinel.com-20070322194159-fxl08l4zah9df24r
parent: pqm at pqm.ubuntu.com-20070321071219-55447700ec71371f
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: checkout_uses_branch_format_93854
timestamp: Thu 2007-03-22 14:41:59 -0500
message:
  (John Arbash Meinel) Fix bug #93854, make 'bzr checkout' create branches in the same format as the source.
added:
  bzrlib/tests/branch_implementations/test_create_checkout.py test_create_checkout-20070322193723-n2wkp1g03r0404di-1
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
  bzrlib/tests/branch_implementations/__init__.py __init__.py-20060123013057-b12a52c3f361daf4
  bzrlib/tests/test_branch.py    test_branch.py-20060116013032-97819aa07b8ab3b5
-------------- next part --------------
=== added file 'bzrlib/tests/branch_implementations/test_create_checkout.py'
--- a/bzrlib/tests/branch_implementations/test_create_checkout.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/branch_implementations/test_create_checkout.py	2007-03-22 19:41:59 +0000
@@ -0,0 +1,66 @@
+# Copyright (C) 2007 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+"""Tests for the Branch.create_checkout"""
+
+from bzrlib import (
+    branch,
+    )
+from bzrlib.tests.branch_implementations.test_branch import TestCaseWithBranch
+
+
+class TestCreateCheckout(TestCaseWithBranch):
+
+    def test_checkout_format(self):
+        """Make sure the new checkout uses the same branch format."""
+        a_branch = self.make_branch('branch')
+        tree = a_branch.create_checkout('checkout')
+        if self.branch_format in branch._legacy_formats:
+            # Legacy formats create checkouts with the default format.
+            # Only newer formats create identical checkouts.
+            expected_format = branch.BranchFormat.get_default_format()
+        else:
+            expected_format = a_branch._format
+        self.assertEqual(expected_format.get_format_string(),
+                         tree.branch._format.get_format_string())
+
+    def test_create_revision_checkout(self):
+        """Test that we can create a checkout from an earlier revision."""
+        tree1 = self.make_branch_and_tree('base')
+        self.build_tree(['base/a'])
+        tree1.add(['a'], ['a-id'])
+        tree1.commit('first', rev_id='rev-1')
+        self.build_tree(['base/b'])
+        tree1.add(['b'], ['b-id'])
+        tree1.commit('second', rev_id='rev-2')
+
+        tree2 = tree1.branch.create_checkout('checkout', revision_id='rev-1')
+        self.assertEqual('rev-1', tree2.last_revision())
+        self.failUnlessExists('checkout/a')
+        self.failIfExists('checkout/b')
+
+    def test_create_lightweight_checkout(self):
+        """We should be able to make a lightweight checkout."""
+        tree1 = self.make_branch_and_tree('base')
+        tree2 = tree1.branch.create_checkout('checkout', lightweight=True)
+        self.assertNotEqual(tree1.basedir, tree2.basedir)
+        self.assertEqual(tree1.branch.base, tree2.branch.base)
+
+    def test_create_checkout_exists(self):
+        """We shouldn't fail if the directory already exists."""
+        tree1 = self.make_branch_and_tree('base')
+        self.build_tree('checkout')
+        tree2 = tree1.branch.create_checkout('checkout', lightweight=True)

=== modified file 'NEWS'
--- a/NEWS	2007-03-21 04:28:02 +0000
+++ b/NEWS	2007-03-22 19:41:59 +0000
@@ -22,6 +22,9 @@
     * ``bzr status FILENAME`` failed on Windows because of an uncommon
       errno. (``ERROR_DIRECTORY == 267 != ENOTDIR``).
       (Wouter van Heyst, John Arbash Meinel, #90819)
+
+    * ``bzr checkout source`` should create a local branch in the same
+      format as source. (John Arbash Meinel, #93854)
  
 
 bzr 0.15rc2  2007-03-14

=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2007-03-13 01:00:34 +0000
+++ b/bzrlib/branch.py	2007-03-22 19:41:59 +0000
@@ -690,7 +690,9 @@
             format.repository_format = weaverepo.RepositoryFormat7()
         else:
             format = self.repository.bzrdir.checkout_metadir()
-            format.branch_format = self._format
+            # TODO: jam 20070322 Why is 'repository_format' public, but
+            #       _workingtree_format and _branch_format private?
+            format._branch_format = self._format
         return format
 
     def create_checkout(self, to_location, revision_id=None,

=== modified file 'bzrlib/tests/branch_implementations/__init__.py'
--- a/bzrlib/tests/branch_implementations/__init__.py	2007-02-15 01:23:29 +0000
+++ b/bzrlib/tests/branch_implementations/__init__.py	2007-03-22 19:41:59 +0000
@@ -42,6 +42,7 @@
         'bzrlib.tests.branch_implementations.test_bound_sftp',
         'bzrlib.tests.branch_implementations.test_branch',
         'bzrlib.tests.branch_implementations.test_break_lock',
+        'bzrlib.tests.branch_implementations.test_create_checkout',
         'bzrlib.tests.branch_implementations.test_commit',
         'bzrlib.tests.branch_implementations.test_hooks',
         'bzrlib.tests.branch_implementations.test_http',

=== modified file 'bzrlib/tests/test_branch.py'
--- a/bzrlib/tests/test_branch.py	2007-03-14 03:42:40 +0000
+++ b/bzrlib/tests/test_branch.py	2007-03-22 19:41:59 +0000
@@ -175,13 +175,6 @@
         BranchFormat.unregister_format(format)
         self.make_branch_and_tree('bar')
 
-    def test_checkout_format(self):
-        branch = self.make_repository('repository', shared=True)
-        branch = self.make_branch('repository/branch',
-            format='metaweave')
-        tree = branch.create_checkout('checkout')
-        self.assertIs(tree.branch.__class__, _mod_branch.BzrBranch5)
-
 
 class TestBranch6(TestCaseWithTransport):
 



More information about the bazaar-commits mailing list