Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #313 from crazy4pi314/fix-checkout-branch
Browse files Browse the repository at this point in the history
passing checkout option to update_repo, add docs
  • Loading branch information
kjaymiller authored Dec 13, 2023
2 parents 0b15622 + 0e04a44 commit 5fc0c5d
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions tools/update_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def update_repo(
repo:str,
path: pathlib.Path,
branch:str="cruft/update",
checkout_branch:str|None=None,
checkout:str|None=None,
submit_pr:bool=True,
**kwargs) -> None:
"""
Expand All @@ -145,23 +145,30 @@ def update_repo(
path (pathlib.Path): The parent folder where the will be saved.
branch (str): The name of the branch to create and push to.
Defaults to cruft/update.
checkout (str): The name of the branch to checkout from repo to update.
**kwargs: Additional keyword arguments to pass to cruft.update as
"""
# console = console.Console()
per_file_formatter = logging.Formatter(f'%(asctime)s - {repo} - %(levelname)s - %(message)s')
file_handler.setFormatter(per_file_formatter)
url = f"[email protected]:Azure-Samples/{repo}.git"
logger.info(f"Cloning from GitHub from {url}")
logger.info(f"Cloning {checkout} branch from GitHub from {url}")
path = path.joinpath(repo)

try:
subprocess.check_output(
["git", "clone", url],
cwd=path.parent,
)
if checkout is not None:
subprocess.check_output(
["git", "clone", "-b", checkout, url],
cwd=path.parent,
)
else:
subprocess.check_output(
["git", "clone", url],
cwd=path.parent,
)

except subprocess.CalledProcessError as e:
logging.warning(f"Could not to clone {url}: {e}.\nThis is likely a non-existent repo.")
logging.warning(f"Could not to clone {checkout} branch on {url}: {e}.\nThis is likely a non-existent repo or branch.")
return None

subprocess.check_output(
Expand All @@ -174,7 +181,7 @@ def update_repo(
path,
skip_apply_ask=True,
extra_context=kwargs,
checkout=checkout_branch if checkout_branch else None,
checkout=checkout if checkout else None,
)

if not subprocess.check_output(
Expand Down Expand Up @@ -243,7 +250,7 @@ def update_repos(
logger.info(f"Found {len(patterns)} repos matching \"{pattern}\"\n{patterns_str}")

for repo in patterns:
update_repo(repo=repo, path=path, branch=branch)
update_repo(repo=repo, path=path, branch=branch, checkout=checkout)

if __name__ == "__main__":
app()

0 comments on commit 5fc0c5d

Please sign in to comment.