22import os
33import subprocess
44
5+ from git import Repo as GitRepo
6+
7+ from codegen .git .utils .remote_progress import CustomRemoteProgress
58from codegen .shared .performance .stopwatch_utils import subprocess_with_stopwatch
69
710logger = logging .getLogger (__name__ )
811
912
10- # TODO: update to use GitPython instead + move into LocalRepoOperator
13+ # TODO: move into LocalRepoOperator
1114def 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