143
133
self.run_bzr(['switch', 'branchb'], working_dir='heavyco/a')
144
134
self.assertEqual(branchb_id, checkout.last_revision())
145
135
self.assertEqual(tree2.branch.base, checkout.branch.get_bound_location())
147
def test_switch_revision(self):
148
tree = self._create_sample_tree()
149
checkout = tree.branch.create_checkout('checkout', lightweight=True)
150
self.run_bzr(['switch', 'branch-1', '-r1'], working_dir='checkout')
151
self.failUnlessExists('checkout/file-1')
152
self.failIfExists('checkout/file-2')
154
def test_switch_only_revision(self):
155
tree = self._create_sample_tree()
156
checkout = tree.branch.create_checkout('checkout', lightweight=True)
157
self.failUnlessExists('checkout/file-1')
158
self.failUnlessExists('checkout/file-2')
159
self.run_bzr(['switch', '-r1'], working_dir='checkout')
160
self.failUnlessExists('checkout/file-1')
161
self.failIfExists('checkout/file-2')
162
# Check that we don't accept a range
164
['bzr switch --revision takes exactly one revision identifier'],
165
['switch', '-r0..2'], working_dir='checkout')
167
def prepare_lightweight_switch(self):
168
branch = self.make_branch('branch')
169
branch.create_checkout('tree', lightweight=True)
170
os.rename('branch', 'branch1')
172
def test_switch_lightweight_after_branch_moved(self):
173
self.prepare_lightweight_switch()
174
self.run_bzr('switch --force ../branch1', working_dir='tree')
175
branch_location = WorkingTree.open('tree').branch.base
176
self.assertEndsWith(branch_location, 'branch1/')
178
def test_switch_lightweight_after_branch_moved_relative(self):
179
self.prepare_lightweight_switch()
180
self.run_bzr('switch --force branch1', working_dir='tree')
181
branch_location = WorkingTree.open('tree').branch.base
182
self.assertEndsWith(branch_location, 'branch1/')
184
def test_create_branch_no_branch(self):
185
self.prepare_lightweight_switch()
186
self.run_bzr_error(['cannot create branch without source branch'],
187
'switch --create-branch ../branch2', working_dir='tree')
189
def test_create_branch(self):
190
branch = self.make_branch('branch')
191
tree = branch.create_checkout('tree', lightweight=True)
192
tree.commit('one', rev_id='rev-1')
193
self.run_bzr('switch --create-branch ../branch2', working_dir='tree')
194
tree = WorkingTree.open('tree')
195
self.assertEndsWith(tree.branch.base, '/branch2/')
197
def test_create_branch_local(self):
198
branch = self.make_branch('branch')
199
tree = branch.create_checkout('tree', lightweight=True)
200
tree.commit('one', rev_id='rev-1')
201
self.run_bzr('switch --create-branch branch2', working_dir='tree')
202
tree = WorkingTree.open('tree')
203
# The new branch should have been created at the same level as
204
# 'branch', because we did not have a '/' segment
205
self.assertEqual(branch.base[:-1] + '2/', tree.branch.base)
207
def test_create_branch_short_name(self):
208
branch = self.make_branch('branch')
209
tree = branch.create_checkout('tree', lightweight=True)
210
tree.commit('one', rev_id='rev-1')
211
self.run_bzr('switch -b branch2', working_dir='tree')
212
tree = WorkingTree.open('tree')
213
# The new branch should have been created at the same level as
214
# 'branch', because we did not have a '/' segment
215
self.assertEqual(branch.base[:-1] + '2/', tree.branch.base)
217
def test_create_branch_directory_services(self):
218
branch = self.make_branch('branch')
219
tree = branch.create_checkout('tree', lightweight=True)
220
class FooLookup(object):
221
def look_up(self, name, url):
223
directories.register('foo:', FooLookup, 'Create branches named foo-')
224
self.addCleanup(directories.remove, 'foo:')
225
self.run_bzr('switch -b foo:branch2', working_dir='tree')
226
tree = WorkingTree.open('tree')
227
self.assertEndsWith(tree.branch.base, 'foo-branch2/')