Skip to main content

GitCommand

Struct GitCommand 

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

A git invocation with Mermaid’s hardening already applied.

Implementations§

Source§

impl GitCommand

Source

pub fn new() -> Self

Start a hardened git invocation. Add a working directory with Self::cwd; without one the command inherits the process’s.

Source

pub fn cwd(self, dir: &Path) -> Self

Run in dir.

Source

pub fn arg<S: AsRef<OsStr>>(self, arg: S) -> Self

Append one argument.

Source

pub fn args<I, S>(self, args: I) -> Self
where I: IntoIterator<Item = S>, S: AsRef<OsStr>,

Append several arguments.

Source

pub fn stdin_bytes(self, data: Vec<u8>) -> Self

Feed data to the command’s stdin. Lets git apply take a patch without staging it through a temp file whose lifetime we’d have to manage (and whose contents would briefly sit on disk unredacted).

Source

pub fn run(self) -> Result<()>

Run and require success, discarding output.

§Errors

git not being spawnable (not installed, not on PATH), a failure while feeding stdin or collecting output, and a nonzero exit — the message carries the command line and git’s trimmed stderr. Use Self::success where a nonzero exit is an answer rather than a failure.

Source

pub fn success(self) -> Result<bool>

Run and report whether it exited zero, discarding output. For the predicate forms (diff --quiet, rev-parse) where a nonzero exit is an answer rather than a failure.

§Errors

Only failures to run git: not spawnable, or stdin/output handling failed. The exit status never produces an Err here — that is the bool.

Source

pub fn output(self) -> Result<String>

Run and return trimmed stdout, requiring success.

§Errors

Exactly Self::output_bytes’s. Invalid UTF-8 is not among them: it is replaced lossily, so use output_bytes when the exact bytes matter.

Source

pub fn output_bytes(self) -> Result<Vec<u8>>

Run and return raw stdout, requiring success. Use for diff --binary and anything else that need not be valid UTF-8.

§Errors

git not being spawnable, a failure while feeding stdin or collecting output, and a nonzero exit — the message carries the command line and git’s trimmed stderr. Stdout written before a nonzero exit is discarded.

Trait Implementations§

Source§

impl Default for GitCommand

Source§

fn default() -> Self

Returns the “default value” for a type. 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> 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> Same for T

Source§

type Output = T

Should always be Self
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