Example #1
0
 def test_branch(self):
     scm = SCM(self._root_dir)
     scm.add([self.DATA_SUB_DIR])
     scm.commit("add data_dir/data_sub_dir/data_sub")
     tree = GitTree(self.git, "master")
     self.assertWalkEqual(
         tree.walk("."),
         [
             (self._root_dir, ["data_dir"], ["code.py"]),
             (join(self._root_dir, "data_dir"), ["data_sub_dir"], []),
             (
                 join(self._root_dir, "data_dir", "data_sub_dir"),
                 [],
                 ["data_sub"],
             ),
         ],
     )
     self.assertWalkEqual(
         tree.walk(join("data_dir", "data_sub_dir")),
         [(
             join(self._root_dir, "data_dir", "data_sub_dir"),
             [],
             ["data_sub"],
         )],
     )
Example #2
0
    def test_isfile(self):
        self.scm.add([self.FOO, self.DATA_DIR])
        self.scm.commit("add")

        tree = GitTree(self.git, "master")
        self.assertTrue(tree.isfile(self.FOO))
        self.assertFalse(tree.isfile(self.DATA_DIR))
        self.assertFalse(tree.isfile("not-existing-file"))
Example #3
0
    def get_tree(self, rev: str, **kwargs):
        from dvc.tree.git import GitTree

        from .objects import GitTrie

        resolved = self.resolve_rev(rev)
        tree_obj = self._backend_func("get_tree_obj", rev=resolved)
        trie = GitTrie(tree_obj, resolved)
        return GitTree(self.root_dir, trie, **kwargs)
Example #4
0
    def test_open(self):
        self.scm.add([self.FOO, self.UNICODE, self.DATA_DIR])
        self.scm.commit("add")

        tree = GitTree(self.git, "master")
        with tree.open(self.FOO) as fd:
            self.assertEqual(fd.read(), self.FOO_CONTENTS)
        with tree.open(self.UNICODE) as fd:
            self.assertEqual(fd.read(), self.UNICODE_CONTENTS)
        with self.assertRaises(IOError):
            tree.open("not-existing-file")
        with self.assertRaises(IOError):
            tree.open(self.DATA_DIR)
Example #5
0
 def setUp(self):
     super().setUp()
     self.scm = SCM(self._root_dir)
     self.tree = GitTree(self.git, "master")
     self._pushd(self._root_dir)
Example #6
0
File: git.py Project: hl-a-k/dvc
    def get_tree(self, rev, **kwargs):
        from dvc.tree.git import GitTree

        return GitTree(self.repo, self.resolve_rev(rev), **kwargs)
Example #7
0
    def test_exists(self):
        tree = GitTree(self.git, "master")
        self.assertFalse(tree.exists(self.FOO))
        self.assertFalse(tree.exists(self.UNICODE))
        self.assertFalse(tree.exists(self.DATA_DIR))
        self.scm.add([self.FOO, self.UNICODE, self.DATA])
        self.scm.commit("add")

        tree = GitTree(self.git, "master")
        self.assertTrue(tree.exists(self.FOO))
        self.assertTrue(tree.exists(self.UNICODE))
        self.assertTrue(tree.exists(self.DATA_DIR))
        self.assertFalse(tree.exists("non-existing-file"))