diff --git a/python/wpt/exporter/__init__.py b/python/wpt/exporter/__init__.py index c9b5e5d0285..b2df5675598 100644 --- a/python/wpt/exporter/__init__.py +++ b/python/wpt/exporter/__init__.py @@ -19,6 +19,7 @@ import dataclasses import json import logging import re +import shutil import subprocess from typing import Callable, Optional @@ -50,8 +51,12 @@ class LocalGitRepo: self.path = path self.sync = sync + # We pass env to subprocess, which may clobber PATH, so we need to find + # git in advance and run the subprocess by its absolute path. + self.git_path = shutil.which("git") + def run_without_encoding(self, *args, env: dict = {}): - command_line = ["git"] + list(args) + command_line = [self.git_path] + list(args) logging.info(" → Execution (cwd='%s'): %s", self.path, " ".join(command_line)) @@ -142,9 +147,9 @@ class WPTSync: suppress_force_push: bool = False def __post_init__(self): - self.servo = GithubRepository(self, self.servo_repo) - self.wpt = GithubRepository(self, self.wpt_repo) - self.downstream_wpt = GithubRepository(self, self.downstream_wpt_repo) + self.servo = GithubRepository(self, self.servo_repo, "main") + self.wpt = GithubRepository(self, self.wpt_repo, "master") + self.downstream_wpt = GithubRepository(self, self.downstream_wpt_repo, "master") self.local_servo_repo = LocalGitRepo(self.servo_path, self) self.local_wpt_repo = LocalGitRepo(self.wpt_path, self) diff --git a/python/wpt/exporter/github.py b/python/wpt/exporter/github.py index 08b491765be..824bcb997f4 100644 --- a/python/wpt/exporter/github.py +++ b/python/wpt/exporter/github.py @@ -55,9 +55,10 @@ class GithubRepository: This class allows interacting with a single GitHub repository. """ - def __init__(self, sync: WPTSync, repo: str): + def __init__(self, sync: WPTSync, repo: str, default_branch: str): self.sync = sync self.repo = repo + self.default_branch = default_branch self.org = repo.split("/")[0] self.pulls_url = f"repos/{self.repo}/pulls" @@ -105,7 +106,7 @@ class GithubRepository: data = { "title": title, "head": branch.get_pr_head_reference_for_repo(self), - "base": "main", + "base": self.default_branch, "body": body, "maintainer_can_modify": False, } diff --git a/python/wpt/exporter/step.py b/python/wpt/exporter/step.py index d56c4a3e852..9781353ce15 100644 --- a/python/wpt/exporter/step.py +++ b/python/wpt/exporter/step.py @@ -190,7 +190,7 @@ class CreateOrUpdateBranchForPRStep(Step): return branch_name finally: try: - run.sync.local_wpt_repo.run("checkout", "main") + run.sync.local_wpt_repo.run("checkout", "master") run.sync.local_wpt_repo.run("branch", "-D", branch_name) except Exception: pass diff --git a/python/wpt/test.py b/python/wpt/test.py index f30e01eb79c..742796035c6 100644 --- a/python/wpt/test.py +++ b/python/wpt/test.py @@ -644,17 +644,17 @@ def setUpModule(): suppress_force_push=True, ) - def setup_mock_repo(repo_name, local_repo): + def setup_mock_repo(repo_name, local_repo, default_branch: str): subprocess.check_output( ["cp", "-R", "-p", os.path.join(TESTS_DIR, repo_name), local_repo.path]) - local_repo.run("init", "-b", "main") + local_repo.run("init", "-b", default_branch) local_repo.run("add", ".") local_repo.run("commit", "-a", "-m", "Initial commit") logging.info("=" * 80) logging.info("Setting up mock repositories") - setup_mock_repo("servo-mock", SYNC.local_servo_repo) - setup_mock_repo("wpt-mock", SYNC.local_wpt_repo) + setup_mock_repo("servo-mock", SYNC.local_servo_repo, "main") + setup_mock_repo("wpt-mock", SYNC.local_wpt_repo, "master") logging.info("=" * 80)