Fix git pulling on cached invalid git entry. On error, re-clone the entire repo again (disable using "agent.vcs_cache.clone_on_pull_fail: false")

This commit is contained in:
allegroai 2024-04-12 20:29:36 +03:00
parent 98cc0d86ba
commit 4179ac5234

View File

@ -777,7 +777,21 @@ def clone_repository_cached(session, execution, destination):
# We clone the entire repository, not a specific branch
vcs.clone() # branch=execution.branch)
vcs.pull()
print("pulling git")
try:
vcs.pull()
except Exception as ex:
if (
session.config.get("agent.vcs_cache.enabled", False) and
session.config.get("agent.vcs_cache.clone_on_pull_fail", True)
):
print("pulling git failed, re-cloning: {}".format(no_password_url))
rm_tree(cached_repo_path)
vcs.clone()
else:
raise ex
print("pulling git completed")
rm_tree(destination)
shutil.copytree(Text(cached_repo_path), Text(clone_folder),
symlinks=select_for_platform(linux=True, windows=False),