Skip to content

Commit 29f22f8

Browse files
committed
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.
1 parent c50bc6a commit 29f22f8

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/taskgraph/config.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,16 @@ def register(self):
152152

153153
@property
154154
def vcs_root(self):
155-
repo = get_repository(os.getcwd())
156-
path = Path(repo.path)
157-
158-
return path
155+
try:
156+
repo = get_repository(os.getcwd())
157+
return Path(repo.path)
158+
except RuntimeError:
159+
root = Path(self.root_dir)
160+
if root.parts[-1:] != ("taskcluster",):
161+
raise Exception(
162+
"Not guessing path to vcs root. Graph config in non-standard location."
163+
)
164+
return root.parent
159165

160166
@property
161167
def taskcluster_yml(self):

test/test_config.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,15 @@ def test_vcs_root_with_non_standard_dir():
4848
expected_path = Path("/path/to/repo")
4949

5050
assert vcs_root == expected_path
51+
52+
53+
def test_vcs_root_fallback(mocker):
54+
mocker.patch("os.getcwd", return_value="/path/to/repo")
55+
56+
cfg = {"foo": "bar"}
57+
with mocker.patch("taskgraph.config.get_repository", side_effect=RuntimeError):
58+
assert GraphConfig(cfg, "taskcluster").vcs_root == Path("/path/to/repo")
59+
60+
with mocker.patch("taskgraph.config.get_repository", side_effect=RuntimeError):
61+
with pytest.raises(Exception):
62+
GraphConfig(cfg, "root/data").vcs_root

0 commit comments

Comments
 (0)