Skip to content

Commit

Permalink
out: str: don't try to relpath paths outside of the repo
Browse files Browse the repository at this point in the history
This is not very useful overall, but also results in a ValueError from
relpath on windows if your repo and output are on different drives.
  • Loading branch information
efiop committed Jul 25, 2023
1 parent 9c89841 commit 4d01171
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 3 additions & 0 deletions dvc/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,9 @@ def __str__(self):
):
return str(self.def_path)

if not self.fs.path.isin(self.fs_path, self.repo.root_dir):
return self.fs_path

cur_dir = self.fs.path.getcwd()
if self.fs.path.isin(cur_dir, self.repo.root_dir):
return self.fs.path.relpath(self.fs_path, cur_dir)
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/output/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from dvc.output import Output
from dvc.stage import Stage
from dvc.utils import relpath
from dvc_data.hashfile.hash_info import HashInfo
from dvc_data.hashfile.meta import Meta

Expand All @@ -11,7 +10,7 @@ def test_str_workdir_outside_repo(tmp_dir, erepo_dir):
stage = Stage(erepo_dir.dvc)
output = Output(stage, "path", cache=False)

assert relpath("path", erepo_dir.dvc.root_dir) == str(output)
assert os.path.abspath("path") == str(output)


def test_str_workdir_inside_repo(dvc):
Expand Down

0 comments on commit 4d01171

Please sign in to comment.