in pontoon/sync/repositories/git.py [0:0]
def update(source: str, target: str, branch: str | None, shallow: bool) -> None:
log.debug(f"Git: Updating repo {source}")
if branch and re.search(r"[^%&()+,\-./0-9;<=>@A-Z_a-z{|}]|^-|\.\.|{@", branch):
raise PullFromRepositoryException(f"Git: Unsupported branch name {branch}")
command = ["git", "rev-parse", "--is-shallow-repository"]
code, output, error = execute(command, target)
if code == 0:
command = (
["git", "fetch", "origin"]
if shallow or output.strip() == b"false"
else ["git", "fetch", "--unshallow", "origin"]
)
code, output, error = execute(command, target)
if code == 0:
log.debug("Git: Repo updated.")
if branch:
command = ["git", "checkout", branch]
code, output, error = execute(command, target)
if code != 0:
if output:
log.debug(output)
raise PullFromRepositoryException(error)
log.debug(f"Git: Branch {branch} checked out.")
# Undo any local changes
remote = f"origin/{branch}" if branch else "origin"
command = ["git", "reset", "--hard", remote]
code, output, error = execute(command, target)
if code != 0:
if output:
log.debug(output)
raise PullFromRepositoryException(error)
else:
if error != "No such file or directory":
if output:
log.debug(output)
log.warning(f"Git: {error}")
log.debug("Git: Cloning repo...")
command = ["git", "clone"]
if branch:
command.extend(["--branch", branch])
if shallow:
command.extend(["--depth", "1"])
command.extend([source, target])
code, output, error = execute(command)
if code != 0:
if output:
log.debug(output)
raise PullFromRepositoryException(error)
log.debug("Git: Repo cloned.")