Rev 4707: (andrew) Fix traceback when doing 'bzr push --use-existing-dir' into in file:///home/pqm/archives/thelove/bzr/2.0/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Wed Dec 2 02:43:10 GMT 2009


At file:///home/pqm/archives/thelove/bzr/2.0/

------------------------------------------------------------
revno: 4707 [merge]
revision-id: pqm at pqm.ubuntu.com-20091202024309-7eblqn2luitz3tzs
parent: pqm at pqm.ubuntu.com-20091120025352-c0rtr4c3fgx1d876
parent: andrew.bennetts at canonical.com-20091202013035-2n64u5z7bequt7ye
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: 2.0
timestamp: Wed 2009-12-02 02:43:09 +0000
message:
  (andrew) Fix traceback when doing 'bzr push --use-existing-dir' into
  	a dir with an invalid .bzr directory. (#423563)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
  bzrlib/push.py                 push.py-20080606021927-5fe39050e8xne9un-1
  bzrlib/tests/blackbox/test_push.py test_push.py-20060329002750-929af230d5d22663
=== modified file 'NEWS'
--- a/NEWS	2009-11-20 01:39:36 +0000
+++ b/NEWS	2009-12-02 01:30:35 +0000
@@ -20,6 +20,10 @@
 Bug Fixes
 *********
 
+* ``bzr push --use-existing-dir`` no longer crashes if the directory
+  exists but contains an invalid ``.bzr`` directory.
+  (Andrew Bennetts, #423563)
+
 * Content filters are now applied correctly after pull, merge and switch.
   (Ian Clatworthy, #385879)
 

=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2009-08-19 18:04:49 +0000
+++ b/bzrlib/branch.py	2009-11-23 07:10:47 +0000
@@ -1284,16 +1284,9 @@
         # clone call. Or something. 20090224 RBC/spiv.
         if revision_id is None:
             revision_id = self.last_revision()
-        try:
-            dir_to = self.bzrdir.clone_on_transport(to_transport,
-                revision_id=revision_id, stacked_on=stacked_on,
-                create_prefix=create_prefix, use_existing_dir=use_existing_dir)
-        except errors.FileExists:
-            if not use_existing_dir:
-                raise
-        except errors.NoSuchFile:
-            if not create_prefix:
-                raise
+        dir_to = self.bzrdir.clone_on_transport(to_transport,
+            revision_id=revision_id, stacked_on=stacked_on,
+            create_prefix=create_prefix, use_existing_dir=use_existing_dir)
         return dir_to.open_branch()
 
     def create_checkout(self, to_location, revision_id=None,

=== modified file 'bzrlib/push.py'
--- a/bzrlib/push.py	2009-07-18 21:09:00 +0000
+++ b/bzrlib/push.py	2009-11-25 06:10:00 +0000
@@ -90,12 +90,19 @@
             br_to = br_from.create_clone_on_transport(to_transport,
                 revision_id=revision_id, stacked_on=stacked_on,
                 create_prefix=create_prefix, use_existing_dir=use_existing_dir)
-        except errors.FileExists:
+        except errors.FileExists, err:
+            if err.path.endswith('/.bzr'):
+                raise errors.BzrCommandError(
+                    "Target directory %s already contains a .bzr directory, "
+                    "but it is not valid." % (location,))
             if not use_existing_dir:
                 raise errors.BzrCommandError("Target directory %s"
-                     " already exists, but does not have a valid .bzr"
+                     " already exists, but does not have a .bzr"
                      " directory. Supply --use-existing-dir to push"
                      " there anyway." % location)
+            # This shouldn't occur, but if it does the FileExists error will be
+            # more informative than an UnboundLocalError for br_to.
+            raise
         except errors.NoSuchFile:
             if not create_prefix:
                 raise errors.BzrCommandError("Parent directory of %s"

=== modified file 'bzrlib/tests/blackbox/test_push.py'
--- a/bzrlib/tests/blackbox/test_push.py	2009-08-20 04:09:58 +0000
+++ b/bzrlib/tests/blackbox/test_push.py	2009-11-25 06:10:00 +0000
@@ -319,6 +319,17 @@
         # The push should have created target/a
         self.failUnlessExists('target/a')
 
+    def test_push_use_existing_into_empty_bzrdir(self):
+        """'bzr push --use-existing-dir' into a dir with an empty .bzr dir
+        fails.
+        """
+        tree = self.create_simple_tree()
+        self.build_tree(['target/', 'target/.bzr/'])
+        self.run_bzr_error(
+            ['Target directory ../target already contains a .bzr directory, '
+             'but it is not valid.'],
+            'push ../target --use-existing-dir', working_dir='tree')
+
     def test_push_onto_repo(self):
         """We should be able to 'bzr push' into an existing bzrdir."""
         tree = self.create_simple_tree()




More information about the bazaar-commits mailing list