Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
cli: don't override existing seeding scope in `rad clone`
Merged Defelo opened 2 months ago

If I’m already seeding a repository, rad clone without an explicit --scope should not change the scope of the existing seeding policy.

2 files changed +14 -4 b04f487b e9245b63
modified crates/radicle-cli/src/commands/clone.rs
@@ -9,8 +9,8 @@ use thiserror::Error;
use radicle::git::raw;
use radicle::identity::doc;
use radicle::identity::doc::RepoId;
-
use radicle::node;
use radicle::node::policy::Scope;
+
use radicle::node::{self, policy};
use radicle::node::{Handle as _, Node};
use radicle::prelude::*;
use radicle::rad;
@@ -121,6 +121,8 @@ enum CloneError {
    NoSeeds(RepoId),
    #[error("fetch: {0}")]
    Fetch(#[from] sync::FetchError),
+
    #[error("policy store: {0}")]
+
    PolicyStore(#[from] policy::store::Error),
}

struct Checkout {
@@ -203,12 +205,21 @@ impl Checkout {
fn clone(
    id: RepoId,
    directory: Option<PathBuf>,
-
    scope: Scope,
+
    scope: Option<Scope>,
    settings: SyncSettings,
    node: &mut Node,
    profile: &Profile,
    bare: bool,
) -> Result<CloneResult, CloneError> {
+
    let scope = match scope {
+
        Some(scope) => scope,
+
        None => profile
+
            .policies()?
+
            .seed_policy(&id)?
+
            .scope()
+
            .unwrap_or(Scope::Followed),
+
    };
+

    // Seed repository.
    if node.seed(id, scope)? {
        term::success!(
modified crates/radicle-cli/src/commands/clone/args.rs
@@ -62,10 +62,9 @@ pub struct Args {
    /// Follow scope
    #[arg(
        long,
-
        default_value_t = Scope::Followed,
        value_parser = terminal::args::ScopeParser
    )]
-
    pub(super) scope: Scope,
+
    pub(super) scope: Option<Scope>,

    #[clap(flatten)]
    pub(super) sync: SyncArgs,