Skip to main content

Module repo

Module repo 

Source
Expand description

High-level handle for operating on a git repository.

A Repository is a cheap, cloneable reference to a working tree path. It is the entry point for most users: construct one via Repository::open, Repository::init, or Repository::clone, then call the accessor methods (Repository::add, Repository::commit, Repository::log, …) to build commands pre-scoped to this repo.

use git_spawn::{GitCommand, Repository};

// Create a fresh repo and commit a file into it.
let repo = Repository::init("/tmp/demo").await?;
std::fs::write(repo.path().join("hello.txt"), "hi")?;
repo.add().path("hello.txt").execute().await?;
repo.commit().message("first").execute().await?;

§Cloning an existing repo

let repo = Repository::clone(
    "https://github.com/octocat/Hello-World.git",
    "/tmp/hello-world",
).await?;
assert!(repo.git_dir().exists());

Structs§

Repository
A handle to a git working tree.