Merge lp:~jelmer/bzr/checkout-into-empty-control-dir into lp:bzr/2.5

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Vincent Ladeuil
Approved revision: no longer in the source branch.
Merged at revision: 6453
Proposed branch: lp:~jelmer/bzr/checkout-into-empty-control-dir
Merge into: lp:bzr/2.5
Prerequisite: lp:~jelmer/bzr/controldir-set-branch-reference
Diff against target: 222 lines (+77/-13) (has conflicts)
9 files modified
bzrlib/branch.py (+21/-4)
bzrlib/bzrdir.py (+7/-4)
bzrlib/errors.py (+5/-0)
bzrlib/push.py (+4/-4)
bzrlib/remote.py (+8/-0)
bzrlib/tests/blackbox/test_checkout.py (+7/-0)
bzrlib/tests/per_controldir/test_controldir.py (+11/-0)
bzrlib/tests/test_smart.py (+1/-1)
doc/en/release-notes/bzr-2.5.txt (+13/-0)
Text conflict in bzrlib/branch.py
Text conflict in bzrlib/remote.py
Text conflict in doc/en/release-notes/bzr-2.5.txt
To merge this branch: bzr merge lp:~jelmer/bzr/checkout-into-empty-control-dir
Reviewer Review Type Date Requested Status
Vincent Ladeuil Approve
Review via email: mp+89136@code.launchpad.net

Commit message

Allow creating a checkout in a directory that already has a control directory.

Description of the change

Allow creating a checkout in a directory that already has a control directory (of course, only as long as there is no existing checkout there).

This is useful for e.g. checking out a directory into a location where one or more colocated (but not active) branches already exist.

To post a comment you must log in.
Revision history for this message
Vincent Ladeuil (vila) wrote :

Nicely tested !

review: Approve
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

sent to pqm by email

Revision history for this message
Jelmer Vernooij (jelmer) wrote :

sent to pqm by email

Revision history for this message
Jelmer Vernooij (jelmer) wrote :

