Skip to content

Commit

Permalink
fix: update already present repositories
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Selwyn-Smith <[email protected]>
  • Loading branch information
benmss committed Dec 19, 2024
1 parent 1ea1bd5 commit 90cd182
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/macaron/slsa_analyzer/git_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,27 @@ def clone_remote_repo(clone_dir: str, url: str) -> Repo | None:
os.rmdir(clone_dir)
logger.debug("The clone dir %s is empty. It has been deleted for cloning the repo.", clone_dir)
except OSError:
logger.debug(
"The clone dir %s is not empty. Cloning will not be proceeded.",
clone_dir,
)
return None
# If the repository has already been cloned, we attempt to update using `git pull`.
try:
git_env_patch = {
# Setting the GIT_TERMINAL_PROMPT environment variable to ``0`` stops
# ``git clone`` from prompting for login credentials.
"GIT_TERMINAL_PROMPT": "0",
}
subprocess.run( # nosec B603
args=["git", "pull"],
capture_output=True,
cwd=clone_dir,
# If `check=True` and return status code is not zero, subprocess.CalledProcessError is
# raised, which we don't want. We want to check the return status code of the subprocess
# later on.
check=False,
env=get_patched_env(git_env_patch),
)
return Repo(path=clone_dir)
except (subprocess.CalledProcessError, OSError):
logger.debug("The clone dir %s is not empty. An attempt to update it failed.")
return None

# Ensure that the parent directory where the repo is cloned into exists.
parent_dir = Path(clone_dir).parent
Expand Down

0 comments on commit 90cd182

Please sign in to comment.