Rev 6453: (jelmer) Allow creating a checkout in a directory that already has a control in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/2.5/

Patch Queue Manager pqm at pqm.ubuntu.com
Thu Jan 19 19:18:48 UTC 2012


At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/2.5/

------------------------------------------------------------
revno: 6453 [merge]
revision-id: pqm at pqm.ubuntu.com-20120119191847-h2lx53l76ctzof8w
parent: pqm at pqm.ubuntu.com-20120119165139-rbj2syrqv2x4rwvq
parent: jelmer at samba.org-20120119185128-2se9vxb0exo9fdlr
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: 2.5
timestamp: Thu 2012-01-19 19:18:47 +0000
message:
  (jelmer) Allow creating a checkout in a directory that already has a control
   directory. (Jelmer Vernooij)
modified:
  bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
  bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
  bzrlib/errors.py               errors.py-20050309040759-20512168c4e14fbd
  bzrlib/push.py                 push.py-20080606021927-5fe39050e8xne9un-1
  bzrlib/tests/blackbox/test_checkout.py test_checkout.py-20060211231752-a5cde67cf70af854
  bzrlib/tests/per_controldir/test_controldir.py test_bzrdir.py-20060131065642-0ebeca5e30e30866
  bzrlib/tests/test_smart.py     test_smart.py-20061122024551-ol0l0o0oofsu9b3t-2
  doc/en/release-notes/bzr-2.5.txt bzr2.5.txt-20110708125756-587p0hpw7oke4h05-1
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2012-01-18 17:47:06 +0000
+++ b/bzrlib/branch.py	2012-01-18 20:35:41 +0000
@@ -1457,18 +1457,30 @@
         t = transport.get_transport(to_location)
         t.ensure_base()
         format = self._get_checkout_format(lightweight=lightweight)
+        try:
+            checkout = format.initialize_on_transport(t)
+        except errors.AlreadyControlDirError:
+            # It's fine if the control directory already exists,
+            # as long as there is no existing branch and working tree.
+            checkout = controldir.ControlDir.open_from_transport(t)
+            try:
+                checkout.open_branch()
+            except errors.NotBranchError:
+                pass
+            else:
+                raise errors.AlreadyControlDirError(t.base)
+
         if lightweight:
-            checkout = format.initialize_on_transport(t)
             from_branch = checkout.set_branch_reference(target_branch=self)
         else:
-            checkout_branch = controldir.ControlDir.create_branch_convenience(
-                to_location, force_new_tree=False, format=format)
-            checkout = checkout_branch.bzrdir
+            policy = checkout.determine_repository_policy()
+            repo = policy.acquire_repository()[0]
+            checkout_branch = checkout.create_branch()
             checkout_branch.bind(self)
             # pull up to the specified revision_id to set the initial
             # branch tip correctly, and seed it with history.
             checkout_branch.pull(self, stop_revision=revision_id)
-            from_branch=None
+            from_branch = None
         tree = checkout.create_workingtree(revision_id,
                                            from_branch=from_branch,
                                            accelerator_tree=accelerator_tree,

=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py	2012-01-18 17:46:57 +0000
+++ b/bzrlib/bzrdir.py	2012-01-18 20:27:41 +0000
@@ -1475,10 +1475,13 @@
         # mode from the root directory
         temp_control = lockable_files.LockableFiles(transport,
                             '', lockable_files.TransportLock)
-        temp_control._transport.mkdir('.bzr',
-                                      # FIXME: RBC 20060121 don't peek under
-                                      # the covers
-                                      mode=temp_control._dir_mode)
+        try:
+            temp_control._transport.mkdir('.bzr',
+                # FIXME: RBC 20060121 don't peek under
+                # the covers
+                mode=temp_control._dir_mode)
+        except errors.FileExists:
+            raise errors.AlreadyControlDirError(transport.base)
         if sys.platform == 'win32' and isinstance(transport, local.LocalTransport):
             win32utils.set_file_attr_hidden(transport._abspath('.bzr'))
         file_mode = temp_control._file_mode

=== modified file 'bzrlib/errors.py'
--- a/bzrlib/errors.py	2011-12-22 15:33:16 +0000
+++ b/bzrlib/errors.py	2012-01-18 20:27:41 +0000
@@ -700,6 +700,11 @@
        self.path = urlutils.unescape_for_display(branch.base, 'ascii')
 
 
+class AlreadyControlDirError(PathError):
+
+    _fmt = 'A control directory already exists: "%(path)s".'
+
+
 class AlreadyBranchError(PathError):
 
     _fmt = 'Already a branch: "%(path)s".'

=== modified file 'bzrlib/push.py'
--- a/bzrlib/push.py	2011-12-19 13:23:58 +0000
+++ b/bzrlib/push.py	2012-01-19 17:23:00 +0000
@@ -92,11 +92,11 @@
                 revision_id=revision_id, stacked_on=stacked_on,
                 create_prefix=create_prefix, use_existing_dir=use_existing_dir,
                 no_tree=no_tree)
