Git

Struct Git 

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

Git subprocess wrapper.

Implementations§

Source§

impl Git

Source

pub fn new() -> Self

Create a new Git instance using the current directory.

Source

pub fn with_work_dir<P: AsRef<Path>>(path: P) -> Self

Create a new Git instance with a specific working directory.

Source

pub fn work_dir(&self) -> &Path

Get the working directory.

Source

pub fn check_repository(&self) -> Result<(), Error>

Check if we’re in a git repository.

§Errors

Returns an error if git is not found or we’re not in a repository.

Source

pub fn repo_root(&self) -> Result<PathBuf, Error>

Get the repository root directory.

§Errors

Returns an error if not in a git repository.

Source

pub fn run(&self, args: &[&str]) -> Result<Output, Error>

Run a git command and return the raw output.

§Errors

Returns an error if the command fails to execute.

Source

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

Run a git command and return stdout as a string.

§Errors

Returns an error if the command fails or returns non-zero exit code.

Source

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

Run a git command silently, only checking for success.

§Errors

Returns an error if the command fails.

Source

pub fn head(&self) -> Result<String, Error>

Get the current HEAD commit hash.

§Errors

Returns an error if HEAD cannot be resolved.

Source

pub fn short_hash(&self, commit: &str) -> Result<String, Error>

Get a short commit hash.

§Errors

Returns an error if the commit cannot be resolved.

Source

pub fn config_get(&self, key: &str) -> Result<Option<String>, Error>

Get a git config value.

§Errors

Returns an error if the config key doesn’t exist.

Source

pub fn config_set(&self, key: &str, value: &str) -> Result<(), Error>

Set a git config value.

§Errors

Returns an error if the config cannot be set.

Source

pub fn config_unset(&self, key: &str, all: bool) -> Result<(), Error>

Unset a git config value.

If all is true, removes all values for multi-valued keys.

§Errors

Returns an error if the config cannot be unset.

Source

pub fn notes_show( &self, notes_ref: &str, commit: &str, ) -> Result<Option<String>, Error>

Get notes content for a commit.

§Errors

Returns an error if the notes cannot be read.

Source

pub fn notes_add( &self, notes_ref: &str, commit: &str, content: &str, ) -> Result<(), Error>

Add or update notes for a commit.

§Errors

Returns an error if the notes cannot be added.

Source

pub fn notes_remove(&self, notes_ref: &str, commit: &str) -> Result<(), Error>

Remove notes for a commit.

§Errors

Returns an error if the notes cannot be removed.

Source

pub fn notes_list( &self, notes_ref: &str, ) -> Result<Vec<(String, String)>, Error>

List all notes in a ref.

§Errors

Returns an error if notes cannot be listed.

Source

pub fn notes_push(&self, remote: &str, notes_ref: &str) -> Result<(), Error>

Push notes to a remote.

§Errors

Returns an error if push fails.

Source

pub fn notes_fetch(&self, remote: &str, notes_ref: &str) -> Result<(), Error>

Fetch notes from a remote.

§Errors

Returns an error if fetch fails.

Trait Implementations§

Source§

impl Clone for Git

Source§

fn clone(&self) -> Git

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 Git

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Git

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Git

§

impl RefUnwindSafe for Git

§

impl Send for Git

§

impl Sync for Git

§

impl Unpin for Git

§

impl UnwindSafe for Git

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.

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V