2
2
import os
3
3
import subprocess
4
4
5
+ from git import Repo as GitRepo
6
+
7
+ from codegen .git .utils .remote_progress import CustomRemoteProgress
5
8
from codegen .shared .performance .stopwatch_utils import subprocess_with_stopwatch
6
9
7
10
logger = logging .getLogger (__name__ )
8
11
9
12
10
- # TODO: update to use GitPython instead + move into LocalRepoOperator
13
+ # TODO: move into LocalRepoOperator
11
14
def clone_repo (
12
15
repo_path : str ,
13
16
clone_url : str ,
@@ -22,14 +25,7 @@ def clone_repo(
22
25
delete_command = f"rm -rf { repo_path } "
23
26
logger .info (f"Deleting existing clone with command: { delete_command } " )
24
27
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 ())
33
29
return repo_path
34
30
35
31
@@ -44,12 +40,7 @@ def clone_or_pull_repo(
44
40
pull_repo (clone_url = clone_url , repo_path = repo_path )
45
41
else :
46
42
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 )
53
44
return repo_path
54
45
55
46
0 commit comments