gitbaby is an asynchronous Rust library wrapping git operations, built on gix + tokio + async-trait. Module layout: - archive, blame, blob, branch, cleanup, commit, compare, config, conflict, diff, merge, refs, remote, setup, share, submodule, tags, tree (feature modules) - command: command scheduler (cmd/env/pipe/context/error) - repo: RepositoryFacade trait (consumers implement, exposing a gix::Repository) Features: - async API on tokio 1.53 - order-preserving Env (Vec<(String, String)>) - hand-written BabyError / CmdError, not using thiserror derive - integration tests covering cmd_run / context / env / pipe (env keys prefixed for isolation) CI: none, standard cargo build / test / clippy / fmt only
3.2 KiB
3.2 KiB
AGENTS.md — gitbaby
What this is
- Single-crate Rust library (no binary, no workspace). Edition
2024. - Public entrypoint:
GitBaby::new(facade: Arc<dyn RepositoryFacade>, pipe: Pipe)insrc/lib.rs. - Consumers must implement
RepositoryFacade(src/repo.rs) — three async fns returning a path/paths and agix::Repository. There is no default impl.
Build / test / verify
- Standard cargo only. No CI, no pre-commit, no scripts, no rust-toolchain pin.
- Edition 2024 requires a recent stable toolchain (rustc ≥ 1.85). Local env verified at
rustc 1.97.1. - Useful commands (no order dependency beyond what's standard):
cargo build/cargo check/cargo build --releasecargo test(sync +#[tokio::test]integration tests intests/)cargo test --test <file>to run a single integration test filecargo test <name>to filter by test name substringcargo clippy --all-targets -- -D warningsif strictcargo fmt --check/cargo fmt(default rustfmt; norustfmt.toml)
Architecture notes
- Error pattern is hand-written.
BabyError(src/error.rs, ~50 variants) andCmdError(src/command/error.rs) implementDisplay+std::error::Errorby hand.thiserroris inCargo.tomlbut not used via#[derive(thiserror::Error)]. Do not "modernize" by adding the derive — keep the hand-written impls consistent. Envinsrc/command/env.rsis order-preserving (Vec<(String, String)>), not aHashMap.withappends,setreplaces in place. This matters for env-var ordering in spawned processes.Cmd::Display=prog+config_args+args(config_args are prepended to args at runtime).PipeisClone;cancel_pipe()setscancelled=trueand sendsstart_kill()to every running child but does not remove them fromcmds.
Module layout convention
- Most feature modules follow
src/<feature>/{mod.rs, types.rs, helper.rs, usecase.rs};mod.rsre-exports the public types fromtypes.rs. src/share/is the outlier: it uses{cmd.rs, env.rs, error.rs, path.rs}instead. Don't "normalize" it.src/command/uses{cmd.rs, context.rs, env.rs, error.rs, pipe.rs}and has its ownerror.rsseparate fromsrc/error.rs.
Test quirks (tests/)
tests/cmd_run.rsdefines a localunwrap_or_recover_or_panic!-style macro for asserting command output — reuse it, don't reinvent.tests/env.rsmutates process env. It guards tests withstatic ENV_LOCK: Mutex<()>and uses keys prefixedGITBABY_TEST_ENV_<suffix>for isolation.std::env::set_var/remove_varare wrapped in localunsafe fns; follow that pattern when adding env-mutating tests.tests/pipe.rsasync cancel tests calltokio::time::sleep(Duration::from_millis(200))aftercancel_pipe()to letChild::try_waitobserve exit — keep that delay when adding new cancel tests.
Gotchas
- No README. No docs beyond the code. Treat
Cargo.toml+ source as the only source of truth. gix = "0.86",tokio = 1.53(full features),time = 0.3— all recent; do not bump them speculatively.- Public API surfaces async (
async_trait); sync callers must use a runtime (tests use#[tokio::test]).