Parse the .gitmodules file to extract submodule paths.
(&self, repo_path: &Path)
| 1134 | |
| 1135 | /// Parse the .gitmodules file to extract submodule paths. |
| 1136 | async fn parse_gitmodules(&self, repo_path: &Path) -> Result<Vec<SubmoduleInfo>, String> { |
| 1137 | let gitmodules_path = repo_path.join(".gitmodules"); |
| 1138 | if !gitmodules_path.exists() { |
| 1139 | return Ok(Vec::new()); |
| 1140 | } |
| 1141 | |
| 1142 | let content = tokio::fs::read_to_string(&gitmodules_path) |
| 1143 | .await |
| 1144 | .map_err(|e| format!("Failed to read .gitmodules: {}", e))?; |
| 1145 | |
| 1146 | let mut submodules = Vec::new(); |
| 1147 | let mut current_path: Option<String> = None; |
| 1148 | |
| 1149 | for line in content.lines() { |
| 1150 | let line = line.trim(); |
| 1151 | if line.starts_with("[submodule ") { |
| 1152 | // Save previous submodule if path was found |
| 1153 | if let Some(path) = current_path.take() { |
| 1154 | submodules.push(SubmoduleInfo { path }); |
| 1155 | } |
| 1156 | } else if let Some(path_value) = line.strip_prefix("path = ") { |
| 1157 | current_path = Some(path_value.to_string()); |
| 1158 | } |
| 1159 | } |
| 1160 | |
| 1161 | // Don't forget the last submodule |
| 1162 | if let Some(path) = current_path { |
| 1163 | submodules.push(SubmoduleInfo { path }); |
| 1164 | } |
| 1165 | |
| 1166 | Ok(submodules) |
| 1167 | } |
| 1168 | } |
| 1169 | |
| 1170 | #[cfg(test)] |
no outgoing calls
no test coverage detected