pub struct Repository { /* private fields */ }Expand description
High-level wrapper around a git repository.
Implementations§
Source§impl Repository
impl Repository
Sourcepub fn open(path: impl AsRef<Path>) -> Result<Self>
pub fn open(path: impl AsRef<Path>) -> Result<Self>
Open a repository at the given path.
§Errors
Returns error if no repository found at path or any parent.
Sourcepub fn open_current() -> Result<Self>
pub fn open_current() -> Result<Self>
Open the repository containing the current directory.
§Errors
Returns error if not inside a git repository.
Sourcepub fn state(&self) -> RepositoryState
pub fn state(&self) -> RepositoryState
Get the current repository state.
Sourcepub fn is_rebasing(&self) -> bool
pub fn is_rebasing(&self) -> bool
Check if there’s a rebase in progress.
Sourcepub fn current_branch(&self) -> Result<String>
pub fn current_branch(&self) -> Result<String>
Sourcepub fn branch_commit(&self, branch_name: &str) -> Result<Oid>
pub fn branch_commit(&self, branch_name: &str) -> Result<Oid>
Sourcepub fn remote_branch_commit(&self, branch_name: &str) -> Result<Oid>
pub fn remote_branch_commit(&self, branch_name: &str) -> Result<Oid>
Sourcepub fn create_branch(&self, name: &str) -> Result<Oid>
pub fn create_branch(&self, name: &str) -> Result<Oid>
Sourcepub fn list_branches(&self) -> Result<Vec<String>>
pub fn list_branches(&self) -> Result<Vec<String>>
Sourcepub fn branch_exists(&self, name: &str) -> bool
pub fn branch_exists(&self, name: &str) -> bool
Check if a branch exists.
Sourcepub fn delete_branch(&self, name: &str) -> Result<()>
pub fn delete_branch(&self, name: &str) -> Result<()>
Sourcepub fn is_clean(&self) -> Result<bool>
pub fn is_clean(&self) -> Result<bool>
Check if the working directory is clean (no modified or staged files).
Untracked files are ignored - only tracked files that have been modified or staged count as “dirty”.
§Errors
Returns error if status check fails.
Sourcepub fn require_clean(&self) -> Result<()>
pub fn require_clean(&self) -> Result<()>
Ensure working directory is clean, returning error if not.
§Errors
Returns DirtyWorkingDirectory if there are uncommitted changes.
Sourcepub fn find_commit(&self, oid: Oid) -> Result<Commit<'_>>
pub fn find_commit(&self, oid: Oid) -> Result<Commit<'_>>
Sourcepub fn signature(&self) -> Result<Signature<'_>>
pub fn signature(&self) -> Result<Signature<'_>>
Get the default signature for commits.
§Errors
Returns error if git config doesn’t have user.name/email.
Sourcepub fn rebase_onto(&self, target: Oid) -> Result<()>
pub fn rebase_onto(&self, target: Oid) -> Result<()>
Rebase the current branch onto a target commit.
Returns Ok(()) on success, or Err(RebaseConflict) if there are conflicts.
§Errors
Returns error if rebase fails or conflicts occur.
Sourcepub fn rebase_onto_from(&self, new_base: Oid, old_base: Oid) -> Result<()>
pub fn rebase_onto_from(&self, new_base: Oid, old_base: Oid) -> Result<()>
Rebase the current branch onto a new base, replaying only commits after old_base.
This is equivalent to git rebase --onto <new_base> <old_base>.
Use this when the old_base was squash-merged and you want to bring only
the unique commits from the current branch.
§Errors
Returns error if rebase fails or conflicts occur.
Sourcepub fn conflicting_files(&self) -> Result<Vec<String>>
pub fn conflicting_files(&self) -> Result<Vec<String>>
Sourcepub fn rebase_abort(&self) -> Result<()>
pub fn rebase_abort(&self) -> Result<()>
Sourcepub fn rebase_continue(&self) -> Result<()>
pub fn rebase_continue(&self) -> Result<()>
Sourcepub fn origin_url(&self) -> Result<String>
pub fn origin_url(&self) -> Result<String>
Sourcepub fn parse_github_remote(url: &str) -> Result<(String, String)>
pub fn parse_github_remote(url: &str) -> Result<(String, String)>
Parse owner and repo name from a GitHub URL.
Supports both HTTPS and SSH URLs:
https://github.com/owner/repo.gitgit@github.com:owner/repo.git
§Errors
Returns error if URL cannot be parsed.
Sourcepub fn pull_ff(&self) -> Result<()>
pub fn pull_ff(&self) -> Result<()>
Pull (fast-forward only) the current branch from origin.
This fetches and merges origin/<branch> into the current branch,
but only if it can be fast-forwarded.
§Errors
Returns error if pull fails or fast-forward is not possible.
Sourcepub const fn inner(&self) -> &Repository
pub const fn inner(&self) -> &Repository
Get a reference to the underlying git2 repository.
Use sparingly - prefer high-level methods.