Rev 4578: (bialix) Allow 'bzr export' to export into an existing (but empty) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Thu Jul 30 15:24:11 BST 2009


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

------------------------------------------------------------
revno: 4578 [merge]
revision-id: pqm at pqm.ubuntu.com-20090730142406-wg8gmxpcjz4c1z00
parent: pqm at pqm.ubuntu.com-20090729225922-ct2n8v4ebyr46xwq
parent: bialix at ukr.net-20090729134655-cje82wzo7rex9pbt
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2009-07-30 15:24:06 +0100
message:
  (bialix) Allow 'bzr export' to export into an existing (but empty)
  	directory
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/export/dir_exporter.py  dir_exporter.py-20051114235828-b51397f56bc7b117
  bzrlib/tests/test_export.py    test_export.py-20090220201010-tpbxssdnezsvu9pk-1
=== modified file 'NEWS'
--- a/NEWS	2009-07-29 21:38:13 +0000
+++ b/NEWS	2009-07-30 14:24:06 +0000
@@ -70,6 +70,10 @@
   causes a redirection loop when bzr tries to read a URL as a bundle.
   (Andrew Bennetts, #400847)
   
+* Fixed export to existing directory: if directory is empty then export 
+  will succeed, otherwise it fails with error.
+  (Alexander Belchenko, #406174)
+
 * Fixed spurious "Source branch does not support stacking" warning when
   pushing. (Andrew Bennetts, #388908)
 

=== modified file 'bzrlib/export/dir_exporter.py'
--- a/bzrlib/export/dir_exporter.py	2009-07-23 16:30:49 +0000
+++ b/bzrlib/export/dir_exporter.py	2009-07-29 13:46:55 +0000
@@ -17,7 +17,7 @@
 """Export a Tree to a non-versioned directory.
 """
 
-
+import errno
 import os
 import StringIO
 
@@ -43,7 +43,15 @@
            left in a half-assed state.
     """
     mutter('export version %r', tree)
-    os.mkdir(dest)
+    try:
+        os.mkdir(dest)
+    except OSError, e:
+        if e.errno == errno.EEXIST:
+            # check if directory empty
+            if os.listdir(dest) != []:
+                raise errors.BzrError("Can't export tree to non-empty directory.")
+        else:
+            raise
     for dp, ie in _export_iter_entries(tree, subdir):
         fullpath = osutils.pathjoin(dest, dp)
         if ie.kind == "file":

=== modified file 'bzrlib/tests/test_export.py'
--- a/bzrlib/tests/test_export.py	2009-07-23 18:36:54 +0000
+++ b/bzrlib/tests/test_export.py	2009-07-29 13:46:55 +0000
@@ -18,6 +18,7 @@
 
 
 from bzrlib import (
+    errors,
     export,
     osutils,
     tests,
@@ -42,3 +43,22 @@
         wt.add(['link'])
         export.export(wt, 'target', format="dir")
         self.failUnlessExists('target/link')
+
+    def test_dir_export_to_existing_empty_dir_success(self):
+        self.build_tree(['source/', 'source/a', 'source/b/', 'source/b/c'])
+        wt = self.make_branch_and_tree('source')
+        wt.add(['a', 'b', 'b/c'])
+        wt.commit('1')
+        self.build_tree(['target/'])
+        export.export(wt, 'target', format="dir")
+        self.failUnlessExists('target/a')
+        self.failUnlessExists('target/b')
+        self.failUnlessExists('target/b/c')
+
+    def test_dir_export_to_existing_nonempty_dir_fail(self):
+        self.build_tree(['source/', 'source/a', 'source/b/', 'source/b/c'])
+        wt = self.make_branch_and_tree('source')
+        wt.add(['a', 'b', 'b/c'])
+        wt.commit('1')
+        self.build_tree(['target/', 'target/foo'])
+        self.assertRaises(errors.BzrError, export.export, wt, 'target', format="dir")




More information about the bazaar-commits mailing list