pub struct Repository { /* private fields */ }git only.Expand description
A logical git repository which may or may not exist.
Implementations§
Source§impl Repository
impl Repository
Sourcepub fn new(dir: impl AsRef<Path>) -> Repository
pub fn new(dir: impl AsRef<Path>) -> Repository
Create a logical repository from the git worktree dir.
Note the git dir must be .git.
Sourcepub fn open(dir: impl AsRef<Path>) -> Result<Repository>
pub fn open(dir: impl AsRef<Path>) -> Result<Repository>
Try to open an existing git repository.
Sourcepub fn origin(&self) -> Option<&String>
pub fn origin(&self) -> Option<&String>
Get the remote name from which this repository was cloned.
Sourcepub fn get_remotes(&self) -> Result<Vec<(String, String)>, CmdError>
pub fn get_remotes(&self) -> Result<Vec<(String, String)>, CmdError>
Get all remote names and their urls.
Sourcepub fn get_default_branch_of(&self, remote: &str) -> Result<String, Error>
pub fn get_default_branch_of(&self, remote: &str) -> Result<String, Error>
Get the default branch name of remote.
Sourcepub fn get_default_branch(&self) -> Result<Option<String>, Error>
pub fn get_default_branch(&self) -> Result<Option<String>, Error>
Get the default branch of this repository’s origin.
Returns None if Self::origin returns None.
Sourcepub fn is_clean(&self) -> Result<bool, CmdError>
pub fn is_clean(&self) -> Result<bool, CmdError>
Query whether the work-tree is clean ignoring any untracked files and recursing through all submodules.
Sourcepub fn describe_exact_ref(&self) -> Result<String, CmdError>
pub fn describe_exact_ref(&self) -> Result<String, CmdError>
Get the exact ref from all refs/ directly referencing the current commit.
E.g.
- branch
<branch>:heads/<branch> - tag
<tag>:tags/<tag>
Calls git describe --all --exact-match.
Sourcepub fn get_ref(&self) -> Result<Ref, CmdError>
pub fn get_ref(&self) -> Result<Ref, CmdError>
Get a Ref for the current commit.
Calls git describe --all --exact-match --always --abbrev=40
Sourcepub fn get_branch_name(&self) -> Result<Option<String>, CmdError>
pub fn get_branch_name(&self) -> Result<Option<String>, CmdError>
Get the current branch name if the current checkout is the top of the branch.
Sourcepub fn clone(&mut self, url: &str) -> Result<bool, Error>
pub fn clone(&mut self, url: &str) -> Result<bool, Error>
Clone the repository with the default options and return if the repository was modified.
Sourcepub fn is_ref(&self, git_ref: &Ref) -> bool
pub fn is_ref(&self, git_ref: &Ref) -> bool
Whether the repository has currently checked out git_ref.
Sourcepub fn is_shallow(&self) -> bool
pub fn is_shallow(&self) -> bool
Whether this repo is a shallow clone.
Sourcepub fn clone_ext(
&mut self,
url: &str,
options: CloneOptions,
) -> Result<bool, Error>
pub fn clone_ext( &mut self, url: &str, options: CloneOptions, ) -> Result<bool, Error>
Clone the repository with options and return if the repository was modified.
Sourcepub fn apply(
&self,
patches: impl IntoIterator<Item = impl AsRef<OsStr>>,
) -> Result<(), CmdError>
pub fn apply( &self, patches: impl IntoIterator<Item = impl AsRef<OsStr>>, ) -> Result<(), CmdError>
Apply all patches to this repository.
Sourcepub fn apply_once(
&self,
patches: impl Iterator<Item = impl AsRef<OsStr>> + Clone,
) -> Result<(), CmdError>
pub fn apply_once( &self, patches: impl Iterator<Item = impl AsRef<OsStr>> + Clone, ) -> Result<(), CmdError>
Apply all patches to this repository only if they were not applied already.
Uses is_applied to determine if the patches were already applied.
Sourcepub fn is_applied(
&self,
patches: impl IntoIterator<Item = impl AsRef<OsStr>>,
) -> Result<bool, CmdError>
pub fn is_applied( &self, patches: impl IntoIterator<Item = impl AsRef<OsStr>>, ) -> Result<bool, CmdError>
Whether all patches are already applied to this repository.
This runs git apply --check --reverse <patches..> which if it succeeds means
that git could reverse all patches successfully and implies that all patches
were already applied.
Trait Implementations§
Source§impl Clone for Repository
impl Clone for Repository
Source§fn clone(&self) -> Repository
fn clone(&self) -> Repository
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for Repository
impl RefUnwindSafe for Repository
impl Send for Repository
impl Sync for Repository
impl Unpin for Repository
impl UnwindSafe for Repository
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> 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