1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-02 19:32:19 +01:00

Allow cloning/fetching Github PR branches in external_components (#2639)

This commit is contained in:
Jesse Hills
2021-10-29 07:12:05 +13:00
committed by GitHub
parent 0d3e6b2c4c
commit 73accf747f
2 changed files with 25 additions and 9 deletions

View File

@@ -40,15 +40,23 @@ def clone_or_update(
) -> Path:
key = f"{url}@{ref}"
repo_dir = _compute_destination_path(key, domain)
fetch_pr_branch = ref.startswith("pull/")
if not repo_dir.is_dir():
_LOGGER.info("Cloning %s", key)
_LOGGER.debug("Location: %s", repo_dir)
cmd = ["git", "clone", "--depth=1"]
if ref is not None:
if ref is not None and not fetch_pr_branch:
cmd += ["--branch", ref]
cmd += ["--", url, str(repo_dir)]
run_git_command(cmd)
if fetch_pr_branch:
# We need to fetch the PR branch first, otherwise git will complain
# about missing objects
_LOGGER.info("Fetching %s", ref)
run_git_command(["git", "fetch", "--", "origin", ref], str(repo_dir))
run_git_command(["git", "reset", "--hard", "FETCH_HEAD"], str(repo_dir))
else:
# Check refresh needed
file_timestamp = Path(repo_dir / ".git" / "FETCH_HEAD")