@@ -185,28 +185,39 @@ def _parse_rust(repo: Path) -> List[dict]:
185
185
# Git submodules: .gitmodules
186
186
187
187
def _parse_gitmodules (repo : Path ) -> List [dict ]:
188
- results = []
189
188
gm = repo / ".gitmodules"
190
189
if not gm .exists ():
191
- return results
192
- content = _read_text (gm ) or ""
193
- current = {}
194
- for line in content .splitlines ():
195
- line = line .strip ()
190
+ return []
191
+ content = (gm .read_text (encoding = "utf-8" , errors = "ignore" ) or "" )
192
+ entries : List [dict ] = []
193
+ current : dict = {}
194
+ for raw in content .splitlines ():
195
+ line = raw .strip ()
196
+ if not line or line .startswith (("#" , ";" )):
197
+ continue
196
198
if line .startswith ("[submodule" ):
197
199
if current :
198
- results .append (current )
199
- current = {"package_manager" : "gitmodules" , "dependency_scope" : "submodule" , "source_type" : "submodule" , "direct" : True }
200
+ entries .append (current )
201
+ current = {
202
+ "package_manager" : "gitmodules" ,
203
+ "dependency_scope" : "submodule" ,
204
+ "source_type" : "submodule" ,
205
+ "direct" : True ,
206
+ }
207
+ m = re .search (r"\[submodule\s+\"([^\"]+)\"\]" , line )
208
+ if m :
209
+ current ["name" ] = m .group (1 )
200
210
elif "=" in line :
201
211
k , v = [x .strip () for x in line .split ("=" , 1 )]
202
212
current [k ] = v
203
213
if current :
204
- results .append (current )
205
- final = []
206
- for entry in results :
207
- name = entry .get ("submodule" ) or entry .get ("name" ) or entry .get ("path" ) or ""
214
+ entries .append (current )
215
+
216
+ results : List [dict ] = []
217
+ for entry in entries :
218
+ name = entry .get ("name" ) or entry .get ("path" ) or ""
208
219
url = entry .get ("url" ) or ""
209
- final .append ({
220
+ results .append ({
210
221
"package_manager" : "gitmodules" ,
211
222
"dependency_name" : name ,
212
223
"dependency_version_requirement" : url ,
@@ -215,7 +226,7 @@ def _parse_gitmodules(repo: Path) -> List[dict]:
215
226
"source_type" : "submodule" ,
216
227
"direct" : True ,
217
228
})
218
- return final
229
+ return results
219
230
220
231
221
232
# Foundry: foundry.toml, lib/*
0 commit comments