@@ -44,67 +44,23 @@ def clone_repo(repository: str, session_id: str, session_type: str = "session")
4444 raise RuntimeError ("GITHUB_TOKEN environment variable not set" )
4545
4646 base_path = Path (os .environ .get ("HOME" , "/mnt/efs" )) / "repos"
47- cache_path = base_path / repository .replace ("/" , "_" )
4847 session_path = base_path / f"{ session_type } -{ session_id } " / repository
4948
5049 base_path .mkdir (parents = True , exist_ok = True )
5150 session_path .parent .mkdir (parents = True , exist_ok = True )
5251
5352 cleanup_old_sessions (base_path )
5453
55- clone_url = f"https://x-access-token:{ github_token } @github.com/{ repository } .git"
56-
57- if cache_path .exists () and (cache_path / ".git" ).exists ():
58- logger .info (f"Found cached repo at { cache_path } , copying to { session_path } " )
59- try :
60- if session_path .exists ():
61- shutil .rmtree (session_path )
62- shutil .copytree (cache_path , session_path )
63-
64- configure_git_auth (str (session_path ))
65-
66- subprocess .run (
67- ["git" , "fetch" , "origin" ],
68- cwd = str (session_path ),
69- check = True ,
70- capture_output = True ,
71- text = True ,
72- )
73- subprocess .run (
74- ["git" , "reset" , "--hard" , "origin/HEAD" ],
75- cwd = str (session_path ),
76- check = True ,
77- capture_output = True ,
78- text = True ,
79- )
80- logger .info (f"Successfully reused cached repo and updated to latest" )
81- except Exception as e :
82- logger .warning (f"Failed to reuse cache: { e } , will clone fresh" )
83- if session_path .exists ():
84- shutil .rmtree (session_path )
85- _clone_fresh (clone_url , session_path , repository )
86- configure_git_auth (str (session_path ))
87- else :
88- logger .info (f"No cache found, cloning fresh into { session_path } " )
89- _clone_fresh (clone_url , session_path , repository )
90- configure_git_auth (str (session_path ))
91-
92- try :
93- if cache_path .exists ():
94- shutil .rmtree (cache_path )
95- shutil .copytree (session_path , cache_path )
96- logger .info (f"Cached repo for future use at { cache_path } " )
97- except Exception as e :
98- logger .warning (f"Failed to create cache: { e } , continuing without cache" )
99-
100- return str (session_path )
54+ if session_path .exists ():
55+ logger .info (f"Removing existing session path: { session_path } " )
56+ shutil .rmtree (session_path )
10157
58+ clone_url = f"https://x-access-token:{ github_token } @github.com/{ repository } .git"
10259
103- def _clone_fresh (clone_url : str , repo_path : Path , repository : str ) -> None :
104- """Helper to clone a repository from scratch."""
60+ logger .info (f"Cloning { repository } into { session_path } " )
10561 try :
10662 subprocess .run (
107- ["git" , "clone" , clone_url , str (repo_path )],
63+ ["git" , "clone" , clone_url , str (session_path )],
10864 check = True ,
10965 capture_output = True ,
11066 text = True ,
@@ -114,6 +70,10 @@ def _clone_fresh(clone_url: str, repo_path: Path, repository: str) -> None:
11470 logger .error (f"Failed to clone repository: { e .stderr } " )
11571 raise RuntimeError (f"Failed to clone { repository } : { e .stderr } " )
11672
73+ configure_git_auth (str (session_path ))
74+
75+ return str (session_path )
76+
11777
11878def configure_git_auth (repo_path : str ) -> None :
11979 """Configure git user for the repository."""
0 commit comments