Expand description
Command execution primitives.
Every git subcommand wrapper is a struct that implements GitCommand.
The trait gives each command:
execute()— run and return a typed outputarg()/args()— append raw CLI arguments (escape hatch)with_timeout()— cap execution timecurrent_dir()/env()— control the subprocess environment
Under the hood, each command delegates to a shared CommandExecutor that
spawns git via tokio::process::Command, captures stdout/stderr, and
maps non-zero exits to Error::CommandFailed.
§The two-tier output model
Commands with unstructured output — porcelain that varies by git version,
locale, and config — return CommandOutput. Callers can treat stdout as
bytes or pass it through a parser in crate::parse.
Commands whose output is stable enough to decode return typed values directly. Examples:
InitCommandandCloneCommandreturnRepository.RevParseCommandreturns a trimmedString(typically a SHA or a boolean-ish literal).CatFileCommandreturns the object body as aString(or raw bytes viaexecute_bytesfor binary blobs).HashObjectCommandreturns the computed SHA.
§Escape hatches
Every command supports arg, args,
flag, and option. Raw args are
appended after the command’s typed flags, so they compose naturally:
let repo = Repository::open("/repo")?;
// `--shortstat` isn't on DiffCommand yet — fine, append it raw:
let out = repo.diff().cached().arg("--shortstat").execute().await?;
println!("{}", out.stdout_str());Modules§
- add
git add— add file contents to the index.- bisect
git bisect— find the commit that introduced a bug via binary search.- branch
git branch— list, create, or delete branches.- cat_
file git cat-file— provide content or type/size information for repository objects.- checkout
git checkout— switch branches or restore working tree files.- cherry_
pick git cherry-pick— apply the changes introduced by some existing commits.- clone
git clone— clone a repository into a new directory.- commit
git commit— record changes to the repository.- config
git config— get and set repository or global options.- describe
git describe— describe a commit using the most recent reachable tag.- diff
git diff— show changes between commits, trees, and the working tree.- fetch
git fetch— download objects and refs from another repository.- for_
each_ ref git for-each-ref— output information on each ref matching a pattern.- grep
git grep— print lines matching a pattern.- hash_
object git hash-object— compute object ID and optionally create a blob from a file.- init
git init— create an empty Git repository or reinitialize an existing one.- log
git log— show commit logs.- ls_
files git ls-files— show information about files in the index and working tree.- ls_tree
git ls-tree— list the contents of a tree object.- merge
git merge— join two or more development histories together.- mv
git mv— move or rename a file, directory, or symlink.- pull
git pull— fetch from and integrate with another repository or a local branch.- push
git push— update remote refs along with associated objects.- rebase
git rebase— reapply commits on top of another base tip.- reflog
git reflog— manage and inspect reflog information.- remote
git remote— manage set of tracked repositories.- reset
git reset— reset current HEAD to the specified state.- restore
git restore— restore working tree files.- rev_
parse git rev-parse— pick out and massage parameters.- rm
git rm— remove files from the working tree and from the index.- show
git show— show various types of objects.- show_
ref git show-ref— list references in a local repository.- stash
git stash— stash the changes in a dirty working directory away.- status
git status— show the working tree status.- submodule
git submodule— initialize, update, or inspect submodules.- switch
git switch— switch branches (modern successor tocheckout).- symbolic_
ref git symbolic-ref— read or modify a symbolic ref (most commonlyHEAD).- tag
git tag— create, list, delete, or verify tags.- update_
ref git update-ref— update the object name stored in a ref safely.- worktree
git worktree— manage multiple working trees attached to the same repository.
Structs§
- Command
Executor - Shared machinery used by every
GitCommandto spawngit. - Command
Output - Captured output from running a git command.
Constants§
- DEFAULT_
COMMAND_ TIMEOUT - Default timeout applied when none is configured on the executor.
Traits§
- GitCommand
- Trait implemented by every git subcommand wrapper.
Functions§
- find_
git - Locate the
gitbinary, returningError::GitNotFoundif missing. - git_
version - Run
git --versionand return the raw version string.