Initializes and checks out all submodules recursively in a repository. Runs `git submodule update --init --recursive` with local file protocol enabled, which is needed because cloned repos have local file:// URLs for submodules.
(repo_path: &Path)
| 521 | /// Runs `git submodule update --init --recursive` with local file protocol enabled, |
| 522 | /// which is needed because cloned repos have local file:// URLs for submodules. |
| 523 | pub async fn init_submodules(repo_path: &Path) -> Result<(), String> { |
| 524 | let output = tokio::process::Command::new("git") |
| 525 | .args([ |
| 526 | "-c", |
| 527 | "protocol.file.allow=always", |
| 528 | "submodule", |
| 529 | "update", |
| 530 | "--init", |
| 531 | "--recursive", |
| 532 | ]) |
| 533 | .current_dir(repo_path) |
| 534 | .output() |
| 535 | .await |
| 536 | .map_err(|e| format!("Failed to run git submodule update: {e}"))?; |
| 537 | |
| 538 | if output.status.success() { |
| 539 | Ok(()) |
| 540 | } else { |
| 541 | let stderr = String::from_utf8_lossy(&output.stderr); |
| 542 | Err(format!("git submodule update failed: {stderr}")) |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | /// Resolves a local branch name to its commit SHA. |
| 547 | /// |