예제 #1
0
    def test_gitignore_should_append_newline_to_gitignore(self, git, repo_dir):
        git = Git(repo_dir._root_dir)

        foo_ignore_pattern = "/foo"
        bar_ignore_pattern = "/bar"
        bar_path = os.path.join(repo_dir._root_dir, repo_dir.BAR)
        gitignore = os.path.join(repo_dir._root_dir, Git.GITIGNORE)

        with open(gitignore, "w") as fobj:
            fobj.write(foo_ignore_pattern)

        with open(gitignore, "r") as fobj:
            last = fobj.readlines()[-1]
        assert not last.endswith("\n")

        git.ignore(bar_path)

        with open(gitignore, "r") as fobj:
            lines = list(fobj.readlines())

        assert len(lines) == 2
        for l in lines:
            assert l.endswith("\n")

        assert lines[0].strip() == foo_ignore_pattern
        assert lines[1].strip() == bar_ignore_pattern
예제 #2
0
파일: test_scm.py 프로젝트: rpip/dvc
    def test_get_gitignore_ignorefile_dir_upper_level(self):
        git = Git(self._root_dir)

        file_double_dir = os.path.join("dir1", "dir2", "file1")
        data_dir1 = os.path.join(self._root_dir, file_double_dir)
        ignore_file_dir = os.path.realpath(os.path.join("aa", "bb"))

        with self.assertRaises(FileNotInTargetSubdirError):
            git._get_gitignore(data_dir1, ignore_file_dir)
예제 #3
0
    def test_get_gitignore(self, git, repo_dir):
        data_dir = os.path.join(repo_dir._root_dir, "file1")
        entry, gitignore = Git(repo_dir._root_dir)._get_gitignore(data_dir)
        assert entry == "/file1"
        assert gitignore == os.path.join(repo_dir._root_dir, Git.GITIGNORE)

        data_dir = os.path.join(repo_dir._root_dir, "dir")
        entry, gitignore = Git(repo_dir._root_dir)._get_gitignore(data_dir)

        assert entry == "/dir"
        assert gitignore == os.path.join(repo_dir._root_dir, Git.GITIGNORE)
예제 #4
0
파일: test_scm.py 프로젝트: rpip/dvc
    def test_get_gitignore_subdir(self):
        data_dir = os.path.join(self._root_dir, os.path.join("dir1", "file1"))
        entry, gitignore = Git(self._root_dir)._get_gitignore(data_dir)
        self.assertEqual(entry, "/file1")
        self.assertEqual(gitignore,
                         os.path.join(self._root_dir, "dir1", Git.GITIGNORE))

        data_dir = os.path.join(self._root_dir, os.path.join("dir1", "dir2"))
        entry, gitignore = Git(self._root_dir)._get_gitignore(data_dir)
        self.assertEqual(entry, "/dir2")
        self.assertEqual(gitignore,
                         os.path.join(self._root_dir, "dir1", Git.GITIGNORE))
예제 #5
0
 def test_get_gitignore_symlink(self, git, repo_dir):
     link = os.path.join(repo_dir.root_dir, "link")
     target = os.path.join(repo_dir.root_dir, repo_dir.DATA_SUB)
     System.symlink(target, link)
     entry, gitignore = Git(repo_dir._root_dir)._get_gitignore(link)
     assert entry == "/link"
     assert gitignore == os.path.join(repo_dir.root_dir, Git.GITIGNORE)
예제 #6
0
파일: test_scm.py 프로젝트: rpip/dvc
    def test_get_gitignore_ignorefile_dir(self):
        git = Git(self._root_dir)

        file_double_dir = os.path.join("dir1", "dir2", "file1")
        data_dir1 = os.path.join(self._root_dir, file_double_dir)
        dir1_real1 = os.path.realpath("dir1")
        entry, gitignore = git._get_gitignore(data_dir1, dir1_real1)
        self.assertEqual(entry, "/dir2/file1")
        gitignore1 = os.path.join(self._root_dir, "dir1", Git.GITIGNORE)
        self.assertEqual(gitignore, gitignore1)

        triple_dir = os.path.join("dir1", "dir2", "dir3")
        data_dir2 = os.path.join(self._root_dir, triple_dir)
        dir1_real2 = os.path.realpath("dir1")
        entry, gitignore = git._get_gitignore(data_dir2, dir1_real2)
        self.assertEqual(entry, "/dir2/dir3")
        gitignore2 = os.path.join(self._root_dir, "dir1", Git.GITIGNORE)
        self.assertEqual(gitignore, gitignore2)
