示例#1
0
 def test_revert_executable(self):
     tree = self.tree_with_executable()
     tt = transform.TreeTransform(tree)
     newfile = tt.trans_id_tree_file_id('newfile-id')
     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-id'))
示例#2
0
    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)
示例#3
0
 def tree_with_executable(self):
     tree = self.make_branch_and_tree('tree')
     tt = transform.TreeTransform(tree)
     tt.new_file('newfile', tt.root, 'helooo!', 'newfile-id', True)
     tt.apply()
     tree.lock_write()
     try:
         self.assertTrue(tree.is_executable('newfile-id'))
         tree.commit('added newfile')
     finally:
         tree.unlock()
     return tree
示例#4
0
    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)
示例#5
0
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.
    """
    file_id = wt.path2id(path)
    tt = transform.TreeTransform(wt)
    try:
        tt.set_executability(executable, tt.trans_id_tree_file_id(file_id))
        tt.apply()
    finally:
        tt.finalize()
示例#6
0
 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/']
     ids = ['file1', 'file2', 'dir1', 'dir2']
     self.build_tree(paths)
     tree.add(paths, ids)
     tt = transform.TreeTransform(tree)
     root_transaction_id = tt.trans_id_tree_path('')
     tt.new_symlink('link1', root_transaction_id, 'link-target', 'link1')
     tt.new_symlink('link2', root_transaction_id, 'link-target', 'link2')
     tt.apply()
     tree.bzrdir.root_transport.delete_tree('dir1')
     tree.bzrdir.root_transport.delete_tree('dir2')
     tree.bzrdir.root_transport.delete('file1')
     tree.bzrdir.root_transport.delete('file2')
     tree.bzrdir.root_transport.delete('link1')
     tree.bzrdir.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, 'dir1', 'directory'),
             ('dir2', 'dir2', 'symlink', dir2_stat, 'dir2', 'directory'),
             ('file1', 'file1', 'directory', file1_stat, 'file1', 'file'),
             ('file2', 'file2', 'symlink', file2_stat, 'file2', 'file'),
             ('link1', 'link1', 'file', link1_stat, 'link1', 'symlink'),
             ('link2', 'link2', 'directory', link2_stat, 'link2',
              'symlink'),
         ]),
         (('dir1', 'dir1'), []),
         (('dir2', 'dir2'), []),
         (('file1', None), []),
         (('link2', None), []),
     ]
     tree.lock_read()
     result = list(tree.walkdirs())
     tree.unlock()
     # 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))
示例#7
0
    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' ('d-id'), renames b to d/e.
        """
        self._make_abc_tree(tree)
        self.build_tree(['d/'], transport=tree.bzrdir.root_transport)
        tree.add(['d'], ['d-id'])
        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)
示例#8
0
 def test_preserve_execute(self):
     tree = self.tree_with_executable()
     tt = transform.TreeTransform(tree)
     newfile = tt.trans_id_tree_file_id('newfile-id')
     tt.delete_contents(newfile)
     tt.create_file('Woooorld!', newfile)
     tt.apply()
     tree = workingtree.WorkingTree.open('tree')
     tree.lock_write()
     self.addCleanup(tree.unlock)
     self.assertTrue(tree.is_executable('newfile-id'))
     transform.revert(tree, tree.basis_tree(), None, backups=True)
     self.assertEqual('helooo!', tree.get_file('newfile-id').read())
     self.assertTrue(tree.is_executable('newfile-id'))
示例#9
0
 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, '0c352290ae1c26ca7f97d5b2906c4624784abd60'))
示例#10
0
    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 bzrlib.osutils.has_symlinks() function.

        The returned tree has the following inventory:
            [('', inventory.ROOT_ID),
             ('0file', '2file'),
             ('1top-dir', '1top-dir'),
             (u'2utf\u1234file', u'0utf\u1234file'),
             ('symlink', 'symlink'),            # only if symlinks arg is True
             ('1top-dir/0file-in-1topdir', '1file-in-1topdir'),
             ('1top-dir/1dir-in-1topdir', '0dir-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/'
        ]
        ids = [
            '2file', '1top-dir', u'0utf\u1234file'.encode('utf8'),
            '1file-in-1topdir', '0dir-in-1topdir'
        ]
        self.build_tree(paths)
        tree.add(paths, ids)
        tt = transform.TreeTransform(tree)
        if symlinks:
            root_transaction_id = tt.trans_id_tree_path('')
            tt.new_symlink('symlink', root_transaction_id, 'link-target',
                           'symlink')
        tt.apply()
        return self.workingtree_to_test_tree(tree)