def test_clone_stacking_policy_upgrades(self): """Cloning an unstackable branch format to somewhere with a default stack-on branch upgrades branch and repo to match the target and honour the policy. """ try: repo = self.make_repository('repo', shared=True) except errors.IncompatibleFormat: raise tests.TestNotApplicable('Cannot make a shared repository') if repo.bzrdir._format.fixed_components: self.knownFailure("pre metadir branches do not upgrade on push " "with stacking policy") if isinstance(repo._format, knitpack_repo.RepositoryFormatKnitPack5RichRootBroken): raise tests.TestNotApplicable("unsupported format") # Make a source branch in 'repo' in an unstackable branch format bzrdir_format = self.repository_format._matchingbzrdir transport = self.get_transport('repo/branch') transport.mkdir('.') target_bzrdir = bzrdir_format.initialize_on_transport(transport) branch = _mod_branch.BzrBranchFormat6().initialize(target_bzrdir) # Ensure that stack_on will be stackable and match the serializer of # repo. if isinstance(repo, remote.RemoteRepository): repo._ensure_real() info_repo = repo._real_repository else: info_repo = repo format_description = info.describe_format(info_repo.bzrdir, info_repo, None, None) formats = format_description.split(' or ') stack_on_format = formats[0] if stack_on_format in ["pack-0.92", "dirstate", "metaweave"]: stack_on_format = "1.9" elif stack_on_format in [ "dirstate-with-subtree", "rich-root", "rich-root-pack", "pack-0.92-subtree" ]: stack_on_format = "1.9-rich-root" # formats not tested for above are already stackable, so we can use the # format as-is. stack_on = self.make_branch('stack-on-me', format=stack_on_format) self.make_bzrdir('.').get_config().set_default_stack_on('stack-on-me') target = branch.bzrdir.clone(self.get_url('target')) # The target branch supports stacking. self.assertTrue(target.open_branch()._format.supports_stacking()) if isinstance(repo, remote.RemoteRepository): repo._ensure_real() repo = repo._real_repository target_repo = target.open_repository() if isinstance(target_repo, remote.RemoteRepository): target_repo._ensure_real() target_repo = target_repo._real_repository # The repository format is unchanged if it could already stack, or the # same as the stack on. if repo._format.supports_external_lookups: self.assertEqual(repo._format, target_repo._format) else: self.assertEqual(stack_on.repository._format, target_repo._format)
def test_creation(self): format = bzrdir.BzrDirMetaFormat1() format.set_branch_format(_mod_branch.BzrBranchFormat6()) branch = self.make_branch('a', format=format) self.assertIsInstance(branch, self.get_class()) branch = self.make_branch('b', format=self.get_format_name()) self.assertIsInstance(branch, self.get_class()) branch = _mod_branch.Branch.open('a') self.assertIsInstance(branch, self.get_class())
def test_describe_repo_format(self): for key in bzrdir.format_registry.keys(): if key in bzrdir.format_registry.aliases(): continue expected = None if key in ('dirstate', 'knit', 'dirstate-tags'): expected = 'dirstate or dirstate-tags or knit' self.assertRepoDescription(key, expected) format = bzrdir.format_registry.make_bzrdir('metaweave') format.set_branch_format(_mod_branch.BzrBranchFormat6()) tree = self.make_branch_and_tree('unknown', format=format) self.assertEqual('unnamed', info.describe_format(tree.bzrdir, tree.branch.repository, tree.branch, tree))
def test_repo_push_tags(self): # source src_repo = self.make_repository('src', shared=True) os.chdir('src') br_dir = bzrdir.BzrDir.create('branch') br_a = branch.BzrBranchFormat6().initialize(br_dir) wt = br_a.bzrdir.create_workingtree() self.build_tree(['branch/foo']) wt.add('foo') wt.commit('1', rev_id='one-id') # add tag br_a.tags.set_tag('mytag', 'one-id') # dest dest = self.make_repository('../dest', shared=True) # repo-push self.run_bzr('repo-push ../dest') # inspect tags br_b = branch.Branch.open_containing('../dest/branch')[0] self.assertEquals({'mytag': 'one-id'}, br_b.tags.get_tag_dict())
def test_sprout_uses_bzrdir_branch_format(self): # branch.sprout(bzrdir) is defined as using the branch format selected # by bzrdir; format preservation is achieved by parameterising the # bzrdir during bzrdir.sprout, which is where stacking compatibility # checks are done. So this test tests that each implementation of # Branch.sprout delegates appropriately to the bzrdir which the # branch is being created in, rather than testing that the result is # in the format that we are testing (which is what would happen if # the branch did not delegate appropriately). if isinstance(self.branch_format, _mod_branch.BranchReferenceFormat): raise tests.TestNotApplicable('cannot sprout to a reference') # Start with a format that is unlikely to be the target format # We call the super class to allow overriding the format of creation) source = tests.TestCaseWithTransport.make_branch(self, 'old-branch', format='knit') target_bzrdir = self.make_bzrdir('target') target_bzrdir.create_repository() result_format = self.branch_format if isinstance(target_bzrdir, remote.RemoteBzrDir): # for a remote bzrdir, we need to parameterise it with a branch # format, as, after creation, the newly opened remote objects # do not have one unless a branch was created at the time. # We use branch format 6 because its not the default, and its not # metaweave either. target_bzrdir._format.set_branch_format( _mod_branch.BzrBranchFormat6()) result_format = target_bzrdir._format.get_branch_format() target = source.sprout(target_bzrdir) if isinstance(target, remote.RemoteBranch): # we have to look at the real branch to see whether RemoteBranch # did the right thing. target._ensure_real() target = target._real_branch if isinstance(result_format, remote.RemoteBranchFormat): # Unwrap a parameterised RemoteBranchFormat for comparison. result_format = result_format._custom_format self.assertIs(result_format.__class__, target._format.__class__)