pub fn is_valid_git_repo(path: &Path) -> boolExpand description
Checks if a directory contains a valid Git repository.
This function performs the same validation as GitRepo::is_git_repo() but
operates on an arbitrary path without requiring a GitRepo instance. It’s
useful for validating paths before creating repository handles.
§Arguments
path- The directory path to check for Git repository validity
§Return Value
trueif the path contains a.gitsubdirectoryfalseif the.gitsubdirectory is missing or the path doesn’t exist
§Examples
use agpm_cli::git::is_valid_git_repo;
use std::path::Path;
let path = Path::new("/home/user/my-project");
if is_valid_git_repo(path) {
println!("Found Git repository at: {}", path.display());
} else {
println!("Not a Git repository: {}", path.display());
}§Use Cases
- Path validation: Check directories before creating
GitRepoinstances - Discovery: Scan directories to find Git repositories
- Conditional logic: Branch behavior based on repository presence
- Bulk operations: Filter lists of paths to Git repositories only
§Batch Processing Example
use agpm_cli::git::is_valid_git_repo;
use std::fs;
use std::path::Path;
let search_dir = Path::new("/home/user/projects");
// Find all Git repositories in a directory
for entry in fs::read_dir(search_dir)? {
let path = entry?.path();
if path.is_dir() && is_valid_git_repo(&path) {
println!("Found repository: {}", path.display());
}
}§Validation Scope
This function only verifies the presence of a .git directory and does not:
- Check repository integrity or corruption
- Validate Git version compatibility
- Test network connectivity to remotes
- Verify specific repository content or structure
§Performance
This is a lightweight, synchronous operation that performs a single filesystem check. It’s suitable for bulk validation scenarios.