def tree_with_executable(self): tree = self.make_branch_and_tree('tree') tt = transform.TreeTransform(tree) tt.new_file('newfile', tt.root, [b'helooo!'], b'newfile-id', True) tt.apply() with tree.lock_write(): self.assertTrue(tree.is_executable('newfile')) tree.commit('added newfile') return tree
def test_revert_executable(self): tree = self.tree_with_executable() tt = transform.TreeTransform(tree) newfile = tt.trans_id_tree_path('newfile') tt.set_executability(False, newfile) tt.apply() tree.lock_write() self.addCleanup(tree.unlock) transform.revert(tree, tree.basis_tree(), None) self.assertTrue(tree.is_executable('newfile'))
def test_walkdirs_type_changes(self): """Walkdir shows the actual kinds on disk and the recorded kinds.""" self.requireFeature(SymlinkFeature) tree = self.make_branch_and_tree('.') paths = ['file1', 'file2', 'dir1/', 'dir2/'] self.build_tree(paths) tree.add(paths) tt = transform.TreeTransform(tree) root_transaction_id = tt.trans_id_tree_path('') tt.new_symlink('link1', root_transaction_id, 'link-target', b'link1') tt.new_symlink('link2', root_transaction_id, 'link-target', b'link2') tt.apply() tree.controldir.root_transport.delete_tree('dir1') tree.controldir.root_transport.delete_tree('dir2') tree.controldir.root_transport.delete('file1') tree.controldir.root_transport.delete('file2') tree.controldir.root_transport.delete('link1') tree.controldir.root_transport.delete('link2') changed_paths = ['dir1', 'file1/', 'link1', 'link2/'] self.build_tree(changed_paths) os.symlink('target', 'dir2') os.symlink('target', 'file2') dir1_stat = os.lstat('dir1') dir2_stat = os.lstat('dir2') file1_stat = os.lstat('file1') file2_stat = os.lstat('file2') link1_stat = os.lstat('link1') link2_stat = os.lstat('link2') expected_dirblocks = [(('', tree.path2id('')), [ ('dir1', 'dir1', 'file', dir1_stat, tree.path2id('dir1'), 'directory' if tree.has_versioned_directories() else None), ('dir2', 'dir2', 'symlink', dir2_stat, tree.path2id('dir2'), 'directory' if tree.has_versioned_directories() else None), ('file1', 'file1', 'directory', file1_stat, tree.path2id('file1'), 'file'), ('file2', 'file2', 'symlink', file2_stat, tree.path2id('file2'), 'file'), ('link1', 'link1', 'file', link1_stat, tree.path2id('link1'), 'symlink'), ('link2', 'link2', 'directory', link2_stat, tree.path2id('link2'), 'symlink'), ])] if tree.has_versioned_directories(): expected_dirblocks.extend([(('dir1', tree.path2id('dir1')), []), (('dir2', tree.path2id('dir2')), [])]) expected_dirblocks.extend([ (('file1', None), []), (('link2', None), []), ]) with tree.lock_read(): result = list(tree.walkdirs()) # check each return value for debugging ease. for pos, item in enumerate(expected_dirblocks): self.assertEqual(item, result[pos]) self.assertEqual(len(expected_dirblocks), len(result))
def get_tree_no_parents_abc_content_3(self, tree, converter=None): """return a test tree with a, b/, b/c contents. This variation changes the executable flag of b/c to True. """ self._make_abc_tree(tree) tt = transform.TreeTransform(tree) trans_id = tt.trans_id_tree_path('b/c') tt.set_executability(True, trans_id) tt.apply() return self._convert_tree(tree, converter)
def set_executability(wt, path, executable=True): """Set the executable bit for the file at path in the working tree os.chmod() doesn't work on windows. But TreeTransform can mark or unmark a file as executable. """ tt = transform.TreeTransform(wt) try: tt.set_executability(executable, tt.trans_id_tree_path(path)) tt.apply() finally: tt.finalize()
def get_tree_no_parents_abc_content_6(self, tree, converter=None): """return a test tree with a, b/, e contents. This variation renames b/c to e, and makes it executable. """ self._make_abc_tree(tree) tt = transform.TreeTransform(tree) trans_id = tt.trans_id_tree_path('b/c') parent_trans_id = tt.trans_id_tree_path('') tt.adjust_path('e', parent_trans_id, trans_id) tt.set_executability(True, trans_id) tt.apply() return self._convert_tree(tree, converter)
def get_tree_no_parents_abc_content_7(self, tree, converter=None): """return a test tree with a, b/, d/e contents. This variation adds a dir 'd' (b'd-id'), renames b to d/e. """ self._make_abc_tree(tree) self.build_tree(['d/'], transport=tree.controldir.root_transport) tree.add(['d']) tt = transform.TreeTransform(tree) trans_id = tt.trans_id_tree_path('b') parent_trans_id = tt.trans_id_tree_path('d') tt.adjust_path('e', parent_trans_id, trans_id) tt.apply() return self._convert_tree(tree, converter)
def test_preserve_execute(self): tree = self.tree_with_executable() tt = transform.TreeTransform(tree) newfile = tt.trans_id_tree_path('newfile') tt.delete_contents(newfile) tt.create_file([b'Woooorld!'], newfile) tt.apply() tree = workingtree.WorkingTree.open('tree') tree.lock_write() self.addCleanup(tree.unlock) self.assertTrue(tree.is_executable('newfile')) transform.revert(tree, tree.basis_tree(), None, backups=True) with tree.get_file('newfile', 'rb') as f: self.assertEqual(b'helooo!', f.read()) self.assertTrue(tree.is_executable('newfile'))
def test_file_content_summary_executable(self): tree = self.make_branch_and_tree('tree') self.build_tree(['tree/path']) tree.add(['path']) tt = transform.TreeTransform(tree) self.addCleanup(tt.finalize) tt.set_executability(True, tt.trans_id_tree_path('path')) tt.apply() summary = self._convert_tree(tree).path_content_summary('path') self.assertEqual(4, len(summary)) self.assertEqual('file', summary[0]) self.check_content_summary_size(tree, summary, 22) # executable self.assertEqual(True, summary[2]) # may have hash, self.assertSubset((summary[3], ), (None, b'0c352290ae1c26ca7f97d5b2906c4624784abd60'))
def get_tree_with_subdirs_and_all_supported_content_types(self, symlinks): """Return a test tree with subdirs and all supported content types. Some content types may not be created on some platforms (like symlinks on native win32) :param symlinks: control is symlink should be created in the tree. Note: if you wish to automatically set this parameters depending on underlying system, please use value returned by breezy.osutils.has_symlinks() function. The returned tree has the following inventory: ['', '0file', '1top-dir', u'2utf\u1234file', 'symlink', # only if symlinks arg is True '1top-dir/0file-in-1topdir', '1top-dir/1dir-in-1topdir'] where each component has the type of its name - i.e. '1file..' is afile. note that the order of the paths and fileids is deliberately mismatched to ensure that the result order is path based. """ self.requireFeature(features.UnicodeFilenameFeature) tree = self.make_branch_and_tree('.') paths = [ '0file', '1top-dir/', u'2utf\u1234file', '1top-dir/0file-in-1topdir', '1top-dir/1dir-in-1topdir/' ] self.build_tree(paths) tree.add(paths) tt = transform.TreeTransform(tree) if symlinks: root_transaction_id = tt.trans_id_tree_path('') tt.new_symlink('symlink', root_transaction_id, 'link-target', b'symlink') tt.apply() return self.workingtree_to_test_tree(tree)