Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/taskgraph/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,16 @@ def register(self):

@property
def vcs_root(self):
repo = get_repository(os.getcwd())
path = Path(repo.path)

return path
try:
repo = get_repository(os.getcwd())
return Path(repo.path)
except RuntimeError:
root = Path(self.root_dir)
if root.parts[-1:] != ("taskcluster",):
raise Exception(
"Not guessing path to vcs root. Graph config in non-standard location."
)
return root.parent

@property
def taskcluster_yml(self):
Expand Down
12 changes: 12 additions & 0 deletions test/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,15 @@ def test_vcs_root_with_non_standard_dir():
expected_path = Path("/path/to/repo")

assert vcs_root == expected_path


def test_vcs_root_fallback(mocker):
mocker.patch("os.getcwd", return_value="/path/to/repo")

cfg = {"foo": "bar"}
with mocker.patch("taskgraph.config.get_repository", side_effect=RuntimeError):
assert GraphConfig(cfg, "taskcluster").vcs_root == Path("/path/to/repo")

with mocker.patch("taskgraph.config.get_repository", side_effect=RuntimeError):
with pytest.raises(Exception):
GraphConfig(cfg, "root/data").vcs_root
Loading