diff --git a/src/codegen/git/utils/clone.py b/src/codegen/git/utils/clone.py index a4e937458..8394beef3 100644 --- a/src/codegen/git/utils/clone.py +++ b/src/codegen/git/utils/clone.py @@ -2,12 +2,15 @@ import os import subprocess +from git import Repo as GitRepo + +from codegen.git.utils.remote_progress import CustomRemoteProgress from codegen.shared.performance.stopwatch_utils import subprocess_with_stopwatch logger = logging.getLogger(__name__) -# TODO: update to use GitPython instead + move into LocalRepoOperator +# TODO: move into LocalRepoOperator def clone_repo( repo_path: str, clone_url: str, @@ -22,14 +25,7 @@ def clone_repo( delete_command = f"rm -rf {repo_path}" logger.info(f"Deleting existing clone with command: {delete_command}") subprocess.run(delete_command, shell=True, capture_output=True) - - if shallow: - clone_command = f"""git clone --depth 1 {clone_url} {repo_path}""" - else: - clone_command = f"""git clone {clone_url} {repo_path}""" - logger.info(f"Cloning with command: {clone_command} ...") - subprocess_with_stopwatch(clone_command, shell=True, capture_output=True) - # TODO: if an error raise or return None rather than silently failing + GitRepo.clone_from(url=clone_url, to_path=repo_path, depth=1 if shallow else None, progress=CustomRemoteProgress()) return repo_path @@ -44,12 +40,7 @@ def clone_or_pull_repo( pull_repo(clone_url=clone_url, repo_path=repo_path) else: logger.info(f"{repo_path} directory does not exist running git clone ...") - if shallow: - clone_command = f"""git clone --depth 1 {clone_url} {repo_path}""" - else: - clone_command = f"""git clone {clone_url} {repo_path}""" - logger.info(f"Cloning with command: {clone_command} ...") - subprocess_with_stopwatch(command=clone_command, command_desc=f"clone {repo_path}", shell=True, capture_output=True) + clone_repo(repo_path=repo_path, clone_url=clone_url, shallow=shallow) return repo_path