@@ -35,7 +35,6 @@ async def setup(self):
3535 else :
3636 self .output_dir = self .scan .temp_dir / "git_repos"
3737 self .helpers .mkdir (self .output_dir )
38- self .unsafe_regex = self .helpers .re .compile (r"^\s*fsmonitor|sshcommand|askpass|editor|pager" , re .IGNORECASE )
3938 self .ref_regex = self .helpers .re .compile (r"ref: refs/heads/([a-zA-Z\d_-]+)" )
4039 self .obj_regex = self .helpers .re .compile (r"[a-f0-9]{40}" )
4140 self .pack_regex = self .helpers .re .compile (r"pack-([a-f0-9]{40})\.pack" )
@@ -131,7 +130,6 @@ async def handle_event(self, event):
131130 else :
132131 result = await self .git_fuzz (repo_url , repo_folder )
133132 if result :
134- await self .sanitize_config (repo_folder )
135133 await self .git_checkout (repo_folder )
136134 codebase_event = self .make_event ({"path" : str (repo_folder )}, "FILESYSTEM" , tags = ["git" ], parent = event )
137135 await self .emit_event (
@@ -251,15 +249,6 @@ async def download_files(self, urls, folder):
251249 self .debug (f"Unable to download git files to { folder } " )
252250 return False
253251
254- async def sanitize_config (self , folder ):
255- config_file = folder / ".git/config"
256- if config_file .exists ():
257- with config_file .open ("r" , encoding = "utf-8" , errors = "ignore" ) as file :
258- content = file .read ()
259- sanitized = await self .helpers .re .sub (self .unsafe_regex , r"# \g<0>" , content )
260- with config_file .open ("w" , encoding = "utf-8" ) as file :
261- file .write (sanitized )
262-
263252 async def git_catfile (self , hash , option = "-t" , folder = Path ()):
264253 command = ["git" , "cat-file" , option , hash ]
265254 try :
@@ -270,8 +259,10 @@ async def git_catfile(self, hash, option="-t", folder=Path()):
270259 return output .stdout
271260
272261 async def git_checkout (self , folder ):
262+ self .helpers .sanitize_git_repo (folder )
273263 self .verbose (f"Running git checkout to reconstruct the git repository at { folder } " )
274- command = ["git" , "checkout" , "." ]
264+ # we do "checkout head -- ." because the sanitization deletes the index file, and it needs to be reconstructed
265+ command = ["git" , "checkout" , "HEAD" , "--" , "." ]
275266 try :
276267 await self .run_process (command , env = {"GIT_TERMINAL_PROMPT" : "0" }, cwd = folder , check = True )
277268 except CalledProcessError as e :
0 commit comments