+        except errors.AlreadyControlDirError, err:
+            raise errors.BzrCommandError(gettext(
+                "Target directory %s already contains a .bzr directory, "
+                "but it is not valid.") % (location,))
         except errors.FileExists, err:
-            if err.path.endswith('/.bzr'):
-                raise errors.BzrCommandError(gettext(
-                    "Target directory %s already contains a .bzr directory, "
-                    "but it is not valid.") % (location,))
             if not use_existing_dir:
                 raise errors.BzrCommandError(gettext("Target directory %s"
                      " already exists, but does not have a .bzr"

=== modified file 'bzrlib/tests/blackbox/test_checkout.py'
--- a/bzrlib/tests/blackbox/test_checkout.py	2012-01-05 13:02:31 +0000
+++ b/bzrlib/tests/blackbox/test_checkout.py	2012-01-18 20:35:41 +0000
@@ -76,6 +76,13 @@
         self.assertEqual(['1'], result.open_workingtree().get_parent_ids())
         self.assertPathDoesNotExist('checkout/added_in_2')
 
+    def test_checkout_into_empty_dir(self):
+        self.make_bzrdir('checkout')
+        out, err = self.run_bzr(['checkout', 'branch', 'checkout'])
+        result = bzrdir.BzrDir.open('checkout')
+        tree = result.open_workingtree()
+        branch = result.open_branch()
+
     def test_checkout_reconstitutes_working_trees(self):
         # doing a 'bzr checkout' in the directory of a branch with no tree
         # or a 'bzr checkout path' with path the name of a directory with

=== modified file 'bzrlib/tests/per_controldir/test_controldir.py'
--- a/bzrlib/tests/per_controldir/test_controldir.py	2012-01-18 17:47:06 +0000
+++ b/bzrlib/tests/per_controldir/test_controldir.py	2012-01-18 20:27:41 +0000
@@ -108,6 +108,17 @@
         self.assertRaises(errors.UninitializableFormat,
             self.bzrdir_format.initialize, t.base)
 
+    def test_multiple_initialization(self):
+        # loopback test to check the current format initializes to itself.
+        if not self.bzrdir_format.is_initializable():
+            # unsupported formats are not loopback testable
+            # because the default open will not open them and
+            # they may not be initializable.
+            raise TestNotApplicable("format is not initializable")
+        self.bzrdir_format.initialize('.')
+        self.assertRaises(errors.AlreadyControlDirError,
+            self.bzrdir_format.initialize, '.')
+
     def test_create_null_workingtree(self):
         dir = self.make_bzrdir('dir1')
         dir.create_repository()

=== modified file 'bzrlib/tests/test_smart.py'
--- a/bzrlib/tests/test_smart.py	2012-01-06 22:06:36 +0000
+++ b/bzrlib/tests/test_smart.py	2012-01-19 19:18:47 +0000
@@ -512,7 +512,7 @@
         backing = self.get_transport()
         request = smart_dir.SmartServerRequestInitializeBzrDir(backing)
         self.make_bzrdir('subdir')
-        self.assertRaises(errors.FileExists,
+        self.assertRaises(errors.AlreadyControlDirError,
             request.execute, 'subdir')
 
 

=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- a/doc/en/release-notes/bzr-2.5.txt	2012-01-19 16:51:39 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt	2012-01-19 19:18:47 +0000
@@ -32,6 +32,10 @@
 * ``bzr info`` now reports when there are present (but unused) colocated
   branches. (Jelmer Vernooij, #891646)
 
+* Checkouts can now be into target directories that already have
+  a control directory (but no branch or working tree).
+  (Jelmer Vernooij, #913980)
+
 * New HPSS call for ``BzrDir.get_branches``. (Jelmer Vernooij, #894460)
 
 Bug Fixes




More information about the bazaar-commits mailing list