Merge lp:~bialix/bzr/bug-406174 into lp:~bzr/bzr/trunk-old

Proposed by Alexander Belchenko
Status: Merged
Approved by: John A Meinel
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~bialix/bzr/bug-406174
Merge into: lp:~bzr/bzr/trunk-old
Diff against target: 79 lines
To merge this branch: bzr merge lp:~bialix/bzr/bug-406174
Reviewer Review Type Date Requested Status
John A Meinel Approve
Review via email: mp+9426@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Alexander Belchenko (bialix) wrote :

This branch fixed export to existing directory: if directory is empty then export will succeed, otherwise it fails with error. See bug #406174 for details.

Revision history for this message
John A Meinel (jameinel) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Alexander Belchenko wrote:
> Alexander Belchenko has proposed merging lp:~bialix/bzr/bug-406174 into lp:bzr.
>
> Requested reviews:
> bzr-core (bzr-core)
>
> This branch fixed export to existing directory: if directory is empty then export will succeed, otherwise it fails with error. See bug #406174 for details.
>
>

 review approve
 merge approve

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkpwcEAACgkQJdeBCYSNAAOfGgCeJ24K38h1RY1FVydmAdLukKWw
RzQAoItgQjHfiebrvVKISAHjkRj6E2Xo
=0PJ4
-----END PGP SIGNATURE-----

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2009-07-29 21:38:13 +0000
3+++ NEWS 2009-07-30 02:35:21 +0000
4@@ -70,6 +70,10 @@
5 causes a redirection loop when bzr tries to read a URL as a bundle.
6 (Andrew Bennetts, #400847)
7
8+* Fixed export to existing directory: if directory is empty then export
9+ will succeed, otherwise it fails with error.
10+ (Alexander Belchenko, #406174)
11+
12 * Fixed spurious "Source branch does not support stacking" warning when
13 pushing. (Andrew Bennetts, #388908)
14
15
16=== modified file 'bzrlib/export/dir_exporter.py'
17--- bzrlib/export/dir_exporter.py 2009-07-23 16:30:49 +0000
18+++ bzrlib/export/dir_exporter.py 2009-07-30 02:35:21 +0000
19@@ -17,7 +17,7 @@
20 """Export a Tree to a non-versioned directory.
21 """
22
23-
24+import errno
25 import os
26 import StringIO
27
28@@ -43,7 +43,15 @@
29 left in a half-assed state.
30 """
31 mutter('export version %r', tree)
32- os.mkdir(dest)
33+ try:
34+ os.mkdir(dest)
35+ except OSError, e:
36+ if e.errno == errno.EEXIST:
37+ # check if directory empty
38+ if os.listdir(dest) != []:
39+ raise errors.BzrError("Can't export tree to non-empty directory.")
40+ else:
41+ raise
42 for dp, ie in _export_iter_entries(tree, subdir):
43 fullpath = osutils.pathjoin(dest, dp)
44 if ie.kind == "file":
45
46=== modified file 'bzrlib/tests/test_export.py'
47--- bzrlib/tests/test_export.py 2009-07-23 18:36:54 +0000
48+++ bzrlib/tests/test_export.py 2009-07-30 02:35:21 +0000
49@@ -18,6 +18,7 @@
50
51
52 from bzrlib import (
53+ errors,
54 export,
55 osutils,
56 tests,
57@@ -42,3 +43,22 @@
58 wt.add(['link'])
59 export.export(wt, 'target', format="dir")
60 self.failUnlessExists('target/link')
61+
62+ def test_dir_export_to_existing_empty_dir_success(self):
63+ self.build_tree(['source/', 'source/a', 'source/b/', 'source/b/c'])
64+ wt = self.make_branch_and_tree('source')
65+ wt.add(['a', 'b', 'b/c'])
66+ wt.commit('1')
67+ self.build_tree(['target/'])
68+ export.export(wt, 'target', format="dir")
69+ self.failUnlessExists('target/a')
70+ self.failUnlessExists('target/b')
71+ self.failUnlessExists('target/b/c')
72+
73+ def test_dir_export_to_existing_nonempty_dir_fail(self):
74+ self.build_tree(['source/', 'source/a', 'source/b/', 'source/b/c'])
75+ wt = self.make_branch_and_tree('source')
76+ wt.add(['a', 'b', 'b/c'])
77+ wt.commit('1')
78+ self.build_tree(['target/', 'target/foo'])
79+ self.assertRaises(errors.BzrError, export.export, wt, 'target', format="dir")