pub struct GitRepo { /* private fields */ }Expand description
A Git repository handle providing async operations via CLI commands.
Implementations§
Source§impl GitRepo
impl GitRepo
Sourcepub fn new(path: impl AsRef<Path>) -> Self
pub fn new(path: impl AsRef<Path>) -> Self
Creates a new GitRepo instance for an existing local repository.
§Arguments
path- The filesystem path to the Git repository root directory
Sourcepub async fn clone(url: &str, target: impl AsRef<Path>) -> Result<Self>
pub async fn clone(url: &str, target: impl AsRef<Path>) -> Result<Self>
Clones a Git repository from a remote URL to a local path.
§Arguments
url- The remote repository URL (HTTPS, SSH, or file://)target- The local directory where the repository will be clonedprogress- Optional progress bar for user feedback
§Errors
- The URL is invalid or unreachable
- Authentication fails
- The target directory already exists and is not empty
- Network connectivity issues
- Insufficient disk space
Sourcepub async fn fetch(&self, auth_url: Option<&str>) -> Result<()>
pub async fn fetch(&self, auth_url: Option<&str>) -> Result<()>
Fetches updates from the remote repository without modifying the working tree.
§Arguments
auth_url- Optional URL with authentication for private repositoriesprogress- Optional progress bar for network operation feedback
§Errors
- Network connectivity fails
- Authentication is rejected
- The remote repository is unavailable
- The local repository is in an invalid state
Sourcepub async fn checkout(&self, ref_name: &str) -> Result<()>
pub async fn checkout(&self, ref_name: &str) -> Result<()>
Checks out a specific Git reference (branch, tag, or commit hash).
§Arguments
ref_name- The Git reference to checkout (branch, tag, or commit)
§Errors
- The reference doesn’t exist in the repository
- The repository is in an invalid state
- File system permissions prevent checkout
- The working directory is locked by another process
Sourcepub async fn get_remote_url(&self) -> Result<String>
pub async fn get_remote_url(&self) -> Result<String>
Retrieves the URL of the remote ‘origin’ repository.
§Return Value
- HTTPS:
https://github.com/user/repo.git - SSH:
git@github.com:user/repo.git - File:
file:///path/to/repo.git
§Errors
- No ‘origin’ remote is configured
- The repository is not a valid Git repository
- Git command execution fails
- File system access is denied
Sourcepub fn is_git_repo(&self) -> bool
pub fn is_git_repo(&self) -> bool
Checks if the directory contains a valid Git repository.\n ///
Sourcepub async fn verify_url(url: &str) -> Result<()>
pub async fn verify_url(url: &str) -> Result<()>
Verifies that a Git repository URL is accessible without performing a full clone.
§Arguments
url- The repository URL to verify
§Errors
- Network issues: DNS resolution, connectivity, timeouts
- Authentication failures: Invalid credentials, expired tokens
- Repository issues: Repository doesn’t exist, access denied
- Local path issues: File doesn’t exist (for
file://URLs) - URL format issues: Malformed or unsupported URL schemes
Sourcepub async fn clone_bare_with_context(
url: &str,
target: impl AsRef<Path>,
context: Option<&str>,
) -> Result<Self>
pub async fn clone_bare_with_context( url: &str, target: impl AsRef<Path>, context: Option<&str>, ) -> Result<Self>
Sourcepub async fn create_worktree(
&self,
worktree_path: impl AsRef<Path>,
reference: Option<&str>,
) -> Result<Self>
pub async fn create_worktree( &self, worktree_path: impl AsRef<Path>, reference: Option<&str>, ) -> Result<Self>
Sourcepub async fn create_worktree_with_context(
&self,
worktree_path: impl AsRef<Path>,
reference: Option<&str>,
context: Option<&str>,
) -> Result<Self>
pub async fn create_worktree_with_context( &self, worktree_path: impl AsRef<Path>, reference: Option<&str>, context: Option<&str>, ) -> Result<Self>
Sourcepub async fn remove_worktree(
&self,
worktree_path: impl AsRef<Path>,
) -> Result<()>
pub async fn remove_worktree( &self, worktree_path: impl AsRef<Path>, ) -> Result<()>
Remove a worktree associated with this repository.
§Arguments
worktree_path- The path to the worktree to remove
Sourcepub async fn list_worktrees(&self) -> Result<Vec<PathBuf>>
pub async fn list_worktrees(&self) -> Result<Vec<PathBuf>>
List all worktrees associated with this repository.
Sourcepub async fn prune_worktrees(&self) -> Result<()>
pub async fn prune_worktrees(&self) -> Result<()>
Prune stale worktree administrative files.
Sourcepub async fn get_current_commit(&self) -> Result<String>
pub async fn get_current_commit(&self) -> Result<String>
Sourcepub async fn resolve_refs_batch(
&self,
refs: &[&str],
) -> Result<HashMap<String, Option<String>>>
pub async fn resolve_refs_batch( &self, refs: &[&str], ) -> Result<HashMap<String, Option<String>>>
Batch resolve multiple refs to SHAs in a single git process.
Uses git rev-parse <ref1> <ref2> ... to resolve all refs at once, reducing
process spawn overhead from O(n) to O(1). This is significantly faster
for Windows where process spawning has high overhead.
§Arguments
refs- Slice of ref specifications to resolve
§Returns
HashMap mapping each input ref to its resolved SHA (or None if not found)
§Performance
- Single process for all refs vs one per ref
- Reduces 100 refs from ~5-10 seconds to ~0.5 seconds on Windows
§Examples
use agpm_cli::git::GitRepo;
let repo = GitRepo::new("/path/to/repo");
let refs = vec!["v1.0.0", "main", "abc1234"];
let results = repo.resolve_refs_batch(&refs).await?;
for (ref_name, sha) in results {
if let Some(sha) = sha {
println!("{} -> {}", ref_name, sha);
} else {
println!("{} not found", ref_name);
}
}pub async fn get_current_branch(&self) -> Result<String>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for GitRepo
impl RefUnwindSafe for GitRepo
impl Send for GitRepo
impl Sync for GitRepo
impl Unpin for GitRepo
impl UnwindSafe for GitRepo
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more