mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-08 07:18:27 +01:00
We are currently using this [0] hack to work around the fact that item.name is not always a basename. Even though `IndexObject` has it defined that way [1], but `Submodule` - doesn't [2]. So using `item.name` might cause issues such as [3], because GitPython doesn't pass name parameter when simply going through objects [4]. In other places, when working specifically with submodules, it sets `_name` attribute explicitly [5]. Note that we still don't walk into submodules when walking through a git repo. Might want to reconsider that later as for now we haven't heard anything about it from actual users. Fixes #3481 [0] https://github.com/iterative/dvc/blob/0.90.0/dvc/scm/git/tree.py#L15 [1] https://github.com/gitpython-developers/GitPython/blob/3.1.0/git/objects/base.py#L170 [2] https://github.com/gitpython-developers/GitPython/blob/3.1.0/git/objects/submodule/base.py#L1123 [3] https://github.com/gitpython-developers/GitPython/issues/597 [4] https://github.com/gitpython-developers/GitPython/blob/3.1.0/git/objects/tree.py#L237 [5] https://github.com/gitpython-developers/GitPython/blob/3.1.0/git/objects/submodule/base.py#L357
40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
import os
|
|
|
|
from dvc.compat import fspath
|
|
|
|
from tests.basic_env import TestDvcGit
|
|
|
|
|
|
class TestGit(TestDvcGit):
|
|
def test_belongs_to_scm_true_on_gitignore(self):
|
|
path = os.path.join("path", "to", ".gitignore")
|
|
self.assertTrue(self.dvc.scm.belongs_to_scm(path))
|
|
|
|
def test_belongs_to_scm_true_on_git_internal(self):
|
|
path = os.path.join("path", "to", ".git", "internal", "file")
|
|
self.assertTrue(self.dvc.scm.belongs_to_scm(path))
|
|
|
|
def test_belongs_to_scm_false(self):
|
|
path = os.path.join("some", "non-.git", "file")
|
|
self.assertFalse(self.dvc.scm.belongs_to_scm(path))
|
|
|
|
|
|
def test_walk_with_submodules(tmp_dir, scm, git_dir):
|
|
git_dir.scm_gen(
|
|
{"foo": "foo", "bar": "bar", "dir": {"data": "data"}},
|
|
commit="add dir and files",
|
|
)
|
|
scm.repo.create_submodule("submodule", "submodule", url=fspath(git_dir))
|
|
scm.commit("added submodule")
|
|
|
|
files = []
|
|
dirs = []
|
|
tree = scm.get_tree("HEAD")
|
|
for _, dnames, fnames in tree.walk("."):
|
|
dirs.extend(dnames)
|
|
files.extend(fnames)
|
|
|
|
# currently we don't walk through submodules
|
|
assert not dirs
|
|
assert set(files) == {".gitmodules", "submodule"}
|