node: Implement project checkout

Signed-off-by: Alexis Sellier <self@cloudhead.io>
This commit is contained in:
Alexis Sellier
2022-09-13 10:16:05 +02:00
parent 09265eb3da
commit 4e9b60dee0
6 changed files with 154 additions and 23 deletions
+8 -1
View File
@@ -1,6 +1,7 @@
use std::collections::{BTreeMap, HashSet};
use std::hash::Hash;
use std::ops::RangeBounds;
use std::path::PathBuf;
use nonempty::NonEmpty;
use quickcheck::Arbitrary;
@@ -56,8 +57,14 @@ impl Arbitrary for Project {
let doc = Doc::arbitrary(g);
let id = doc.write(&mut buf).unwrap();
let remotes = storage::Remotes::arbitrary(g);
let path = PathBuf::arbitrary(g);
Self { id, doc, remotes }
Self {
id,
doc,
remotes,
path,
}
}
}
+12
View File
@@ -63,6 +63,18 @@ pub fn storage<P: AsRef<Path>>(path: P) -> Storage {
storages.pop().unwrap()
}
/// Creates a regular repository at the given path with a couple of commits.
pub fn repository<P: AsRef<Path>>(path: P) -> git2::Repository {
let repo = git2::Repository::init(path).unwrap();
{
let sig = git2::Signature::now("anonymous", "anonymous@radicle.xyz").unwrap();
let head = git::initial_commit(&repo, &sig).unwrap();
let head = git::commit(&repo, &head, "Second commit", "anonymous").unwrap();
let _branch = repo.branch("master", &head, false).unwrap();
}
repo
}
#[cfg(test)]
mod tests {
use super::*;