Struct Repository

Source
pub struct Repository { /* private fields */ }
Expand description

The main repository object.

This wrapper allows to keep track of optional git-dir and work-tree directories when executing commands. This functionality was needed for glv & git-stree project.

Implementations§

Source§

impl Repository

Getters

Source

pub fn is_clean(&self) -> bool

§Panics

Panics of executing git-diff(1) fails

Source

pub fn is_shallow(&self) -> bool

§Panics

Panics of executing git-rev-parse(1) fails

Source

pub fn remotes(&self) -> Option<HashMap<String, Remote>>

Returns a HashMap of git remotes

Source

pub fn head(&self) -> String

Returns the HEAD commit id if ref HEAD exists

§Panics

Panics when fails to resolve HEAD

Source

pub fn work_tree(&self) -> Option<PathBuf>

Return path to git WORK_TREE

TODO move to generic repo trait TODO Remove optional

Source

pub fn is_sparse(&self) -> bool

Return true if the repo is sparse

Source

pub fn short_ref(&self, long_ref: &str) -> Result<String, InvalidRefError>

§Errors

Will return InvalidRefError if invalid reference provided

Source§

impl Repository

Constructors

Source

pub fn discover(path: &Path) -> Result<Self, RepoError>

§Errors

Will return RepoError when fails to find repository

Source

pub fn default() -> Result<Self, RepoError>

§Errors

Will return RepoError when fails to find repository

Source

pub fn create(path: &Path) -> Result<Self, String>

§Panics

When git execution fails

§Errors

Returns a string output when something goes horrible wrong

Source

pub fn from_args( change: Option<&str>, git: Option<&str>, work: Option<&str>, ) -> Result<Self, RepoError>

§Errors

Will return RepoError when fails to find repository

Source§

impl Repository

Functions

Source

pub fn commit(&self, message: &str) -> Result<(), CommitError>

Return config value for specified key

§Errors

See CommitError

§Panics

When git-commit(1) fails to execute

Source

pub fn commit_extended( &self, message: &str, allow_empty: bool, no_verify: bool, ) -> Result<(), CommitError>

§Errors

See CommitError

Source

pub fn hack_read_file(&self, path: &Path) -> Result<Vec<u8>>

Read file from workspace or use git-show(1) if bare repository

§Panics

When UTF-8 encoding path fails

§Errors

When fails throws std::io::Error TODO move to generic repo trait

Source

pub fn is_ancestor(&self, first: &str, second: &str) -> bool

Returns true if the first commit is an ancestor of the second commit.

Source

pub fn remote_ref_to_id( &self, remote: &str, git_ref: &str, ) -> Result<String, RefSearchError>

§Errors

See RefSearchError

Source

pub fn sparse_checkout_add(&self, pattern: &str) -> Result<(), String>

§Errors

When fails will return a String describing the issue.

§Panics

When git-sparse-checkout(1) execution fails

Source

pub fn stage(&self, path: &Path) -> Result<(), StagingError>

§Errors

See StagingError

§Panics

Panics if fails to execute git-add(1)

Source

pub fn stash_almost_all(&self, message: &str) -> Result<(), StashingError>

Stash staged, unstaged and untracked files (keeps ignored files).

§Errors

See StashingError

Source

pub fn stash_pop(&self) -> Result<(), StashingError>

Pop stashed changes

§Errors

See StashingError

Source

pub fn subtree_add( &self, url: &str, prefix: &str, revision: &str, message: &str, ) -> Result<(), SubtreeAddError>

§Errors

Fails if current repo is bare or dirty. In error cases see the provided string.

§Panics

When git-subtree(1) execution fails

Source

pub fn subtree_split(&self, prefix: &str) -> Result<(), SubtreeSplitError>

§Errors

Fails if current repo is bare or dirty. In error cases see the provided string.

§Panics

When git-subtree(1) execution fails

Source

pub fn subtree_pull( &self, remote: &str, prefix: &str, git_ref: &str, message: &str, ) -> Result<(), SubtreePullError>

§Errors

Fails if current repo is bare or dirty. In error cases see the provided string.

§Panics

When git-subtree(1) execution fails

Source

pub fn subtree_push( &self, remote: &str, prefix: &str, git_ref: &str, ) -> Result<(), SubtreePushError>

§Errors

Fails if current repo is bare. In other error cases see the provided message string.

Source§

impl Repository

Commit Functions

Source

pub fn merge_base( &self, ids: &[&str], ) -> Result<Option<String>, InvalidCommitishError>

Find best common ancestor between to commits.

§Errors

Will return InvalidCommitishError::Multiple when one or multiple provided ids do not exist

§Panics

When exit code of git-merge-base(1) is not 0 or 128

Source

pub fn git(&self) -> Command

Returns a prepared git Command struct TODO move to generic repo trait

Trait Implementations§

Source§

impl Clone for Repository

Source§

fn clone(&self) -> Repository

Returns a duplicate 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> 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.