Add `rad-clone` initial sketch
Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
This commit is contained in:
parent
c8bff35229
commit
5b673c7440
|
|
@ -32,3 +32,7 @@ path = "src/rad-push.rs"
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "rad-agent"
|
name = "rad-agent"
|
||||||
path = "src/rad-agent.rs"
|
path = "src/rad-agent.rs"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "rad-clone"
|
||||||
|
path = "src/rad-clone.rs"
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
use std::env;
|
||||||
|
use std::path::Path;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
use radicle::identity::Id;
|
||||||
|
|
||||||
|
fn main() -> anyhow::Result<()> {
|
||||||
|
let cwd = Path::new(".").canonicalize()?;
|
||||||
|
let profile = radicle::Profile::load()?;
|
||||||
|
|
||||||
|
if let Some(id) = env::args().nth(1) {
|
||||||
|
let id = Id::from_str(&id)?;
|
||||||
|
let node = profile.node()?;
|
||||||
|
let repo = radicle::rad::clone(id, &cwd, &profile.signer, &profile.storage, &node)?;
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"ok: project {id} cloned into `{}`",
|
||||||
|
repo.workdir().unwrap().display()
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
anyhow::bail!("Error: a project id must be specified");
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
@ -215,6 +215,7 @@ pub fn clone<P: AsRef<Path>, G: Signer, S: storage::WriteStorage, H: node::Handl
|
||||||
storage: &S,
|
storage: &S,
|
||||||
handle: &H,
|
handle: &H,
|
||||||
) -> Result<git2::Repository, CloneError> {
|
) -> Result<git2::Repository, CloneError> {
|
||||||
|
let _ = handle.track(&proj)?;
|
||||||
let _ = handle.fetch(&proj)?;
|
let _ = handle.fetch(&proj)?;
|
||||||
let _ = fork(proj, signer, storage)?;
|
let _ = fork(proj, signer, storage)?;
|
||||||
let working = checkout(proj, signer.public_key(), path, storage)?;
|
let working = checkout(proj, signer.public_key(), path, storage)?;
|
||||||
|
|
@ -276,7 +277,7 @@ pub fn checkout<P: AsRef<Path>, S: storage::ReadStorage>(
|
||||||
let mut opts = git2::RepositoryInitOptions::new();
|
let mut opts = git2::RepositoryInitOptions::new();
|
||||||
opts.no_reinit(true).description(&project.description);
|
opts.no_reinit(true).description(&project.description);
|
||||||
|
|
||||||
let repo = git2::Repository::init_opts(path, &opts)?;
|
let repo = git2::Repository::init_opts(path.as_ref().join(&project.name), &opts)?;
|
||||||
let url = storage.url(&proj);
|
let url = storage.url(&proj);
|
||||||
|
|
||||||
// Configure and fetch all refs from remote.
|
// Configure and fetch all refs from remote.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue