git-spawn
An async Rust wrapper around the git CLI. Each git subcommand is a
builder-style struct; .execute().await spawns git as a subprocess and
returns typed output.
use ;
async
Install
[]
= "0.1"
= { = "1", = ["macros", "rt-multi-thread"] }
MSRV: 1.85 (Rust 2024 edition).
Capabilities
- Porcelain: init, clone, add, commit, status, log, diff, show, branch, checkout, switch, merge, rebase, pull, push, fetch, remote, tag, stash, reset, restore, rm, mv
- Plumbing: rev-parse, ls-files, ls-tree, cat-file, hash-object, update-ref, for-each-ref
- Advanced: worktree, submodule, bisect, cherry-pick, grep, config, reflog
- Typed parsers (behind the
parsefeature, on by default) forstatus --porcelain=v1 -z,logwith a fixed token format, anddiff --name-status -z - Higher-level workflow helpers (behind the
workflowfeature, off by default) —repo.info(),repo.branches(),repo.tags(),repo.history(), andrepo.workflow()for one-call repo state, typed branch / tag / commit listings, and common compositions likefeature_branch,commit_all,sync,squash_merge - Escape hatches on every command (
.arg,.args,.flag,.option) so flags the typed API hasn't surfaced are still reachable
Choosing a git library for Rust
Three realistic options; pick by what you're building, not which is "best."
| Project | What it is | Needs git installed |
Async-native | Honors local git config, hooks, credential helpers |
|---|---|---|---|---|
git-spawn |
Async subprocess wrapper around the git CLI |
yes | yes | yes |
git2 |
Rust bindings to libgit2 (C) | no | no | partial |
gix |
Pure-Rust (gitoxide) | no | some | partial |
git-spawn-- automating workflows a human would script in bash (commit, push, rebase, cherry-pick, tagging) where behavior must match the user's realgit: their~/.gitconfig, hooks, and credential helpers, run concurrently undertokio. Any flag the typed API hasn't surfaced is reachable via the escape hatches. Cost: agitbinary onPATH, process-spawn overhead per call, and output parsing (or theparsefeature).git2-- in-process object access (trees, blobs, commits) without requiring users to havegitinstalled. Cost: a C dependency, no first-class async, and you wire up hooks/credentials yourself.gix-- a pure-Rust stack (no C toolchain, easy cross-compilation) with high-throughput object access for tooling built on git's data model. Cost: a still-evolving API on some write/network paths; likegit2, doesn't run your hooks or credential helpers.
Rule of thumb: calling git on behalf of a user -> git-spawn; reading or
writing objects without a git install -> git2 (mature, C) or gix (pure
Rust); building a merge engine or git server -> gix.
Usage
Repository handle
use ;
async
Repository is cheap and cloneable; the accessor methods (.add(),
.commit(), .log(), ...) return commands pre-scoped to the repo's
working directory.
Typed parsers
use ;
use StatusFormat;
use ;
async
The parse feature (on by default) also provides parse_log (paired with
LOG_FORMAT) and parse_diff_name_status. Enable the serde feature to get
Serialize / Deserialize on the parsed types.
Workflow helpers (opt-in)
Enable the workflow feature for one-call repo state, typed listings, and
common compositions:
[]
= { = "0.1", = ["workflow"] }
use Repository;
async
See the module docs for info, branches, tags, history, and workflow
for the full surface.
Escape hatches
Every command supports .arg, .args, .flag, and .option for flags that
don't yet have a typed builder method:
use ;
async
Timeouts, env, working dir
use Duration;
use ;
async
Feature flags
| Flag | Default | Purpose |
|---|---|---|
parse |
on | Typed parsers for status / log / diff output |
serde |
off | Serialize / Deserialize on parsed types |
workflow |
off | Higher-level helpers: info, branches, tags, history, workflow compositions (implies parse) |
Contributing
PRs welcome. Please run before submitting:
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.