524
class TestBranchParentLocation(TestCaseWithTransport):
527
"""Set up a repository and branch ready for testing."""
528
super(TestBranchParentLocation, self).setUp()
529
self.script_runner = script.ScriptRunner()
530
self.script_runner.run_script(self, '''
531
$ bzr init-repo --no-trees repo
534
shared repository: repo
535
$ bzr init repo/trunk
536
Created a repository branch...
537
Using shared repository: ...
540
def assertParentCorrect(self, branch, expected_parent, name):
541
"""Verify that the parent is not None and is set correctly."""
542
actual_parent = branch.get_parent()
543
self.assertIsNot(actual_parent, None, name + "Parent not set")
544
expected = urlutils.strip_trailing_slash(urlutils.normalize_url(expected_parent))
545
actual = urlutils.strip_trailing_slash(urlutils.normalize_url(actual_parent))
546
self.assertEquals(expected, actual, name + "Parent set incorrectly")
548
def _create_checkout_and_branch(self, option, suffix):
549
self.script_runner.run_script(self, '''
550
$ bzr checkout %(option)s repo/trunk work_%(suffix)s_branch
551
$ cd work_%(suffix)s_branch
552
$ bzr branch --switch ../repo/trunk ../repo/branched_%(suffix)s
523
class TestBranchParentLocation(test_switch.TestSwitchParentLocationBase):
525
def _checkout_and_branch(self, option=''):
526
self.script_runner.run_script(self, '''
527
$ bzr checkout %(option)s repo/trunk checkout
529
$ bzr branch --switch ../repo/trunk ../repo/branched
553
530
2>Branched 0 revision(s).
554
531
2>Tree is up to date at revision 0.
555
2>Switched to branch:...branched_%(suffix)s...
532
2>Switched to branch:...branched...
558
bound_branch = branch.Branch.open_containing('work_%(suffix)s_branch' % locals())[0]
559
master_branch = branch.Branch.open_containing('repo/branched_%(suffix)s' % locals())[0]
535
bound_branch = branch.Branch.open_containing('checkout')[0]
536
master_branch = branch.Branch.open_containing('repo/branched')[0]
560
537
return (bound_branch, master_branch)
562
539
def test_branch_switch_parent_lightweight(self):
563
"""Verify parent directory for lightweight checkout using bzr branch --switch."""
564
bb, mb = self._create_checkout_and_branch(option='--lightweight', suffix='lw')
565
self.assertParentCorrect(bb, urlutils.local_path_to_url('repo/trunk'), "Checkout")
566
self.assertParentCorrect(mb, urlutils.local_path_to_url('repo/trunk'), "Master Branch")
540
"""Lightweight checkout using bzr branch --switch."""
541
bb, mb = self._checkout_and_branch(option='--lightweight')
542
self.assertParent('repo/trunk', bb)
543
self.assertParent('repo/trunk', mb)
568
545
def test_branch_switch_parent_heavyweight(self):
569
"""Verify parent directory for heavyweight checkout using bzr branch --switch."""
570
bb, mb = self._create_checkout_and_branch(option='', suffix='hw')
571
self.assertParentCorrect(bb, urlutils.local_path_to_url('repo/trunk'), "Bound Branch")
572
self.assertParentCorrect(mb, urlutils.local_path_to_url('repo/trunk'), "Master Branch")
546
"""Heavyweight checkout using bzr branch --switch."""
547
bb, mb = self._checkout_and_branch()
548
self.assertParent('repo/trunk', bb)
549
self.assertParent('repo/trunk', mb)