Merge lp:~spiv/bzr/dir_to-423563 into lp:bzr/2.0

Proposed by Andrew Bennetts
Status: Merged
Approved by: Martin Pool
Approved revision: not available
Merged at revision: not available
Proposed branch: lp:~spiv/bzr/dir_to-423563
Merge into: lp:bzr/2.0
Diff against target: 86 lines (+27/-12)
4 files modified
NEWS (+4/-0)
bzrlib/branch.py (+3/-10)
bzrlib/push.py (+9/-2)
bzrlib/tests/blackbox/test_push.py (+11/-0)
To merge this branch: bzr merge lp:~spiv/bzr/dir_to-423563
Reviewer Review Type Date Requested Status
Martin Pool Approve
bzr-core Pending
Review via email: mp+15232@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Andrew Bennetts (spiv) wrote :

This fixes bug 423563, a traceback when doing push --use-existing-dir to a location that exists and contains a .bzr directory that is not actually a valid BzrDir. This patch will cause a simple error instead: "Target directory FOO already contains a .bzr directory, but it is not valid."

(I think there's a deeper API issue I haven't addressed here: part of the problem is that BzrDir.open_from_transport doesn't differentiate between "doesn't exist" and "exists but has corrupt/invalid bzrdir". Similarly, Branch.create_clone_on_transport raises FileExists both for "the destination directory already exists (use_existing_dir would suppress this)" and for "cannot create a bzrdir in the destination because one already exists." So the obvious use of the API that tries open_from_transport, and simply falls back to create_clone_on_transport needs some pretty precise error handling to do the right thing in all cases. I think solving that properly would be a lot of work, though.)

This patch I think is small and safe enough that it's a candidate for 2.0.x.

Revision history for this message
Martin Pool (mbp) wrote :

blah

Revision history for this message
Martin Pool (mbp) wrote :

sorry, i thought i was on staging ;-)

Revision history for this message
Martin Pool (mbp) wrote :

this seems plausible.

you need news.

i feel like you shouldn't be hardcoding '.bzr' here but it's an improvement for now.

Revision history for this message
Martin Pool (mbp) wrote :

spurious review

review: Approve (doc)
Revision history for this message
Martin Pool (mbp) :
review: Approve
Revision history for this message
Robert Collins (lifeless) wrote :

Andrew, just a ping, to say 'please land' :)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2009-11-20 01:39:36 +0000
3+++ NEWS 2009-12-02 01:36:11 +0000
4@@ -20,6 +20,10 @@
5 Bug Fixes
6 *********
7
8+* ``bzr push --use-existing-dir`` no longer crashes if the directory
9+ exists but contains an invalid ``.bzr`` directory.
10+ (Andrew Bennetts, #423563)
11+
12 * Content filters are now applied correctly after pull, merge and switch.
13 (Ian Clatworthy, #385879)
14
15
16=== modified file 'bzrlib/branch.py'
17--- bzrlib/branch.py 2009-08-19 18:04:49 +0000
18+++ bzrlib/branch.py 2009-12-02 01:36:12 +0000
19@@ -1284,16 +1284,9 @@
20 # clone call. Or something. 20090224 RBC/spiv.
21 if revision_id is None:
22 revision_id = self.last_revision()
23- try:
24- dir_to = self.bzrdir.clone_on_transport(to_transport,
25- revision_id=revision_id, stacked_on=stacked_on,
26- create_prefix=create_prefix, use_existing_dir=use_existing_dir)
27- except errors.FileExists:
28- if not use_existing_dir:
29- raise
30- except errors.NoSuchFile:
31- if not create_prefix:
32- raise
33+ dir_to = self.bzrdir.clone_on_transport(to_transport,
34+ revision_id=revision_id, stacked_on=stacked_on,
35+ create_prefix=create_prefix, use_existing_dir=use_existing_dir)
36 return dir_to.open_branch()
37
38 def create_checkout(self, to_location, revision_id=None,
39
40=== modified file 'bzrlib/push.py'
41--- bzrlib/push.py 2009-07-18 21:09:00 +0000
42+++ bzrlib/push.py 2009-12-02 01:36:11 +0000
43@@ -90,12 +90,19 @@
44 br_to = br_from.create_clone_on_transport(to_transport,
45 revision_id=revision_id, stacked_on=stacked_on,
46 create_prefix=create_prefix, use_existing_dir=use_existing_dir)
47- except errors.FileExists:
48+ except errors.FileExists, err:
49+ if err.path.endswith('/.bzr'):
50+ raise errors.BzrCommandError(
51+ "Target directory %s already contains a .bzr directory, "
52+ "but it is not valid." % (location,))
53 if not use_existing_dir:
54 raise errors.BzrCommandError("Target directory %s"
55- " already exists, but does not have a valid .bzr"
56+ " already exists, but does not have a .bzr"
57 " directory. Supply --use-existing-dir to push"
58 " there anyway." % location)
59+ # This shouldn't occur, but if it does the FileExists error will be
60+ # more informative than an UnboundLocalError for br_to.
61+ raise
62 except errors.NoSuchFile:
63 if not create_prefix:
64 raise errors.BzrCommandError("Parent directory of %s"
65
66=== modified file 'bzrlib/tests/blackbox/test_push.py'
67--- bzrlib/tests/blackbox/test_push.py 2009-08-20 04:09:58 +0000
68+++ bzrlib/tests/blackbox/test_push.py 2009-12-02 01:36:11 +0000
69@@ -319,6 +319,17 @@
70 # The push should have created target/a
71 self.failUnlessExists('target/a')
72
73+ def test_push_use_existing_into_empty_bzrdir(self):
74+ """'bzr push --use-existing-dir' into a dir with an empty .bzr dir
75+ fails.
76+ """
77+ tree = self.create_simple_tree()
78+ self.build_tree(['target/', 'target/.bzr/'])
79+ self.run_bzr_error(
80+ ['Target directory ../target already contains a .bzr directory, '
81+ 'but it is not valid.'],
82+ 'push ../target --use-existing-dir', working_dir='tree')
83+
84 def test_push_onto_repo(self):
85 """We should be able to 'bzr push' into an existing bzrdir."""
86 tree = self.create_simple_tree()

Subscribers

People subscribed via source and target branches