Validate that a branch exists and points to an accessible commit # Errors Returns an error if: - The repository cannot be opened - The branch reference does not exist - The branch has no target commit - The target commit object is not accessible in the object database
(repo_path: &Path, branch_name: &str)
| 444 | /// - The branch has no target commit |
| 445 | /// - The target commit object is not accessible in the object database |
| 446 | pub async fn validate_branch_accessible(repo_path: &Path, branch_name: &str) -> Result<(), String> { |
| 447 | tokio::task::spawn_blocking({ |
| 448 | let repo_path = repo_path.to_owned(); |
| 449 | let branch_name = branch_name.to_owned(); |
| 450 | move || -> Result<(), String> { |
| 451 | let repo = Repository::open(&repo_path) |
| 452 | .map_err(|e| format!("Failed to open repository: {e}"))?; |
| 453 | |
| 454 | // Check branch exists |
| 455 | let branch_ref = format!("refs/heads/{branch_name}"); |
| 456 | let reference = repo |
| 457 | .find_reference(&branch_ref) |
| 458 | .map_err(|e| format!("Branch '{}' not found: {}", branch_name, e))?; |
| 459 | |
| 460 | // Check branch points to valid commit |
| 461 | let oid = reference |
| 462 | .target() |
| 463 | .ok_or_else(|| format!("Branch '{}' has no target", branch_name))?; |
| 464 | |
| 465 | // Try to find the commit - this validates object accessibility |
| 466 | repo.find_commit(oid).map_err(|e| { |
| 467 | format!( |
| 468 | "Branch '{}' points to inaccessible commit {}: {}", |
| 469 | branch_name, oid, e |
| 470 | ) |
| 471 | })?; |
| 472 | |
| 473 | Ok(()) |
| 474 | } |
| 475 | }) |
| 476 | .await |
| 477 | .map_err(|e| format!("Task join error: {e}"))? |
| 478 | } |
| 479 | |
| 480 | /// Clone a local repository without hardlinks |
| 481 | /// |