I am trying to clone a repository from Github through Rust. Does the git2 crate in Rust support pulling from a particular commit SHA?
I am trying to clone a repository from Github through Rust. Does the git2 crate in Rust support pulling from a particular commit SHA?
After you have cloned the repository, you can checkout the tree and set the head to the corresponding commit.
use git2::{Object, Oid, Repository};
fn main() {
let path = "/local/path/to/repo";
let repo = "https://github.com/.../...";
let commit = "77c8d299a614314461a7338757cc4ef9ec62ed31";
Repository::clone(repo, path).unwrap();
let repo: Repository = Repository::open(path).unwrap();
let obj: Object = repo.find_commit(Oid::from_str(commit).unwrap()).unwrap().into_object();
repo.checkout_tree(&obj, None).unwrap();
repo.set_head_detached(obj.id()).unwrap();
}