MCPcopy Create free account
hub / github.com/dtormoen/tsk-tsk / parse_gitmodules

Method parse_gitmodules

src/git.rs:1136–1167  ·  view source on GitHub ↗

Parse the .gitmodules file to extract submodule paths.

(&self, repo_path: &Path)

Source from the content-addressed store, hash-verified

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)]

Callers 2

Calls

no outgoing calls

Tested by

no test coverage detected