From 5b673c7440efc032807378e7fb555623b867f5fe Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Mon, 3 Oct 2022 11:50:43 +0200 Subject: [PATCH] Add `rad-clone` initial sketch Signed-off-by: Alexis Sellier --- radicle-tools/Cargo.toml | 4 ++++ radicle-tools/src/rad-clone.rs | 25 +++++++++++++++++++++++++ radicle/src/rad.rs | 3 ++- 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 radicle-tools/src/rad-clone.rs diff --git a/radicle-tools/Cargo.toml b/radicle-tools/Cargo.toml index c6b8fc61..a9f16221 100644 --- a/radicle-tools/Cargo.toml +++ b/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" diff --git a/radicle-tools/src/rad-clone.rs b/radicle-tools/src/rad-clone.rs new file mode 100644 index 00000000..2dba981b --- /dev/null +++ b/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(()) +} diff --git a/radicle/src/rad.rs b/radicle/src/rad.rs index a7ef9dbf..2f7f7ab0 100644 --- a/radicle/src/rad.rs +++ b/radicle/src/rad.rs @@ -215,6 +215,7 @@ pub fn clone, G: Signer, S: storage::WriteStorage, H: node::Handl storage: &S, handle: &H, ) -> Result { + 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, 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.