From a8ff7295982ea2c9fd1c3fda9af14d4d9d2bba28 Mon Sep 17 00:00:00 2001 From: Andrew Halberstadt Date: Tue, 12 Aug 2025 14:44:55 -0400 Subject: [PATCH] fix: fallback to guessing repo root in config.py We made the repo root detection smarter by using util/vcs.py to search for the `.git` directory. However, this broke a MacOS build task in Gecko CI because no `.git` directory exists. I'm not entirely sure why that happens, as the Taskgraph command still needs to run from the repo root. Ay any rate, this patch re-adds the old logic as a fallback in the event util/vcs.py wasn't able to detect the repo. --- src/taskgraph/config.py | 14 ++++++++++---- test/test_config.py | 12 ++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/taskgraph/config.py b/src/taskgraph/config.py index c5ae48375..6c55cb8ed 100644 --- a/src/taskgraph/config.py +++ b/src/taskgraph/config.py @@ -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): diff --git a/test/test_config.py b/test/test_config.py index cbde9b3ff..4392e35ba 100644 --- a/test/test_config.py +++ b/test/test_config.py @@ -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