pub struct GitCommand { /* private fields */ }Expand description
A git invocation with Mermaid’s hardening already applied.
Implementations§
Source§impl GitCommand
impl GitCommand
Sourcepub fn new() -> Self
pub fn new() -> Self
Start a hardened git invocation. Add a working directory with
Self::cwd; without one the command inherits the process’s.
Sourcepub fn stdin_bytes(self, data: Vec<u8>) -> Self
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).
Sourcepub fn run(self) -> Result<()>
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.
Sourcepub fn success(self) -> Result<bool>
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.
Sourcepub fn output(self) -> Result<String>
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.
Sourcepub fn output_bytes(self) -> Result<Vec<u8>>
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.