Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
Add `rad-clone` initial sketch
Alexis Sellier committed 3 years ago
commit 5b673c7440efc032807378e7fb555623b867f5fe
parent c8bff352296a54ade1b87260833726527d6eea1a
3 files changed +31 -1
modified radicle-tools/Cargo.toml
@@ -32,3 +32,7 @@ path = "src/rad-push.rs"
[[bin]]
name = "rad-agent"
path = "src/rad-agent.rs"
+

+
[[bin]]
+
name = "rad-clone"
+
path = "src/rad-clone.rs"
added radicle-tools/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(())
+
}
modified radicle/src/rad.rs
@@ -215,6 +215,7 @@ pub fn clone<P: AsRef<Path>, G: Signer, S: storage::WriteStorage, H: node::Handl
    storage: &S,
    handle: &H,
) -> Result<git2::Repository, CloneError> {
+
    let _ = handle.track(&proj)?;
    let _ = handle.fetch(&proj)?;
    let _ = fork(proj, signer, 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();
    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);

    // Configure and fetch all refs from remote.