Skip to content

Commit

Permalink
list: add support for tracked directories
Browse files Browse the repository at this point in the history
  • Loading branch information
efiop committed Jun 25, 2020
1 parent 5ac0a50 commit f4306b2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
6 changes: 3 additions & 3 deletions dvc/repo/ls.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ def _ls(repo, path_info, recursive=None, dvc_only=False):
def onerror(exc):
raise exc

# use our own RepoTree instance instead of repo.repo_tree since we do not
# want fetch/stream enabled for ls
tree = RepoTree(repo)
# use our own RepoTree instance instead of repo.repo_tree since we want to
# fetch directory listings, but don't want to fetch file contents.
tree = RepoTree(repo, stream=True)

ret = {}
try:
Expand Down
27 changes: 27 additions & 0 deletions tests/func/test_ls.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,3 +445,30 @@ def test_ls_shows_pipeline_tracked_outs(tmp_dir, dvc, scm, run_copy):

files = Repo.ls(os.curdir, dvc_only=True)
match_files(files, ((("bar",), True),))


def test_ls_granular(erepo_dir):
with erepo_dir.chdir():
erepo_dir.dvc_gen(
{
"dir": {
"1": "1",
"2": "2",
"subdir": {"foo": "foo", "bar": "bar"},
}
},
commit="create dir",
)

entries = Repo.ls(os.fspath(erepo_dir), os.path.join("dir", "subdir"))
assert entries == [
{"isout": False, "isdir": False, "isexec": False, "path": "bar"},
{"isout": False, "isdir": False, "isexec": False, "path": "foo"},
]

entries = Repo.ls(os.fspath(erepo_dir), "dir")
assert entries == [
{"isout": False, "isdir": False, "isexec": False, "path": "1"},
{"isout": False, "isdir": False, "isexec": False, "path": "2"},
{"isout": False, "isdir": True, "isexec": False, "path": "subdir"},
]

0 comments on commit f4306b2

Please sign in to comment.