Skip to content

Commit d38d194

Browse files
chore: CG-732 use git python to clone repo (#427)
1 parent e229453 commit d38d194

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

src/codegen/git/utils/clone.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
import os
33
import subprocess
44

5+
from git import Repo as GitRepo
6+
7+
from codegen.git.utils.remote_progress import CustomRemoteProgress
58
from codegen.shared.performance.stopwatch_utils import subprocess_with_stopwatch
69

710
logger = logging.getLogger(__name__)
811

912

10-
# TODO: update to use GitPython instead + move into LocalRepoOperator
13+
# TODO: move into LocalRepoOperator
1114
def clone_repo(
1215
repo_path: str,
1316
clone_url: str,
@@ -22,14 +25,7 @@ def clone_repo(
2225
delete_command = f"rm -rf {repo_path}"
2326
logger.info(f"Deleting existing clone with command: {delete_command}")
2427
subprocess.run(delete_command, shell=True, capture_output=True)
25-
26-
if shallow:
27-
clone_command = f"""git clone --depth 1 {clone_url} {repo_path}"""
28-
else:
29-
clone_command = f"""git clone {clone_url} {repo_path}"""
30-
logger.info(f"Cloning with command: {clone_command} ...")
31-
subprocess_with_stopwatch(clone_command, shell=True, capture_output=True)
32-
# TODO: if an error raise or return None rather than silently failing
28+
GitRepo.clone_from(url=clone_url, to_path=repo_path, depth=1 if shallow else None, progress=CustomRemoteProgress())
3329
return repo_path
3430

3531

@@ -44,12 +40,7 @@ def clone_or_pull_repo(
4440
pull_repo(clone_url=clone_url, repo_path=repo_path)
4541
else:
4642
logger.info(f"{repo_path} directory does not exist running git clone ...")
47-
if shallow:
48-
clone_command = f"""git clone --depth 1 {clone_url} {repo_path}"""
49-
else:
50-
clone_command = f"""git clone {clone_url} {repo_path}"""
51-
logger.info(f"Cloning with command: {clone_command} ...")
52-
subprocess_with_stopwatch(command=clone_command, command_desc=f"clone {repo_path}", shell=True, capture_output=True)
43+
clone_repo(repo_path=repo_path, clone_url=clone_url, shallow=shallow)
5344
return repo_path
5445

5546

0 commit comments

Comments
 (0)