Struct Repository

Source
pub struct Repository { /* private fields */ }
Available on crate feature git only.
Expand description

A logical git repository which may or may not exist.

Implementations§

Source§

impl Repository

Source

pub fn new(dir: impl AsRef<Path>) -> Repository

Create a logical repository from the git worktree dir.

Note the git dir must be .git.

Source

pub fn open(dir: impl AsRef<Path>) -> Result<Repository>

Try to open an existing git repository.

Source

pub fn worktree(&self) -> &Path

Get the path to the worktree of this git repository.

Source

pub fn origin(&self) -> Option<&String>

Get the remote name from which this repository was cloned.

Source

pub fn get_remotes(&self) -> Result<Vec<(String, String)>, CmdError>

Get all remote names and their urls.

Source

pub fn get_default_branch_of(&self, remote: &str) -> Result<String, Error>

Get the default branch name of remote.

Source

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.

Source

pub fn is_clean(&self) -> Result<bool, CmdError>

Query whether the work-tree is clean ignoring any untracked files and recursing through all submodules.

Source

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.

Source

pub fn get_ref(&self) -> Result<Ref, CmdError>

Get a Ref for the current commit.

Calls git describe --all --exact-match --always --abbrev=40

Source

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.

Source

pub fn clone(&mut self, url: &str) -> Result<bool, Error>

Clone the repository with the default options and return if the repository was modified.

Source

pub fn is_ref(&self, git_ref: &Ref) -> bool

Whether the repository has currently checked out git_ref.

Source

pub fn is_shallow(&self) -> bool

Whether this repo is a shallow clone.

Source

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.

Source

pub fn apply( &self, patches: impl IntoIterator<Item = impl AsRef<OsStr>>, ) -> Result<(), CmdError>

Apply all patches to this repository.

Source

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.

Source

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

Source§

fn clone(&self) -> Repository

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Repository

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T