def test_checkout_reconstitutes_working_trees(self): # doing a 'brz checkout' in the directory of a branch with no tree # or a 'brz checkout path' with path the name of a directory with # a branch with no tree will reconsistute the tree. os.mkdir('treeless-branch') branch = controldir.ControlDir.create_branch_convenience( 'treeless-branch', force_new_tree=False, format=bzrdir.BzrDirMetaFormat1()) # check no tree was created self.assertRaises(errors.NoWorkingTree, branch.controldir.open_workingtree) out, err = self.run_bzr('checkout treeless-branch') # we should have a tree now branch.controldir.open_workingtree() # with no diff out, err = self.run_bzr('diff treeless-branch') # now test with no parameters branch = controldir.ControlDir.create_branch_convenience( '.', force_new_tree=False, format=bzrdir.BzrDirMetaFormat1()) # check no tree was created self.assertRaises(errors.NoWorkingTree, branch.controldir.open_workingtree) out, err = self.run_bzr('checkout') # we should have a tree now branch.controldir.open_workingtree() # with no diff out, err = self.run_bzr('diff')
def assertInitializeEx(self, t, need_meta=False, **kwargs): """Execute initialize_on_transport_ex and check it succeeded correctly. This involves checking that the disk objects were created, open with the same format returned, and had the expected disk format. :param t: The transport to initialize on. :param **kwargs: Additional arguments to pass to initialize_on_transport_ex. :return: the resulting repo, control dir tuple. """ if not self.bzrdir_format.is_initializable(): raise TestNotApplicable("control dir format is not " "initializable") repo, control, require_stacking, repo_policy = \ self.bzrdir_format.initialize_on_transport_ex(t, **kwargs) if repo is not None: # Repositories are open write-locked self.assertTrue(repo.is_write_locked()) self.addCleanup(repo.unlock) self.assertIsInstance(control, bzrdir.BzrDir) opened = bzrdir.BzrDir.open(t.base) expected_format = self.bzrdir_format if need_meta and expected_format.fixed_components: # Pre-metadir formats change when we are making something that # needs a metaformat, because clone is used for push. expected_format = bzrdir.BzrDirMetaFormat1() if not isinstance(expected_format, RemoteBzrDirFormat): self.assertEqual(control._format.network_name(), expected_format.network_name()) self.assertEqual(control._format.network_name(), opened._format.network_name()) self.assertEqual(control.__class__, opened.__class__) return repo, control
def test_list_tags_dotted_revnos_unsupported(self): class TrimmedBranch(bzrbranch.BzrBranch6): def revision_id_to_dotted_revno(self, revid): raise errors.UnsupportedOperation( self.revision_id_to_dotted_revno, self) class TrimmedBranchFormat(bzrbranch.BzrBranchFormat6): def _branch_class(self): return TrimmedBranch @classmethod def get_format_string(cls): return b"Trimmed Branch" _mod_branch.format_registry.register(TrimmedBranchFormat()) self.addCleanup(_mod_branch.format_registry.remove, TrimmedBranchFormat()) dir_format = bzrdir.BzrDirMetaFormat1() dir_format._branch_format = TrimmedBranchFormat() tree = self.make_branch_and_tree('branch', format=dir_format) self.assertFileEqual('Trimmed Branch', 'branch/.bzr/branch/format') rev1 = tree.commit("rev1") tree.branch.tags.set_tag("mytag", rev1) out, err = self.run_bzr('tags -d branch', encoding='utf-8') self.assertEqual(out, 'mytag ?\n')
def convert(self, to_convert, pb): ui.ui_factory.note('starting upgrade from old test format to 2a') to_convert.control_transport.put_bytes( 'branch-format', bzrdir.BzrDirMetaFormat1().get_format_string(), mode=to_convert._get_file_mode()) return controldir.ControlDir.open(to_convert.user_url)
def test_update_with_merges(self): # Test that 'brz update' works correctly when you have # an update in the master tree, and a lightweight checkout # which has merged another branch master = self.make_branch_and_tree('master') self.build_tree(['master/file']) master.add(['file']) master.commit('one', rev_id=b'm1') self.build_tree(['checkout1/']) checkout_dir = bzrdir.BzrDirMetaFormat1().initialize('checkout1') checkout_dir.set_branch_reference(master.branch) checkout1 = checkout_dir.create_workingtree(b'm1') # Create a second branch, with an extra commit other = master.controldir.sprout('other').open_workingtree() self.build_tree(['other/file2']) other.add(['file2']) other.commit('other2', rev_id=b'o2') # Create a new commit in the master branch self.build_tree(['master/file3']) master.add(['file3']) master.commit('f3', rev_id=b'm2') # Merge the other branch into checkout os.chdir('checkout1') self.run_bzr('merge ../other') self.assertEqual([b'o2'], checkout1.get_parent_ids()[1:]) # At this point, 'commit' should fail, because we are out of date self.run_bzr_error(["please run 'brz update'"], 'commit -m merged') # This should not report about local commits being pending # merges, because they were real merges out, err = self.run_bzr('update') self.assertEqual('', out) self.assertEqualDiff( '''+N file3 All changes applied successfully. Updated to revision 2 of branch %s ''' % osutils.pathjoin( self.test_dir, 'master', ), err) # The pending merges should still be there self.assertEqual([b'o2'], checkout1.get_parent_ids()[1:])
def test_update_with_merge_merged_to_master(self): # Test that 'brz update' works correctly when you have # an update in the master tree, and a [lightweight or otherwise] # checkout which has merge a revision merged to master already. master = self.make_branch_and_tree('master') self.build_tree(['master/file']) master.add(['file']) master.commit('one', rev_id=b'm1') self.build_tree(['checkout1/']) checkout_dir = bzrdir.BzrDirMetaFormat1().initialize('checkout1') checkout_dir.set_branch_reference(master.branch) checkout1 = checkout_dir.create_workingtree(b'm1') # Create a second branch, with an extra commit other = master.controldir.sprout('other').open_workingtree() self.build_tree(['other/file2']) other.add(['file2']) other.commit('other2', rev_id=b'o2') # Merge the other branch into checkout - 'start reviewing a patch' checkout1.merge_from_branch(other.branch) self.assertEqual([b'o2'], checkout1.get_parent_ids()[1:]) # Create a new commit in the master branch - 'someone else lands its' master.merge_from_branch(other.branch) master.commit('f3', rev_id=b'm2') # This should not report about local commits being pending # merges, because they were real merges (but are now gone). # It should perhaps report on them. out, err = self.run_bzr('update', working_dir='checkout1') self.assertEqual('', out) self.assertEqualDiff( '''All changes applied successfully. Updated to revision 2 of branch %s ''' % osutils.pathjoin( self.test_dir, 'master', ), err) # The pending merges should still be there self.assertEqual([], checkout1.get_parent_ids()[1:])
def test_push_only_pushes_history(self): # Knit branches should only push the history for the current revision. format = bzrdir.BzrDirMetaFormat1() format.repository_format = knitrepo.RepositoryFormatKnit1() shared_repo = self.make_repository('repo', format=format, shared=True) shared_repo.set_make_working_trees(True) def make_shared_tree(path): shared_repo.controldir.root_transport.mkdir(path) controldir.ControlDir.create_branch_convenience('repo/' + path) return workingtree.WorkingTree.open('repo/' + path) tree_a = make_shared_tree('a') self.build_tree(['repo/a/file']) tree_a.add('file') tree_a.commit('commit a-1', rev_id=b'a-1') f = open('repo/a/file', 'ab') f.write(b'more stuff\n') f.close() tree_a.commit('commit a-2', rev_id=b'a-2') tree_b = make_shared_tree('b') self.build_tree(['repo/b/file']) tree_b.add('file') tree_b.commit('commit b-1', rev_id=b'b-1') self.assertTrue(shared_repo.has_revision(b'a-1')) self.assertTrue(shared_repo.has_revision(b'a-2')) self.assertTrue(shared_repo.has_revision(b'b-1')) # Now that we have a repository with shared files, make sure # that things aren't copied out by a 'push' self.run_bzr('push ../../push-b', working_dir='repo/b') pushed_tree = workingtree.WorkingTree.open('push-b') pushed_repo = pushed_tree.branch.repository self.assertFalse(pushed_repo.has_revision(b'a-1')) self.assertFalse(pushed_repo.has_revision(b'a-2')) self.assertTrue(pushed_repo.has_revision(b'b-1'))
def test_info_locking(self): transport = self.get_transport() # Create shared repository with a branch repo = self.make_repository('repo', shared=True, format=bzrdir.BzrDirMetaFormat1()) repo.set_make_working_trees(False) repo.controldir.root_transport.mkdir('branch') repo_branch = controldir.ControlDir.create_branch_convenience( 'repo/branch', format=bzrdir.BzrDirMetaFormat1()) # Do a heavy checkout transport.mkdir('tree') transport.mkdir('tree/checkout') co_branch = controldir.ControlDir.create_branch_convenience( 'tree/checkout', format=bzrdir.BzrDirMetaFormat1()) co_branch.bind(repo_branch) # Do a light checkout of the heavy one transport.mkdir('tree/lightcheckout') lco_dir = bzrdir.BzrDirMetaFormat1().initialize('tree/lightcheckout') lco_dir.set_branch_reference(co_branch) lco_dir.create_workingtree() lco_tree = lco_dir.open_workingtree() # Test all permutations of locking the working tree, branch and repository # W B R # U U U self.assertCheckoutStatusOutput('-v tree/lightcheckout', lco_tree, repo_branch=repo_branch, verbose=True, light_checkout=True) # U U L with lco_tree.branch.repository.lock_write(): self.assertCheckoutStatusOutput('-v tree/lightcheckout', lco_tree, repo_branch=repo_branch, repo_locked=True, verbose=True, light_checkout=True) # U L L with lco_tree.branch.lock_write(): self.assertCheckoutStatusOutput('-v tree/lightcheckout', lco_tree, branch_locked=True, repo_locked=True, repo_branch=repo_branch, verbose=True) # L L L with lco_tree.lock_write(): self.assertCheckoutStatusOutput('-v tree/lightcheckout', lco_tree, repo_branch=repo_branch, tree_locked=True, branch_locked=True, repo_locked=True, verbose=True) # L L U with lco_tree.lock_write(), lco_tree.branch.repository.unlock(): self.assertCheckoutStatusOutput('-v tree/lightcheckout', lco_tree, repo_branch=repo_branch, tree_locked=True, branch_locked=True, verbose=True) # L U U with lco_tree.lock_write(), lco_tree.branch.unlock(): self.assertCheckoutStatusOutput('-v tree/lightcheckout', lco_tree, repo_branch=repo_branch, tree_locked=True, verbose=True) # L U L with lco_tree.lock_write(), lco_tree.branch.unlock(), \ lco_tree.branch.repository.lock_write(): self.assertCheckoutStatusOutput('-v tree/lightcheckout', lco_tree, repo_branch=repo_branch, tree_locked=True, repo_locked=True, verbose=True) # U L U with lco_tree.branch.lock_write(), lco_tree.branch.repository.unlock(): self.assertCheckoutStatusOutput('-v tree/lightcheckout', lco_tree, repo_branch=repo_branch, branch_locked=True, verbose=True) if sys.platform == 'win32': self.knownFailure('Win32 cannot run "brz info"' ' when the tree is locked.')
def make_branch_and_tree(self, relpath): source = self.make_branch(pathjoin('..', relpath)) checkout = bzrdir.BzrDirMetaFormat1().initialize(relpath) checkout.set_branch_reference(source) return checkout.create_workingtree()