ensure_git_available

Function ensure_git_available 

Source
pub fn ensure_git_available() -> Result<()>
Expand description

Ensures Git is available on the system or returns a detailed error.

This function validates that Git is installed and accessible, providing a AgpmError::GitNotFound with actionable guidance if Git is unavailable. It’s the error-throwing equivalent of is_git_installed().

§Return Value

  • Ok(()) if Git is properly installed and accessible
  • Err(AgpmError::GitNotFound) if Git is not available

§Error Context

The returned error includes:

  • Clear description of the missing Git requirement
  • Platform-specific installation instructions
  • Troubleshooting guidance for common PATH issues

§Examples

use agpm_cli::git::ensure_git_available;

// Validate Git before starting operations
ensure_git_available()?;

// Git is guaranteed to be available beyond this point
println!("Git is available - proceeding with operations");

§Error Handling

use agpm_cli::git::ensure_git_available;
use agpm_cli::core::AgpmError;

match ensure_git_available() {
    Ok(_) => println!("Git is ready"),
    Err(e) => {
        if let Some(AgpmError::GitNotFound) = e.downcast_ref::<AgpmError>() {
            eprintln!("Please install Git to continue");
            // Show platform-specific installation instructions
        }
    }
}

§Usage Pattern

Typically called at the start of Git-dependent operations:

use agpm_cli::git::{ensure_git_available, GitRepo};
use std::env;

// Validate prerequisites first
ensure_git_available()?;

// Then proceed with Git operations
let temp_dir = env::temp_dir();
let repo = GitRepo::clone(
    "https://github.com/example/repo.git",
    temp_dir.join("repo")
).await?;