226
226
# Create a branch branch-1 that initially is a checkout of 'foo'
227
227
# Use switch to change it to 'anotherbranch'
228
228
repo = self.make_repository('branch-1', format='development-colo')
229
target_branch = repo.controldir.create_branch(name='foo')
230
repo.controldir.set_branch_reference(target_branch)
231
tree = repo.controldir.create_workingtree()
229
target_branch = repo.bzrdir.create_branch(name='foo')
230
repo.bzrdir.set_branch_reference(target_branch)
231
tree = repo.bzrdir.create_workingtree()
232
232
self.build_tree(['branch-1/file-1', 'branch-1/file-2'])
233
233
tree.add('file-1')
234
234
revid1 = tree.commit('rev1')
235
235
tree.add('file-2')
236
236
revid2 = tree.commit('rev2')
237
otherbranch = tree.controldir.create_branch(name='anotherbranch')
237
otherbranch = tree.bzrdir.create_branch(name='anotherbranch')
238
238
otherbranch.generate_revision_history(revid1)
239
239
self.run_bzr(['switch', 'anotherbranch'], working_dir='branch-1')
240
240
tree = WorkingTree.open("branch-1")
241
self.assertEqual(tree.last_revision(), revid1)
242
self.assertEqual(tree.branch.control_url, otherbranch.control_url)
241
self.assertEquals(tree.last_revision(), revid1)
242
self.assertEquals(tree.branch.control_url, otherbranch.control_url)
244
244
def test_switch_new_colocated(self):
245
245
# Create a branch branch-1 that initially is a checkout of 'foo'
246
246
# Use switch to create 'anotherbranch' which derives from that
247
247
repo = self.make_repository('branch-1', format='development-colo')
248
target_branch = repo.controldir.create_branch(name='foo')
249
repo.controldir.set_branch_reference(target_branch)
250
tree = repo.controldir.create_workingtree()
248
target_branch = repo.bzrdir.create_branch(name='foo')
249
repo.bzrdir.set_branch_reference(target_branch)
250
tree = repo.bzrdir.create_workingtree()
251
251
self.build_tree(['branch-1/file-1', 'branch-1/file-2'])
252
252
tree.add('file-1')
253
253
revid1 = tree.commit('rev1')
254
254
self.run_bzr(['switch', '-b', 'anotherbranch'], working_dir='branch-1')
255
255
bzrdir = ControlDir.open("branch-1")
257
{b.name for b in bzrdir.list_branches()},
258
{"foo", "anotherbranch"})
259
self.assertEqual(bzrdir.open_branch().name, "anotherbranch")
260
self.assertEqual(bzrdir.open_branch().last_revision(), revid1)
257
set([b.name for b in bzrdir.list_branches()]),
258
set(["foo", "anotherbranch"]))
259
self.assertEquals(bzrdir.open_branch().name, "anotherbranch")
260
self.assertEquals(bzrdir.open_branch().last_revision(), revid1)
262
262
def test_switch_new_colocated_unicode(self):
263
263
# Create a branch branch-1 that initially is a checkout of 'foo'
264
264
# Use switch to create 'branch\xe9' which derives from that
265
265
self.requireFeature(UnicodeFilenameFeature)
266
266
repo = self.make_repository('branch-1', format='development-colo')
267
target_branch = repo.controldir.create_branch(name='foo')
268
repo.controldir.set_branch_reference(target_branch)
269
tree = repo.controldir.create_workingtree()
267
target_branch = repo.bzrdir.create_branch(name='foo')
268
repo.bzrdir.set_branch_reference(target_branch)
269
tree = repo.bzrdir.create_workingtree()
270
270
self.build_tree(['branch-1/file-1', 'branch-1/file-2'])
271
271
tree.add('file-1')
272
272
revid1 = tree.commit('rev1')
273
273
self.run_bzr(['switch', '-b', u'branch\xe9'], working_dir='branch-1')
274
274
bzrdir = ControlDir.open("branch-1")
276
{b.name for b in bzrdir.list_branches()},
277
{"foo", u"branch\xe9"})
278
self.assertEqual(bzrdir.open_branch().name, u"branch\xe9")
279
self.assertEqual(bzrdir.open_branch().last_revision(), revid1)
276
set([b.name for b in bzrdir.list_branches()]),
277
set(["foo", u"branch\xe9"]))
278
self.assertEquals(bzrdir.open_branch().name, u"branch\xe9")
279
self.assertEquals(bzrdir.open_branch().last_revision(), revid1)
281
281
def test_switch_only_revision(self):
282
282
tree = self._create_sample_tree()
438
438
return (bound_branch, master_branch)
440
440
def test_switch_parent_lightweight(self):
441
"""Lightweight checkout using brz switch."""
441
"""Lightweight checkout using bzr switch."""
442
442
bb, mb = self._checkout_and_switch(option='--lightweight')
443
443
self.assertParent('repo/trunk', bb)
444
444
self.assertParent('repo/trunk', mb)
446
446
def test_switch_parent_heavyweight(self):
447
"""Heavyweight checkout using brz switch."""
447
"""Heavyweight checkout using bzr switch."""
448
448
bb, mb = self._checkout_and_switch()
449
449
self.assertParent('repo/trunk', bb)
450
450
self.assertParent('repo/trunk', mb)
529
529
self.assertPathDoesNotExist('checkout/a')
530
530
self.run_bzr(['switch', '-d', 'checkout', 'orig'])
531
531
self.assertPathDoesNotExist('checkout/a')
534
class TestSwitchStandAloneCorruption(TestCaseWithTransport):
536
def test_empty_tree_switch(self):
537
"""switch . on an empty tree gets infinite recursion
539
Inspired by: https://bugs.launchpad.net/bzr/+bug/1018628
541
self.script_runner = script.ScriptRunner()
542
self.script_runner.run_script(self, '''
544
Created a standalone tree (format: 2a)
546
2>brz: ERROR: switching would create a branch reference loop. Use the "bzr up" command to switch to a different revision.
549
def test_switch_on_previous_rev(self):
550
"""switch to previous rev in a standalone directory
552
Inspired by: https://bugs.launchpad.net/brz/+bug/1018628
554
self.script_runner = script.ScriptRunner()
555
self.script_runner.run_script(self, '''
557
Created a standalone tree (format: 2a)
558
$ brz commit -m 1 --unchanged
559
$ brz commit -m 2 --unchanged
561
2>brz: ERROR: switching would create a branch reference loop. Use the "bzr up" command to switch to a different revision.''',
562
null_output_matches_anything=True)
564
def test_switch_create_colo_locks_repo_path(self):
565
self.script_runner = script.ScriptRunner()
566
self.script_runner.run_script(self, '''
570
Created a standalone tree (format: 2a)
571
$ echo A > a && brz add a && brz commit -m A
578
''', null_output_matches_anything=True)