From b0400984478df19c282496df8d36bf4cbedc7abd Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Tue, 8 Nov 2022 15:25:19 +0100 Subject: [PATCH] Add `rad-clone` command Signed-off-by: Alexis Sellier --- radicle-cli/src/commands.rs | 2 + radicle-cli/src/commands/checkout.rs | 6 +- radicle-cli/src/commands/clone.rs | 127 +++++++++++++++++++++++++++ 3 files changed, 132 insertions(+), 3 deletions(-) create mode 100644 radicle-cli/src/commands/clone.rs diff --git a/radicle-cli/src/commands.rs b/radicle-cli/src/commands.rs index 64e5cf32..218e411e 100644 --- a/radicle-cli/src/commands.rs +++ b/radicle-cli/src/commands.rs @@ -2,6 +2,8 @@ pub mod rad_auth; #[path = "commands/checkout.rs"] pub mod rad_checkout; +#[path = "commands/clone.rs"] +pub mod rad_clone; #[path = "commands/help.rs"] pub mod rad_help; #[path = "commands/init.rs"] diff --git a/radicle-cli/src/commands/checkout.rs b/radicle-cli/src/commands/checkout.rs index b1c8eb2e..1a06903e 100644 --- a/radicle-cli/src/commands/checkout.rs +++ b/radicle-cli/src/commands/checkout.rs @@ -115,8 +115,8 @@ pub fn execute(options: Options, profile: &Profile) -> anyhow::Result { .filter(|id| id != profile.id()) .collect::>(); - // Setup tracking for project delegates. - setup_tracking( + // Setup remote tracking branches for project delegates. + setup_remotes( project::SetupRemote { project: id, default_branch: payload.default_branch, @@ -131,7 +131,7 @@ pub fn execute(options: Options, profile: &Profile) -> anyhow::Result { } /// Setup a remote and tracking branch for each given remote. -pub fn setup_tracking(setup: project::SetupRemote, remotes: &[NodeId]) -> anyhow::Result<()> { +pub fn setup_remotes(setup: project::SetupRemote, remotes: &[NodeId]) -> anyhow::Result<()> { for remote_id in remotes { if let Some((remote, branch)) = setup.run(*remote_id)? { let remote = remote.name().unwrap(); // Only valid UTF-8 is used. diff --git a/radicle-cli/src/commands/clone.rs b/radicle-cli/src/commands/clone.rs new file mode 100644 index 00000000..9182bb66 --- /dev/null +++ b/radicle-cli/src/commands/clone.rs @@ -0,0 +1,127 @@ +#![allow(clippy::or_fun_call)] +use std::ffi::OsString; +use std::path::Path; +use std::str::FromStr; + +use anyhow::anyhow; +use anyhow::Context as _; + +use radicle::node::Handle; +use radicle::prelude::*; +use radicle::rad; +use radicle::storage::WriteStorage; + +use crate::commands::rad_checkout::setup_remotes; +use crate::project; +use crate::terminal as term; +use crate::terminal::args::{Args, Error, Help}; +use crate::terminal::Interactive; + +pub const HELP: Help = Help { + name: "clone", + description: "Clone radicle projects", + version: env!("CARGO_PKG_VERSION"), + usage: r#" +Usage + + rad clone [