sent to pqm by email

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/branch.py'
2--- bzrlib/branch.py 2012-01-18 17:47:06 +0000
3+++ bzrlib/branch.py 2012-01-19 18:54:35 +0000
4@@ -1457,18 +1457,35 @@
5 t = transport.get_transport(to_location)
6 t.ensure_base()
7 format = self._get_checkout_format(lightweight=lightweight)
8+ try:
9+ checkout = format.initialize_on_transport(t)
10+ except errors.AlreadyControlDirError:
11+ # It's fine if the control directory already exists,
12+ # as long as there is no existing branch and working tree.
13+ checkout = controldir.ControlDir.open_from_transport(t)
14+ try:
15+ checkout.open_branch()
16+ except errors.NotBranchError:
17+ pass
18+ else:
19+ raise errors.AlreadyControlDirError(t.base)
20+
21 if lightweight:
22+<<<<<<< TREE
23 checkout = format.initialize_on_transport(t)
24 from_branch = checkout.set_branch_reference(target_branch=self)
25+=======
26+ from_branch = checkout.set_branch_reference(target_branch=self)
27+>>>>>>> MERGE-SOURCE
28 else:
29- checkout_branch = controldir.ControlDir.create_branch_convenience(
30- to_location, force_new_tree=False, format=format)
31- checkout = checkout_branch.bzrdir
32+ policy = checkout.determine_repository_policy()
33+ repo = policy.acquire_repository()[0]
34+ checkout_branch = checkout.create_branch()
35 checkout_branch.bind(self)
36 # pull up to the specified revision_id to set the initial
37 # branch tip correctly, and seed it with history.
38 checkout_branch.pull(self, stop_revision=revision_id)
39- from_branch=None
40+ from_branch = None
41 tree = checkout.create_workingtree(revision_id,
42 from_branch=from_branch,
43 accelerator_tree=accelerator_tree,
44
45=== modified file 'bzrlib/bzrdir.py'
46--- bzrlib/bzrdir.py 2012-01-18 17:46:57 +0000
47+++ bzrlib/bzrdir.py 2012-01-19 18:54:35 +0000
48@@ -1475,10 +1475,13 @@
49 # mode from the root directory
50 temp_control = lockable_files.LockableFiles(transport,
51 '', lockable_files.TransportLock)
52- temp_control._transport.mkdir('.bzr',
53- # FIXME: RBC 20060121 don't peek under
54- # the covers
55- mode=temp_control._dir_mode)
56+ try:
57+ temp_control._transport.mkdir('.bzr',
58+ # FIXME: RBC 20060121 don't peek under
59+ # the covers
60+ mode=temp_control._dir_mode)
61+ except errors.FileExists:
62+ raise errors.AlreadyControlDirError(transport.base)
63 if sys.platform == 'win32' and isinstance(transport, local.LocalTransport):
64 win32utils.set_file_attr_hidden(transport._abspath('.bzr'))
65 file_mode = temp_control._file_mode
66
67=== modified file 'bzrlib/errors.py'
68--- bzrlib/errors.py 2011-12-22 15:33:16 +0000
69+++ bzrlib/errors.py 2012-01-19 18:54:35 +0000
70@@ -700,6 +700,11 @@
71 self.path = urlutils.unescape_for_display(branch.base, 'ascii')
72
73
74+class AlreadyControlDirError(PathError):
75+
76+ _fmt = 'A control directory already exists: "%(path)s".'
77+
78+
79 class AlreadyBranchError(PathError):
80
81 _fmt = 'Already a branch: "%(path)s".'
82
83=== modified file 'bzrlib/push.py'
84--- bzrlib/push.py 2011-12-19 13:23:58 +0000
85+++ bzrlib/push.py 2012-01-19 18:54:35 +0000
86@@ -92,11 +92,11 @@
87 revision_id=revision_id, stacked_on=stacked_on,
88 create_prefix=create_prefix, use_existing_dir=use_existing_dir,
89 no_tree=no_tree)
90+ except errors.AlreadyControlDirError, err:
91+ raise errors.BzrCommandError(gettext(
92+ "Target directory %s already contains a .bzr directory, "
93+ "but it is not valid.") % (location,))
94 except errors.FileExists, err:
95- if err.path.endswith('/.bzr'):
96- raise errors.BzrCommandError(gettext(
97- "Target directory %s already contains a .bzr directory, "
98- "but it is not valid.") % (location,))
99 if not use_existing_dir:
100 raise errors.BzrCommandError(gettext("Target directory %s"
101 " already exists, but does not have a .bzr"
102
103=== modified file 'bzrlib/remote.py'
104--- bzrlib/remote.py 2012-01-19 14:17:55 +0000
105+++ bzrlib/remote.py 2012-01-19 18:54:35 +0000
106@@ -679,6 +679,7 @@
107 b = self.open_branch(name=name)
108 return b._format
109
110+<<<<<<< TREE
111 def get_branches(self, possible_transports=None, ignore_fallbacks=False):
112 path = self._path_for_remote_call(self._client)
113 try:
114@@ -702,6 +703,13 @@
115 self._ensure_real()
116 return self._real_bzrdir.set_branch_reference(target_branch, name=name)
117
118+=======
119+ def set_branch_reference(self, target_branch, name=None):
120+ """See BzrDir.set_branch_reference()."""
121+ self._ensure_real()
122+ return self._real_bzrdir.set_branch_reference(target_branch, name=name)
123+
124+>>>>>>> MERGE-SOURCE
125 def get_branch_reference(self, name=None):
126 """See BzrDir.get_branch_reference()."""
127 if name is not None:
128
129=== modified file 'bzrlib/tests/blackbox/test_checkout.py'
130--- bzrlib/tests/blackbox/test_checkout.py 2012-01-05 13:02:31 +0000
131+++ bzrlib/tests/blackbox/test_checkout.py 2012-01-19 18:54:35 +0000
132@@ -76,6 +76,13 @@
133 self.assertEqual(['1'], result.open_workingtree().get_parent_ids())
134 self.assertPathDoesNotExist('checkout/added_in_2')
135
136+ def test_checkout_into_empty_dir(self):
137+ self.make_bzrdir('checkout')
138+ out, err = self.run_bzr(['checkout', 'branch', 'checkout'])
139+ result = bzrdir.BzrDir.open('checkout')
140+ tree = result.open_workingtree()
141+ branch = result.open_branch()
142+
143 def test_checkout_reconstitutes_working_trees(self):
144 # doing a 'bzr checkout' in the directory of a branch with no tree
145 # or a 'bzr checkout path' with path the name of a directory with
146
147=== modified file 'bzrlib/tests/per_controldir/test_controldir.py'
148--- bzrlib/tests/per_controldir/test_controldir.py 2012-01-18 17:47:06 +0000
149+++ bzrlib/tests/per_controldir/test_controldir.py 2012-01-19 18:54:35 +0000
150@@ -108,6 +108,17 @@
151 self.assertRaises(errors.UninitializableFormat,
152 self.bzrdir_format.initialize, t.base)
153
154+ def test_multiple_initialization(self):
155+ # loopback test to check the current format initializes to itself.
156+ if not self.bzrdir_format.is_initializable():
157+ # unsupported formats are not loopback testable
158+ # because the default open will not open them and
159+ # they may not be initializable.
160+ raise TestNotApplicable("format is not initializable")
161+ self.bzrdir_format.initialize('.')
162+ self.assertRaises(errors.AlreadyControlDirError,
163+ self.bzrdir_format.initialize, '.')
164+
165 def test_create_null_workingtree(self):
166 dir = self.make_bzrdir('dir1')
167 dir.create_repository()
168
169=== modified file 'bzrlib/tests/test_smart.py'
170--- bzrlib/tests/test_smart.py 2012-01-06 22:06:36 +0000
171+++ bzrlib/tests/test_smart.py 2012-01-19 18:54:35 +0000
172@@ -512,7 +512,7 @@
173 backing = self.get_transport()
174 request = smart_dir.SmartServerRequestInitializeBzrDir(backing)
175 self.make_bzrdir('subdir')
176- self.assertRaises(errors.FileExists,
177+ self.assertRaises(errors.AlreadyControlDirError,
178 request.execute, 'subdir')
179
180
181
182=== modified file 'doc/en/release-notes/bzr-2.5.txt'
183--- doc/en/release-notes/bzr-2.5.txt 2012-01-19 16:51:39 +0000
184+++ doc/en/release-notes/bzr-2.5.txt 2012-01-19 18:54:35 +0000
185@@ -26,6 +26,7 @@
186 .. Improvements to existing commands, especially improved performance
187 or memory usage, or better results.
188
189+<<<<<<< TREE
190 * "bzr switch -b" in a standalone tree will now create a colocated branch.
191 (Jelmer Vernooij, #918197)
192
193@@ -34,18 +35,30 @@
194
195 * New HPSS call for ``BzrDir.get_branches``. (Jelmer Vernooij, #894460)
196
197+=======
198+* Checkouts can now be into target directories that already have
199+ a control directory (but no branch or working tree).
200+ (Jelmer Vernooij, #913980)
201+
202+>>>>>>> MERGE-SOURCE
203 Bug Fixes
204 *********
205
206 .. Fixes for situations where bzr would previously crash or give incorrect
207 or undesirable results.
208
209+<<<<<<< TREE
210 * ``bzr branch`` now fetches revisions when branching into an empty
211 control directory. (Jelmer Vernooij, #905594)
212
213 * Support scripts that don't call bzrlib.initialize() but still call run_bzr().
214 (Vincent Ladeuil, #917733)
215
216+=======
217+* Support scripts that don't call bzrlib.initialize() but still call run_bzr().
218+ (Vincent Ladeuil, #917733)
219+
220+>>>>>>> MERGE-SOURCE
221 * Test for equality instead of object identity where ROOT_PARENT is concerned.
222 (Wouter van Heyst, #881142)
223

Subscribers

People subscribed via source and target branches