예제 #7
0
파일: test_scm.py 프로젝트: ye-man/dvc
    def test_get_gitignore_ignorefile_dir(self, git, repo_dir):
        git = Git(repo_dir._root_dir)

        file_double_dir = os.path.join("dir1", "dir2", "file1")
        data_dir1 = os.path.join(repo_dir._root_dir, file_double_dir)
        dir1_real1 = os.path.realpath("dir1")
        entry, gitignore = git._get_gitignore(data_dir1, dir1_real1)
        assert entry == "/dir2/file1"
        gitignore1 = os.path.join(repo_dir._root_dir, "dir1", Git.GITIGNORE)
        assert gitignore == gitignore1

        triple_dir = os.path.join("dir1", "dir2", "dir3")
        data_dir2 = os.path.join(repo_dir._root_dir, triple_dir)
        dir1_real2 = os.path.realpath("dir1")
        entry, gitignore = git._get_gitignore(data_dir2, dir1_real2)
        assert entry == "/dir2/dir3"
        gitignore2 = os.path.join(repo_dir._root_dir, "dir1", Git.GITIGNORE)
        assert gitignore == gitignore2
예제 #8
0
파일: test_scm.py 프로젝트: yustoris/dvc
    def test(self):
        git = Git(self._root_dir)

        git.ignore('foo')
        self.assertTrue(os.path.isfile(Git.GITIGNORE))
        self.assertEqual(self._count_gitignore(), 1)

        git.ignore('foo')
        self.assertEqual(self._count_gitignore(), 1)

        git.ignore_remove('foo')
        self.assertEqual(self._count_gitignore(), 0)
예제 #9
0
파일: test_scm.py 프로젝트: rpip/dvc
    def test_ignore(self):
        git = Git(self._root_dir)
        foo = os.path.join(self._root_dir, self.FOO)

        git.ignore(foo)
        self.assertTrue(os.path.isfile(Git.GITIGNORE))
        self.assertEqual(self._count_gitignore(), 1)

        git.ignore(foo)
        self.assertEqual(self._count_gitignore(), 1)

        git.ignore_remove(foo)
        self.assertEqual(self._count_gitignore(), 0)
예제 #10
0
def _git_checkout(repo_path, revision):
    from dvc.scm import Git

    git = Git(repo_path)
    try:
        git.checkout(revision)
    finally:
        git.close()
예제 #11
0
    def test_ignore(self, git, repo_dir):
        git = Git(repo_dir._root_dir)
        foo = os.path.join(repo_dir._root_dir, repo_dir.FOO)

        target = "/" + repo_dir.FOO

        git.ignore(foo)
        assert os.path.isfile(Git.GITIGNORE)
        assert self._count_gitignore_entries(target) == 1

        git.ignore(foo)
        assert os.path.isfile(Git.GITIGNORE)
        assert self._count_gitignore_entries(target) == 1

        git.ignore_remove(foo)
        assert self._count_gitignore_entries(target) == 0
예제 #12
0
    def test_gitignore_should_end_with_newline(self, git, repo_dir):
        git = Git(repo_dir._root_dir)

        foo = os.path.join(repo_dir._root_dir, repo_dir.FOO)
        bar = os.path.join(repo_dir._root_dir, repo_dir.BAR)
        gitignore = os.path.join(repo_dir._root_dir, Git.GITIGNORE)

        git.ignore(foo)

        with open(gitignore, "r") as fobj:
            last = fobj.readlines()[-1]

        assert last.endswith("\n")

        git.ignore(bar)

        with open(gitignore, "r") as fobj:
            last = fobj.readlines()[-1]

        assert last.endswith("\n")
예제 #13
0
 def test_commit_in_submodule(self):
     G = Git(self._root_dir)
     G.add(["foo"])
     G.commit("add")
     self.assertTrue("foo" in self.git.git.ls_files())
예제 #14
0
 def test_is_submodule(self):
     self.assertTrue(Git.is_submodule(os.curdir))
예제 #15
0
 def test_is_tracked(self):
     foo = os.path.abspath(self.FOO)
     G = Git(self._root_dir)
     G.add([self.FOO, self.UNICODE])
     self.assertTrue(G.is_tracked(foo))
     self.assertTrue(G.is_tracked(self.FOO))
     self.assertTrue(G.is_tracked(self.UNICODE))
     G.commit("add")
     self.assertTrue(G.is_tracked(foo))
     self.assertTrue(G.is_tracked(self.FOO))
     G.repo.index.remove([self.FOO], working_tree=True)
     self.assertFalse(G.is_tracked(foo))
     self.assertFalse(G.is_tracked(self.FOO))
     self.assertFalse(G.is_tracked("not-existing-file"))
예제 #16
0
 def test_commit(self):
     G = Git(self._root_dir)
     G.add(["foo"])
     G.commit("add")
     self.assertIn("foo", self.git.git.ls_files())
예제 #17
0
 def test_is_repo(self):
     self.assertTrue(Git.is_repo(os.curdir))
예제 #18
0
 def test_commit(self):
     G = Git(self._root_dir)
     G.add(['foo'])
     G.commit('add')
     self.assertTrue('foo' in self.git.git.ls_files())
예제 #19
0
 def test_ignore(self):
     Git(self._root_dir).ignore('foo')
     self.assertTrue(os.path.isfile(Git.GITIGNORE))
     self.assertTrue('foo' in open(Git.GITIGNORE, 'r').readlines())
예제 #20
0
def _clone_repo(url, path):
    from dvc.scm.git import Git

    git = Git.clone(url, path)
    git.close()