pub fn is_git_repository(path: &Path) -> boolExpand description
Checks if a path contains a Git repository (regular or bare).
This function detects both types of Git repositories:
- Regular repositories: Contain a
.gitsubdirectory - Bare repositories: Contain a
HEADfile in the root
§Arguments
path- The path to check for a Git repository
§Returns
trueif the path is a valid Git repository (regular or bare)falseif neither repository marker exists
§Examples
use std::path::Path;
use agpm_cli::git::is_git_repository;
// Check a regular repository
let repo_path = Path::new("/path/to/repo");
if is_git_repository(repo_path) {
println!("Found Git repository");
}
// Check a bare repository
let bare_path = Path::new("/path/to/repo.git");
if is_git_repository(bare_path) {
println!("Found bare Git repository");
}§Performance
This is a lightweight synchronous check that performs at most two filesystem operations to determine repository type.