Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions src/codegen/git/utils/clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -22,14 +25,7 @@
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())

Check failure on line 28 in src/codegen/git/utils/clone.py

View workflow job for this annotation

GitHub Actions / mypy

error: Argument "progress" to "clone_from" of "Repo" has incompatible type "CustomRemoteProgress"; expected "Callable[[int, str | float, str | float | None, str], None] | None" [arg-type]
return repo_path


Expand All @@ -44,12 +40,7 @@
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


Expand Down
Loading