vcs-git — automate Git from Rust
Part of the vcs-toolkit-rs workspace.
What you can do: status & branches, stage/commit/checkout, diff & log,
merge/rebase/reset, worktrees, tags, blame, clone, config, cherry-pick/revert,
parse & resolve conflict markers, and a hardened (hooks-off) mode for untrusted
repos — all as typed, repo-scoped async methods over the git binary, behind a
mockable interface.
How it works: each call runs the real git (its exact behaviour, config and
credentials) and parses the output into typed values. Commands run inside an OS job
(an OS-level container that kills the whole process tree if your program exits, via
processkit) so no git subprocess is ever orphaned; calls return the
structured Error and honour an optional timeout.
Credentials: ambient git credential helpers / SSH agent by default; to supply a
token per operation, the one-liner is Git::new().with_token(tok) (or
.with_env_token("MY_TOKEN")); for full control attach a CredentialProvider with
.with_credentials(...). For HTTPS remotes the secret is fed via an inline
credential.helper, kept out of argv (SSH remotes use the ambient agent).
📖 Full guide: on docs.rs — every command by theme, result types, builder/newtype APIs, and worked examples.
Every method is async, so call it from a tokio runtime:
use Path;
use ;
let git = new;
let repo = new;
let branch = git.current_branch.await?; // Option<String>, e.g. Some("main")
let status = git.status.await?; // Vec<StatusEntry>
let log = git.log.await?; // Vec<Commit>, newest first
Stage, commit, inspect
use ;
use ;
# async
Renames come back structured
status runs git status --porcelain=v1 -z, so a rename carries both paths:
# use Path;
# use ;
# async
Worktrees
Manage linked worktrees with structured results:
use ;
use Path;
# async
Distinguish failures structurally
# use Path;
# use ;
# async
Consumers depend on the GitApi trait and substitute a fake in tests — enable
the mock feature for a mockall-generated MockGitApi, or inject a fake
process runner with Git::with_runner(processkit::testing::ScriptedRunner::new()…):
use ;
use Path;
use ;
# async
Requires the git binary on PATH.
License
MIT