def test_mkdir_w_nested_trees(self): """'brz mkdir' with nested trees""" self.make_branch_and_tree('.') self.make_branch_and_tree('a') self.make_branch_and_tree('a/b') self.run_bzr(['mkdir', 'dir', 'a/dir', 'a/b/dir']) self.assertTrue(os.path.isdir('dir')) self.assertTrue(os.path.isdir('a/dir')) self.assertTrue(os.path.isdir('a/b/dir')) wt = WorkingTree.open('.') wt_a = WorkingTree.open('a') wt_b = WorkingTree.open('a/b') delta = wt.changes_from(wt.basis_tree()) self.assertEqual(len(delta.added), 1) self.assertEqual(delta.added[0][0], 'dir') self.assertFalse(delta.modified) delta = wt_a.changes_from(wt_a.basis_tree()) self.assertEqual(len(delta.added), 1) self.assertEqual(delta.added[0][0], 'dir') self.assertFalse(delta.modified) delta = wt_b.changes_from(wt_b.basis_tree()) self.assertEqual(len(delta.added), 1) self.assertEqual(delta.added[0][0], 'dir') self.assertFalse(delta.modified)
def test_304134(self): self.make_checkout(self.repos_url, 'svn-co') self.build_tree({ 'svn-co/subdir1/file1': b'', 'svn-co/subdir1/file2': b'', 'svn-co/subdir2/file3': b'', 'svn-co/subdir2/file4': b'' }) self.client_add('svn-co/subdir1') self.client_add('svn-co/subdir2') self.client_commit('svn-co', "Initial tree.") self.build_tree({ 'svn-co/subdir1/subdir3/file5': b'', 'svn-co/subdir1/subdir3/file6': b'' }) self.client_add('svn-co/subdir1/subdir3') self.client_commit('svn-co', "More files.") self.build_tree({ 'svn-co/subdir2/file3': b'addaline', 'svn-co/subdir2/file4': b'addbline', 'svn-co/subdir2/file7': b'' }) self.client_add('svn-co/subdir2/file7') self.client_set_prop("svn-co/subdir2/file4", "svn:executable", "true") self.client_copy("svn-co/subdir2", "svn-co/subdir1/subdir2") self.client_delete("svn-co/subdir2") self.client_commit("svn-co", "Directory move with modifications.") self.client_update("svn-co") wt = WorkingTree.open("svn-co") with wt.lock_write(): wt.update() wt = None wt = WorkingTree.open("svn-co/subdir1") with wt.lock_write(): pass #wt.update()
def _scrub_obsolete(wt: WorkingTree, debian_path: str, compat_release: str, upgrade_release: str, allow_reformatting: bool = True) -> ScrubObsoleteResult: specific_files = [] control_path = os.path.join(debian_path, "control") try: with ControlEditor(wt.abspath(control_path), allow_reformatting=allow_reformatting) as editor: specific_files.append(control_path) package = editor.source["Source"] control_removed = drop_old_relations(editor, compat_release, upgrade_release) except FileNotFoundError: if wt.has_filename(os.path.join(debian_path, "debcargo.toml")): control_removed = [] else: raise NotDebianPackage(wt, debian_path) maintscript_removed = [] for path, removed in update_maintscripts( wt, debian_path, PackageChecker(upgrade_release, build=False), package, allow_reformatting): if removed: maintscript_removed.append((path, removed, upgrade_release)) specific_files.append(path) return ScrubObsoleteResult( specific_files=specific_files, control_removed=control_removed, maintscript_removed=maintscript_removed, )
def test_init_branch(self): out, err = self.run_bzr('init') self.assertEqual( "Created a standalone tree (format: %s)\n" % (self._default_label, ), out) self.assertEqual('', err) # Can it handle subdirectories of branches too ? out, err = self.run_bzr('init subdir1') self.assertEqual( "Created a standalone tree (format: %s)\n" % (self._default_label, ), out) self.assertEqual('', err) WorkingTree.open('subdir1') self.run_bzr_error( ['Parent directory of subdir2/nothere does not exist'], 'init subdir2/nothere') out, err = self.run_bzr('init subdir2/nothere', retcode=3) self.assertEqual('', out) os.mkdir('subdir2') out, err = self.run_bzr('init subdir2') self.assertEqual( "Created a standalone tree (format: %s)\n" % (self._default_label, ), out) self.assertEqual('', err) # init an existing branch. out, err = self.run_bzr('init subdir2', retcode=3) self.assertEqual('', out) self.assertTrue(err.startswith('brz: ERROR: Already a branch:'))
def tree_set_changelog_version(tree: WorkingTree, build_version: Version, subpath: str) -> None: cl_path = osutils.pathjoin(subpath, "debian/changelog") with tree.get_file(cl_path) as f: cl = Changelog(f) if Version(str(cl.version) + "~") > build_version: return cl.version = build_version with open(tree.abspath(cl_path), "w") as f: cl.write_to_open_file(f)
def test_conflicts(self): self.create_conflicts() self.run_bzr('merge ../other', retcode=1, working_dir='this') wt = WorkingTree.open('this') self.assertEqual(2, len(wt.conflicts())) self.run_bzr('remerge', retcode=1, working_dir='this') wt = WorkingTree.open('this') self.assertEqual(2, len(wt.conflicts())) self.run_bzr('remerge hello', retcode=1, working_dir='this') wt = WorkingTree.open('this') self.assertEqual(2, len(wt.conflicts()))
def test_not_branch_path(self): tree = self.make_svn_branch_and_tree('a', 'dc') self.build_tree({"dc/file": b"data"}) self.client_add("dc/file") self.client_commit("dc", "initial") self.client_update("dc") self.build_tree({"dc/dir": None}) self.client_add("dc/dir") config_set_scheme(Repository.open(tree.branch.repository.base), TrunkBranchingScheme(0), None, True) Repository.open(tree.branch.repository.base).store_layout(TrunkLayout(0)) self.assertRaises(NotBranchError, WorkingTree.open, "dc/foobar") self.assertRaises(NotBranchError, WorkingTree.open, "dc/dir") WorkingTree.open("dc")
def test_new_files_group_sticky_bit(self): if sys.platform == 'win32': raise TestSkipped('chmod has no effect on win32') elif sys.platform == 'darwin' or 'freebsd' in sys.platform: # FreeBSD-based platforms create temp dirs with the 'wheel' group, # which users are not likely to be in, and this prevents us from # setting the sgid bit os.chown(self.test_dir, os.getuid(), os.getgid()) t = self.make_branch_and_tree('.') b = t.branch # Test the group sticky bit # Recursively update the modes of all files chmod_r('.bzr', 0o664, 0o2775) check_mode_r(self, '.bzr', 0o664, 0o2775) t = WorkingTree.open('.') b = t.branch self.assertEqualMode(0o2775, b.control_files._dir_mode) self.assertEqualMode(0o664, b.control_files._file_mode) self.assertEqualMode(0o2775, b.controldir._get_dir_mode()) self.assertEqualMode(0o664, b.controldir._get_file_mode()) with open('a', 'wb') as f: f.write(b'foo4\n') t.commit('foo4') check_mode_r(self, '.bzr', 0o664, 0o2775) with open('d', 'wb') as f: f.write(b'new d\n') t.add('d') t.commit('new d') check_mode_r(self, '.bzr', 0o664, 0o2775)
def test_add_reopen(self): tree = self.make_svn_branch_and_tree('a', 'dc') self.build_tree({"dc/bl": "data"}) tree.add(["bl"]) tree = WorkingTree.open("dc") self.assertEquals(set(), tree.filter_unversioned_files(["bl"]))
def test_commit_metadata(self): self.make_checkout(self.repos_url, "dc") wt = WorkingTree.open("dc") self.build_tree({'dc/foo/bla': "data", 'dc/bla': "otherdata"}) wt.add('bla') wt.branch.get_config().set_user_option("allow_metadata_in_file_properties", "True") wt.commit(message="data") branch = Branch.open(self.repos_url) branch.lock_write() self.addCleanup(branch.unlock) builder = branch.get_commit_builder([branch.last_revision()], timestamp=4534.0, timezone=2, committer="fry", revision_id="my-revision-id") tree = branch.repository.revision_tree(branch.last_revision()) list(builder.record_iter_changes(tree, branch.last_revision(), [])) builder.finish_inventory() builder.commit("foo") self.assertEqual("3 my-revision-id\n", self.client_get_prop("dc", "bzr:revision-id:v3-none", 2)) self.assertEqual( "timestamp: 1970-01-01 01:15:36.000000000 +0000\ncommitter: fry\n", self.client_get_prop("dc", "bzr:revision-info", 2))
def test_content_filtering_applied_on_merge(self): # Create a source branch with two revisions source, path1, path2, path3, path4 = \ self.create_cf_tree_with_two_revisions(txt_reader=None, txt_writer=None, dir='source') if not source.supports_content_filtering(): return self.assert_basis_content(b"Foo ROCKS!", source, path1) self.assertFileEqual(b"Foo ROCKS!", 'source/file1.txt') self.assert_basis_content(b"Foo Bin", source, path2) self.assert_basis_content(b"Hello World", source, path4) self.assertFileEqual(b"Hello World", 'source/file4.txt') # Now patch in content filtering and branch from revision 1 self.patch_in_content_filter() self.run_bzr('branch -r1 source target') target = WorkingTree.open('target') self.assert_basis_content(b"Foo Txt", target, path1) self.assertFileEqual(b"fOO tXT", 'target/file1.txt') self.assertFileEqual(b"Foo Bin", 'target/file2.bin') self.assertFileEqual(b"bAR tXT", 'target/file3.txt') # Merge the latter change and check the target tree is updated self.run_bzr('merge -d target source') self.assertFileEqual(b"fOO rocks!", 'target/file1.txt') self.assertFileEqual(b"hELLO wORLD", 'target/file4.txt') # Commit the merge and check the right content is stored target.commit("merge file1.txt changes from source") self.assert_basis_content(b"Foo ROCKS!", target, path1) self.assert_basis_content(b"Hello World", target, path4)
def get_tree_with_loom(self, path="."): """Get a tree with no commits in loom format.""" # May open on Remote - we want the vfs backed version for loom tests. self.make_branch_and_tree(path) tree = WorkingTree.open(path) breezy.plugins.loom.branch.loomify(tree.branch) return tree.controldir.open_workingtree()
def test_branch_push_pull_merge_copies_tags(self): t = self.make_branch_and_tree('branch1') t.commit(allow_pointless=True, message='initial commit', rev_id=b'first-revid') b1 = t.branch b1.tags.set_tag('tag1', b'first-revid') # branching copies the tag across self.run_bzr('branch branch1 branch2') b2 = Branch.open('branch2') self.assertEqual(b2.tags.lookup_tag('tag1'), b'first-revid') # make a new tag and pull it b1.tags.set_tag('tag2', b'twa') self.run_bzr('pull -d branch2 branch1') self.assertEqual(b2.tags.lookup_tag('tag2'), b'twa') # make a new tag and push it b1.tags.set_tag('tag3', b'san') self.run_bzr('push -d branch1 branch2') self.assertEqual(b2.tags.lookup_tag('tag3'), b'san') # make a new tag and merge it t.commit(allow_pointless=True, message='second commit', rev_id=b'second-revid') t2 = WorkingTree.open('branch2') t2.commit(allow_pointless=True, message='commit in second') b1.tags.set_tag('tag4', b'second-revid') self.run_bzr('merge -d branch2 branch1') self.assertEqual(b2.tags.lookup_tag('tag4'), b'second-revid') # pushing to a new location copies the tag across self.run_bzr('push -d branch1 branch3') b3 = Branch.open('branch3') self.assertEqual(b3.tags.lookup_tag('tag1'), b'first-revid')
def test_export_loom_as_tree(self): tree = self.get_multi_threaded() tree.branch.controldir.root_transport.mkdir('root') root_transport = tree.branch.controldir.root_transport.clone('root') tree.branch.export_threads(root_transport) export_tree = WorkingTree.open(root_transport.local_abspath('thread1')) self.assertEqual(b'thread1-id', export_tree.last_revision())
def test_set_and_get_view_info(self): wt = self.make_branch_and_tree('wt') view_current = 'view-name' view_dict = { view_current: ['dir-1'], 'other-name': ['dir-2']} wt.views.set_view_info(view_current, view_dict) current, views = wt.views.get_view_info() self.assertEqual(view_current, current) self.assertEqual(view_dict, views) # then reopen the tree and see they're still there wt = WorkingTree.open('wt') current, views = wt.views.get_view_info() self.assertEqual(view_current, current) self.assertEqual(view_dict, views) # test setting a current view which does not exist self.assertRaises(_mod_views.NoSuchView, wt.views.set_view_info, 'yet-another', view_dict) current, views = wt.views.get_view_info() self.assertEqual(view_current, current) self.assertEqual(view_dict, views) # test clearing the current view wt.views.set_view_info(None, view_dict) current, views = wt.views.get_view_info() self.assertEqual(None, current) self.assertEqual(view_dict, views)
def test_fetch_fetches_signatures_too(self): if not self.repository_format.supports_revision_signatures: raise TestNotApplicable( 'from repository does not support signatures') if not self.repository_format_to.supports_revision_signatures: raise TestNotApplicable( 'to repository does not support signatures') # and sign 'rev2' tree_a = WorkingTree.open('a') tree_a.branch.repository.lock_write() tree_a.branch.repository.start_write_group() tree_a.branch.repository.sign_revision(self.rev2, breezy.gpg.LoopbackGPGStrategy(None)) tree_a.branch.repository.commit_write_group() tree_a.branch.repository.unlock() from_repo = self.controldir.open_repository() from_signature = from_repo.get_signature_text(self.rev2) to_repo = self.make_to_repository('target') try: to_repo.fetch(from_repo) except errors.NoRoundtrippingSupport: raise TestNotApplicable('interrepo does not support roundtripping') to_signature = to_repo.get_signature_text(self.rev2) self.assertEqual(from_signature, to_signature)
def test_file_id_kept(self): tree = self.make_svn_branch_and_tree('a', 'dc') self.build_tree({'dc/file': 'data'}) tree.add(["file"], ["fooid"]) self.assertEqual("fooid", tree.path2id("file")) tree = WorkingTree.open("dc") self.assertEqual("fooid", tree.path2id("file"))
def prepare_wt(self, path): repo_url = self.make_svn_repository(os.path.join("repo", path)) with self.get_commit_editor(repo_url) as dc: dc.add_dir("trunk") self.make_checkout(repo_url+"/trunk", path) return WorkingTree.open(path)
def test_special_char(self): self.requireFeature(UnicodeFilenameFeature) self.make_svn_branch_and_tree('a', 'dc') self.build_tree({u"dc/I²C": "data"}) self.client_add("dc/I²C") tree = WorkingTree.open("dc") self.assertEquals(set(), tree.filter_unversioned_files([u"I²C"]))
def test_branch_with_nested_trees(self): orig = self.make_branch_and_tree('source', format='development-subtree') subtree = self.make_branch_and_tree('source/subtree') self.build_tree(['source/subtree/a']) subtree.add(['a']) subtree.commit('add subtree contents') orig.add_reference(subtree) orig.set_reference_info('subtree', subtree.branch.user_url) orig.commit('add subtree') self.run_bzr('branch source target') target = WorkingTree.open('target') target_subtree = WorkingTree.open('target/subtree') self.assertTreesEqual(orig, target) self.assertTreesEqual(subtree, target_subtree)
def test_branch_stacked_branch_stacked(self): """Asking to stack on a stacked branch does work""" # We have a mainline trunk_tree = self.make_branch_and_tree('target', format='1.9') trunk_revid = trunk_tree.commit('mainline') # and a branch from it which is stacked branch_tree = self.make_branch_and_tree('branch', format='1.9') branch_tree.branch.set_stacked_on_url(trunk_tree.branch.base) # with some work on it work_tree = trunk_tree.branch.controldir.sprout( 'local').open_workingtree() branch_revid = work_tree.commit('moar work plz') work_tree.branch.push(branch_tree.branch) # you can chain branches on from there out, err = self.run_bzr(['branch', 'branch', '--stacked', 'branch2']) self.assertEqual('', out) self.assertEqual( 'Created new stacked branch referring to %s.\n' % branch_tree.branch.base, err) self.assertEqual(branch_tree.branch.base, branch.Branch.open('branch2').get_stacked_on_url()) branch2_tree = WorkingTree.open('branch2') branch2_revid = work_tree.commit('work on second stacked branch') work_tree.branch.push(branch2_tree.branch) self.assertRevisionInRepository('branch2', branch2_revid) self.assertRevisionsInBranchRepository( [trunk_revid, branch_revid, branch2_revid], 'branch2')
def test_create_branch(self): branch = self.make_branch('branch') tree = branch.create_checkout('tree', lightweight=True) tree.commit('one', rev_id=b'rev-1') self.run_bzr('switch --create-branch ../branch2', working_dir='tree') tree = WorkingTree.open('tree') self.assertEndsWith(tree.branch.base, '/branch2/')
def test_remove_with_new_in_dir1(self): tree = self._make_tree_and_add(files) self.run_bzr('remove --new --keep b b/c', error_regexes=["removed b", "removed b/c"]) tree = WorkingTree.open('.') self.assertInWorkingTree(a) self.assertEqual(tree.path2id(a), a.encode('utf-8') + _id) self.assertFilesUnversioned([b, c])
def test_file_id_consistent(self): tree = self.make_svn_branch_and_tree('a', 'dc') self.build_tree({'dc/file': 'data'}) tree.add(["file"]) oldid = tree.path2id("file") tree = WorkingTree.open("dc") newid = tree.path2id("file") self.assertEqual(oldid, newid)
def move_upstream_changes_to_patch( local_tree: WorkingTree, basis_tree: Tree, subpath: str, patch_name: str, description: str, dirty_tracker=None, timestamp: Optional[datetime] = None, ) -> Tuple[List[str], str]: """Move upstream changes to patch. Args: local_tree: local tree subpath: subpath patch_name: Suggested patch name description: Description dirty_tracker: Dirty tracker """ if timestamp is None: timestamp = datetime.now() diff = BytesIO() show_diff_trees(basis_tree, local_tree, diff) reset_tree(local_tree, basis_tree, subpath, dirty_tracker) header = Message() lines = description.splitlines() # See https://dep-team.pages.debian.net/deps/dep3/ for fields. header["Description"] = (lines[0] + "\n" + "\n".join([(" " + line) if line else " ." for line in lines[1:]])) header["Origin"] = "other" header["Last-Update"] = timestamp.strftime("%Y-%m-%d") patches_directory = tree_patches_directory(local_tree, subpath) patchname = add_patch( local_tree, os.path.join(subpath, patches_directory), patch_name, diff.getvalue(), header, ) specific_files = [ os.path.join(subpath, patches_directory), os.path.join(subpath, patches_directory, "series"), os.path.join(subpath, patches_directory, patchname), ] local_tree.add(specific_files) return specific_files, patchname
def make_svn_branch_and_tree(self, repospath, clientpath, allow_revprop_changes=True, lossy=False): branch = self.make_svn_branch(repospath, lossy=lossy) self.make_checkout(branch.base, clientpath) return WorkingTree.open(clientpath)
def test_file_remove_id(self): tree = self.make_svn_branch_and_tree('a', 'dc') self.build_tree({'dc/file': 'data'}) tree.add(["file"], ["fooid"]) tree.commit("msg") tree.remove(["file"]) self.assertEqual(None, tree.path2id("file")) tree = WorkingTree.open("dc") self.assertEqual(None, tree.path2id("file"))
def test_create_branch_short_name(self): branch = self.make_branch('branch') tree = branch.create_checkout('tree', lightweight=True) tree.commit('one', rev_id=b'rev-1') self.run_bzr('switch -b branch2', working_dir='tree') tree = WorkingTree.open('tree') # The new branch should have been created at the same level as # 'branch', because we did not have a '/' segment self.assertEqual(branch.base[:-1] + '2/', tree.branch.base)
def test_commit_nested(self): repos_url = self.make_client('a', 'dc') self.build_tree({"dc/branches/foobranch/file": "data"}) self.client_add("dc/branches") self.client_commit("dc", "initial changes") self.make_checkout(repos_url + "/branches/foobranch", "de") tree = WorkingTree.open("de") self.build_tree({'de/file': "foo"}) tree.basis_tree() tree.commit(message="data")
def test_get_file_properties(self): repos_url = self.make_client('a', 'dc') self.build_tree({"dc/bla": b"data"}) self.client_add("dc/bla") self.client_set_prop("dc/bla", "bzrbla", "bloe") self.client_commit('dc', 'msg') self.client_set_prop("dc/bla", "bzrbla", "bloe2") t = WorkingTree.open('dc').basis_tree() props = t.get_file_properties('bla') self.assertEquals("bloe", props["bzrbla"])