Get the current commit SHA # Errors Returns an error if: - The repository cannot be opened - HEAD cannot be resolved (e.g., empty repository with no commits) - The HEAD reference does not point to a valid commit
(repo_path: &Path)
| 337 | /// - HEAD cannot be resolved (e.g., empty repository with no commits) |
| 338 | /// - The HEAD reference does not point to a valid commit |
| 339 | pub async fn get_current_commit(repo_path: &Path) -> Result<String, String> { |
| 340 | tokio::task::spawn_blocking({ |
| 341 | let repo_path = repo_path.to_owned(); |
| 342 | move || -> Result<String, String> { |
| 343 | let repo = Repository::open(&repo_path) |
| 344 | .map_err(|e| format!("Failed to open repository: {e}"))?; |
| 345 | |
| 346 | let head = repo |
| 347 | .head() |
| 348 | .map_err(|e| format!("Failed to get HEAD: {e}"))?; |
| 349 | |
| 350 | let commit = head |
| 351 | .peel_to_commit() |
| 352 | .map_err(|e| format!("Failed to get commit from HEAD: {e}"))?; |
| 353 | |
| 354 | Ok(commit.id().to_string()) |
| 355 | } |
| 356 | }) |
| 357 | .await |
| 358 | .map_err(|e| format!("Task join error: {e}"))? |
| 359 | } |
| 360 | |
| 361 | /// Create a branch from a specific commit |
| 362 | pub async fn create_branch_from_commit( |
no outgoing calls