Struct Repo

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

Repository

Implementations§

Source§

impl Repo

Source

pub fn new(directory: impl AsRef<Utf8Path>) -> Result<Self>

Returns an error if the directory doesn’t contain any commit

Source

pub fn directory(&self) -> &Utf8Path

Source

pub fn is_clean(&self) -> Result<()>

Check if there are uncommitted changes.

Source

pub fn checkout_new_branch(&self, branch: &str) -> Result<()>

Source

pub fn delete_branch_in_remote(&self, branch: &str) -> Result<()>

Source

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

Source

pub fn changes(&self, filter: impl FnMut(&&str) -> bool) -> Result<Vec<String>>

Get the list of changed files. filter is applied for each line of git status --porcelain. Only changes for which filter returns true are returned.

Source

pub fn files_of_current_commit(&self) -> Result<HashSet<Utf8PathBuf>>

Get files changed in the current commit

Source

pub fn changes_except_typechanges(&self) -> Result<Vec<String>>

Source

pub fn add<T: AsRef<str>>(&self, paths: &[T]) -> Result<()>

Source

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

Source

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

Source

pub fn push(&self, obj: &str) -> Result<()>

Source

pub fn fetch(&self, obj: &str) -> Result<()>

Source

pub fn force_push(&self, obj: &str) -> Result<()>

Source

pub fn checkout_head(&self) -> Result<()>

Source

pub fn original_branch(&self) -> &str

Branch name before running any git operation. I.e. when the Repo was created.

Source

pub fn git(&self, args: &[&str]) -> Result<String>

Run a git command in the repository git directory

Source

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

Source

pub fn checkout_last_commit_at_paths(&self, paths: &[&Path]) -> Result<()>

Checkout to the latest commit.

Source

pub fn checkout_previous_commit_at_paths(&self, paths: &[&Path]) -> Result<()>

Source

pub fn checkout(&self, object: &str) -> Result<()>

Source

pub fn add_worktree(&self, path: impl AsRef<str>, object: &str) -> Result<()>

Adds a detached git worktree at the given path checked out at the given object.

Source

pub fn remove_worktree(&self, path: impl AsRef<str>) -> Result<()>

Removes a worktree that was created for this repository at the given path.

Source

pub fn current_commit_message(&self) -> Result<String>

Source

pub fn get_author_name(&self, commit_hash: &str) -> Result<String>

Source

pub fn get_author_email(&self, commit_hash: &str) -> Result<String>

Source

pub fn get_committer_name(&self, commit_hash: &str) -> Result<String>

Source

pub fn get_committer_email(&self, commit_hash: &str) -> Result<String>

Source

pub fn current_commit_hash(&self) -> Result<String>

Get the SHA1 of the current HEAD.

Source

pub fn tag(&self, name: &str, message: &str) -> Result<String>

Create a git tag

Source

pub fn get_tag_commit(&self, tag: &str) -> Option<String>

Get the commit hash of the given tag

Source

pub fn get_all_tags(&self) -> Vec<String>

Returns all the tags in the repository in an unspecified order.

Source

pub fn is_ancestor( &self, maybe_ancestor_commit: &str, descendant_commit: &str, ) -> bool

Check if a commit comes before another one.

§Example

For this git log:

commit d6ec399b80d44bf9c4391e4a9ead8482faa9bffd
commit e880d8786cb16aa9a3f258e7503932445d708df7

git.is_ancestor("e880d8786cb16aa9a3f258e7503932445d708df7", "d6ec399b80d44bf9c4391e4a9ead8482faa9bffd") returns true.

Source

pub fn original_remote(&self) -> &str

Name of the remote when the Repo was created.

Source

pub fn original_remote_url(&self) -> Result<String>

Url of the remote when the Repo was created.

Source

pub fn tag_exists(&self, tag: &str) -> Result<bool>

Source

pub fn get_branches_of_commit(&self, commit_hash: &str) -> Result<Vec<String>>

Trait Implementations§

Source§

impl Debug for Repo

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Repo

§

impl RefUnwindSafe for Repo

§

impl Send for Repo

§

impl Sync for Repo

§

impl Unpin for Repo

§

impl UnwindSafe for Repo

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more