Skip to content

Commit df9f88d

Browse files
author
Deepak kudi
committed
Resolve get_url paths from explicit repo root
1 parent 06ff81c commit df9f88d

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

dvc/repo/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,15 +387,17 @@ def get_data_index_entry(
387387
path: str,
388388
workspace: str = "repo",
389389
) -> tuple["DataIndex", "DataIndexEntry"]:
390+
fs_path = path if self.fs.isabs(path) else self.fs.join(self.root_dir, path)
390391
if self.subrepos:
391-
fs_path = self.dvcfs.from_os_path(path)
392+
fs_path = self.dvcfs.from_os_path(fs_path)
393+
fs_path = self.dvcfs.join(self.dvcfs.root_marker, fs_path)
392394
fs = self.dvcfs.fs
393395
key = fs._get_key_from_relative(fs_path)
394396
subrepo, _, key = fs._get_subrepo_info(key)
395397
index = subrepo.index.data[workspace]
396398
else:
397399
index = self.index.data[workspace]
398-
key = self.fs.relparts(path, self.root_dir)
400+
key = self.fs.relparts(fs_path, self.root_dir)
399401

400402
try:
401403
return index, index[key]

tests/func/api/test_data.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,18 @@ def test_get_url_ignore_scm(tmp_dir, dvc, cloud, scm):
9494
api.get_url("foo", repo=repo_url, config={"core": {"no_scm": True}})
9595

9696

97+
def test_get_url_with_explicit_repo_from_subdir(tmp_dir, dvc, scm, cloud):
98+
tmp_dir.add_remote(config=cloud.config)
99+
tmp_dir.dvc_gen("foo", "foo", commit="add foo")
100+
(tmp_dir / "subdir").mkdir()
101+
102+
expected_url = (
103+
cloud / "files" / "md5" / "ac" / "bd18db4cc2f85cedef654fccc4a4d8"
104+
).url
105+
with (tmp_dir / "subdir").chdir():
106+
assert api.get_url("foo", repo=os.fspath(tmp_dir)) == expected_url
107+
108+
97109
def test_open_external(tmp_dir, erepo_dir, cloud):
98110
erepo_dir.add_remote(config=cloud.config)
99111

0 commit comments

Comments
 (0)