Rev 4500: (bialix) Add --use-existing-dir to branch in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Wed Jul 1 18:30:17 BST 2009


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 4500 [merge]
revision-id: pqm at pqm.ubuntu.com-20090701173004-xmeu77pfroy9iklo
parent: pqm at pqm.ubuntu.com-20090701155456-4qodruyp94l2p4ag
parent: v.ladeuil+lp at free.fr-20090701153101-03xc0onyeh0cuk96
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2009-07-01 18:30:04 +0100
message:
  (bialix) Add --use-existing-dir to branch
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
  bzrlib/tests/blackbox/test_branch.py test_branch.py-20060524161337-noms9gmcwqqrfi8y-1
=== modified file 'NEWS'
--- a/NEWS	2009-07-01 07:26:30 +0000
+++ b/NEWS	2009-07-01 15:31:01 +0000
@@ -55,6 +55,10 @@
 * ``Branch.set_append_revisions_only`` now works with branches on a smart
   server. (Andrew Bennetts, #365865)
 
+* By default, ``bzr branch`` will fail if the target directory exists, but
+  does not already have a control directory.  The flag ``--use-existing-dir``
+  will allow operation to proceed.  (Alexander Belchenko, #307554)
+
 * ``bzr ls DIR --from-root`` now shows only things in DIR, not everything.
   (Ian Clatworthy)
 

=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2009-07-01 07:29:00 +0000
+++ b/bzrlib/builtins.py	2009-07-01 15:31:01 +0000
@@ -1188,11 +1188,17 @@
                 'branch for all operations.'),
         Option('standalone',
                help='Do not use a shared repository, even if available.'),
+        Option('use-existing-dir',
+               help='By default branch will fail if the target'
+                    ' directory exists, but does not already'
+                    ' have a control directory.  This flag will'
+                    ' allow branch to proceed.'),
         ]
     aliases = ['get', 'clone']
 
     def run(self, from_location, to_location=None, revision=None,
-            hardlink=False, stacked=False, standalone=False, no_tree=False):
+            hardlink=False, stacked=False, standalone=False, no_tree=False,
+            use_existing_dir=False):
         from bzrlib.tag import _merge_tags_if_possible
 
         accelerator_tree, br_from = bzrdir.BzrDir.open_tree_or_branch(
@@ -1216,8 +1222,16 @@
             try:
                 to_transport.mkdir('.')
             except errors.FileExists:
-                raise errors.BzrCommandError('Target directory "%s" already'
-                                             ' exists.' % to_location)
+                if not use_existing_dir:
+                    raise errors.BzrCommandError('Target directory "%s" '
+                        'already exists.' % to_location)
+                else:
+                    try:
+                        bzrdir.BzrDir.open_from_transport(to_transport)
+                    except errors.NotBranchError:
+                        pass
+                    else:
+                        raise errors.AlreadyBranchError(to_location)
             except errors.NoSuchFile:
                 raise errors.BzrCommandError('Parent of "%s" does not exist.'
                                              % to_location)

=== modified file 'bzrlib/tests/blackbox/test_branch.py'
--- a/bzrlib/tests/blackbox/test_branch.py	2009-06-18 05:02:54 +0000
+++ b/bzrlib/tests/blackbox/test_branch.py	2009-07-01 15:25:31 +0000
@@ -113,6 +113,27 @@
         self.failIfExists('target/hello')
         self.failIfExists('target/goodbye')
 
+    def test_branch_into_existing_dir(self):
+        self.example_branch('a')
+        # existing dir with similar files but no .bzr dir
+        self.build_tree_contents([('b/',)])
+        self.build_tree_contents([('b/hello', 'bar')])  # different content
+        self.build_tree_contents([('b/goodbye', 'baz')])# same content
+        # fails without --use-existing-dir
+        out,err = self.run_bzr('branch a b', retcode=3)
+        self.assertEqual('', out)
+        self.assertEqual('bzr: ERROR: Target directory "b" already exists.\n',
+            err)
+        # force operation
+        self.run_bzr('branch a b --use-existing-dir')
+        # check conflicts
+        self.failUnlessExists('b/hello.moved')
+        self.failIfExists('b/godbye.moved')
+        # we can't branch into branch
+        out,err = self.run_bzr('branch a b --use-existing-dir', retcode=3)
+        self.assertEqual('', out)
+        self.assertEqual('bzr: ERROR: Already a branch: "b".\n', err)
+
 
 class TestBranchStacked(ExternalBase):
     """Tests for branch --stacked"""




More information about the bazaar-commits mailing list