152
156
self.assertEqual(branchb_id, checkout.last_revision())
153
157
self.assertEqual(tree2.branch.base, checkout.branch.get_bound_location())
159
def test_switch_finds_relative_unicode_branch(self):
160
"""Switch will find 'foo' relative to the branch the checkout is of."""
161
self.requireFeature(UnicodeFilenameFeature)
162
self.build_tree(['repo/'])
163
tree1 = self.make_branch_and_tree('repo/brancha')
165
tree2 = self.make_branch_and_tree(u'repo/branch\xe9')
166
tree2.pull(tree1.branch)
167
branchb_id = tree2.commit('bar')
168
checkout = tree1.branch.create_checkout('checkout', lightweight=True)
169
self.run_bzr(['switch', u'branch\xe9'], working_dir='checkout')
170
self.assertEqual(branchb_id, checkout.last_revision())
171
checkout = checkout.bzrdir.open_workingtree()
172
self.assertEqual(tree2.branch.base, checkout.branch.base)
155
174
def test_switch_revision(self):
156
175
tree = self._create_sample_tree()
157
176
checkout = tree.branch.create_checkout('checkout', lightweight=True)
159
178
self.assertPathExists('checkout/file-1')
160
179
self.assertPathDoesNotExist('checkout/file-2')
181
def test_switch_existing_colocated(self):
182
# Create a branch branch-1 that initially is a checkout of 'foo'
183
# Use switch to change it to 'anotherbranch'
184
repo = self.make_repository('branch-1', format='development-colo')
185
target_branch = repo.bzrdir.create_branch(name='foo')
186
branch.BranchReferenceFormat().initialize(
187
repo.bzrdir, target_branch=target_branch)
188
tree = repo.bzrdir.create_workingtree()
189
self.build_tree(['branch-1/file-1', 'branch-1/file-2'])
191
revid1 = tree.commit('rev1')
193
revid2 = tree.commit('rev2')
194
otherbranch = tree.bzrdir.create_branch(name='anotherbranch')
195
otherbranch.generate_revision_history(revid1)
196
self.run_bzr(['switch', 'anotherbranch'], working_dir='branch-1')
197
tree = WorkingTree.open("branch-1")
198
self.assertEquals(tree.last_revision(), revid1)
199
self.assertEquals(tree.branch.control_url, otherbranch.control_url)
201
def test_switch_new_colocated(self):
202
# Create a branch branch-1 that initially is a checkout of 'foo'
203
# Use switch to create 'anotherbranch' which derives from that
204
repo = self.make_repository('branch-1', format='development-colo')
205
target_branch = repo.bzrdir.create_branch(name='foo')
206
branch.BranchReferenceFormat().initialize(
207
repo.bzrdir, target_branch=target_branch)
208
tree = repo.bzrdir.create_workingtree()
209
self.build_tree(['branch-1/file-1', 'branch-1/file-2'])
211
revid1 = tree.commit('rev1')
212
self.run_bzr(['switch', '-b', 'anotherbranch'], working_dir='branch-1')
213
bzrdir = BzrDir.open("branch-1")
215
set([b.name for b in bzrdir.list_branches()]),
216
set(["foo", "anotherbranch"]))
217
self.assertEquals(bzrdir.open_branch().name, "anotherbranch")
218
self.assertEquals(bzrdir.open_branch().last_revision(), revid1)
220
def test_switch_new_colocated_unicode(self):
221
# Create a branch branch-1 that initially is a checkout of 'foo'
222
# Use switch to create 'branch\xe9' which derives from that
223
self.requireFeature(UnicodeFilenameFeature)
224
repo = self.make_repository('branch-1', format='development-colo')
225
target_branch = repo.bzrdir.create_branch(name='foo')
226
branch.BranchReferenceFormat().initialize(
227
repo.bzrdir, target_branch=target_branch)
228
tree = repo.bzrdir.create_workingtree()
229
self.build_tree(['branch-1/file-1', 'branch-1/file-2'])
231
revid1 = tree.commit('rev1')
232
self.run_bzr(['switch', '-b', u'branch\xe9'], working_dir='branch-1')
233
bzrdir = BzrDir.open("branch-1")
235
set([b.name for b in bzrdir.list_branches()]),
236
set(["foo", u"branch\xe9"]))
237
self.assertEquals(bzrdir.open_branch().name, u"branch\xe9")
238
self.assertEquals(bzrdir.open_branch().last_revision(), revid1)
162
240
def test_switch_only_revision(self):
163
241
tree = self._create_sample_tree()
164
242
checkout = tree.branch.create_checkout('checkout', lightweight=True)
352
430
# This test should be cleaner to write, but see bug:
353
431
# https://bugs.launchpad.net/bzr/+bug/812295
354
432
self.assertEqual(1, opened.count('master'))
435
class TestSmartServerSwitch(TestCaseWithTransport):
437
def test_switch_lightweight(self):
438
self.setup_smart_server_with_call_log()
439
t = self.make_branch_and_tree('from')
440
for count in range(9):
441
t.commit(message='commit %d' % count)
442
out, err = self.run_bzr(['checkout', '--lightweight', self.get_url('from'),
444
self.reset_smart_call_log()
445
self.run_bzr(['switch', self.get_url('from')], working_dir='target')
446
# This figure represent the amount of work to perform this use case. It
447
# is entirely ok to reduce this number if a test fails due to rpc_count
448
# being too low. If rpc_count increases, more network roundtrips have
449
# become necessary for this use case. Please do not adjust this number
450
# upwards without agreement from bzr's network support maintainers.
451
self.assertLength(24, self.hpss_calls)
452
self.assertLength(5, self.hpss_connections)
453
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)