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

Should have been part of 8af164aa4ea96a7bf5de2d49c409fb28a4f62b01

6 files changed +139 -8 eea36177 52e55812
added crates/radicle-cli/examples/rad-clone-scope.md
@@ -0,0 +1,63 @@
+
By default `rad clone` should add a seeding policy with the `followed` scope:
+

+
```
+
$ rad clone rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji
+
✓ Seeding policy updated for rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji with scope 'followed'
+
✓ Creating checkout in ./heartwood..
+
✓ Repository successfully cloned under [..]/heartwood/
+
╭────────────────────────────────────╮
+
│ heartwood                          │
+
│ Radicle Heartwood Protocol & Stack │
+
│ 0 issues · 0 patches               │
+
╰────────────────────────────────────╯
+
Run `cd ./heartwood` to go to the repository directory.
+
$ rad seed
+
╭───────────────────────────────────────────────────────────────────╮
+
│ Repository                          Name        Policy   Scope    │
+
├───────────────────────────────────────────────────────────────────┤
+
│ rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji   heartwood   allow    followed │
+
╰───────────────────────────────────────────────────────────────────╯
+
$ rm -rf heartwood
+
```
+

+
Specifying a different scope explicitly should update the policy:
+

+
```
+
$ rad clone rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji --scope all
+
✓ Seeding policy updated for rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji with scope 'all'
+
✓ Creating checkout in ./heartwood..
+
✓ Repository successfully cloned under [..]/heartwood/
+
╭────────────────────────────────────╮
+
│ heartwood                          │
+
│ Radicle Heartwood Protocol & Stack │
+
│ 0 issues · 0 patches               │
+
╰────────────────────────────────────╯
+
Run `cd ./heartwood` to go to the repository directory.
+
$ rad seed
+
╭────────────────────────────────────────────────────────────────╮
+
│ Repository                          Name        Policy   Scope │
+
├────────────────────────────────────────────────────────────────┤
+
│ rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji   heartwood   allow    all   │
+
╰────────────────────────────────────────────────────────────────╯
+
$ rm -rf heartwood
+
```
+

+
Running `rad clone` again without an explicit scope parameter should not change the existing policy:
+

+
```
+
$ rad clone rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji
+
✓ Creating checkout in ./heartwood..
+
✓ Repository successfully cloned under [..]/heartwood/
+
╭────────────────────────────────────╮
+
│ heartwood                          │
+
│ Radicle Heartwood Protocol & Stack │
+
│ 0 issues · 0 patches               │
+
╰────────────────────────────────────╯
+
Run `cd ./heartwood` to go to the repository directory.
+
$ rad seed
+
╭────────────────────────────────────────────────────────────────╮
+
│ Repository                          Name        Policy   Scope │
+
├────────────────────────────────────────────────────────────────┤
+
│ rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji   heartwood   allow    all   │
+
╰────────────────────────────────────────────────────────────────╯
+
```
added crates/radicle-cli/examples/rad-seed-scope.md
@@ -0,0 +1,38 @@
+
By default `rad seed` should add a seeding policy with the `followed` scope:
+

+
```
+
$ rad seed --no-fetch rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji
+
✓ Seeding policy updated for rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji with scope 'followed'
+
$ rad seed
+
╭──────────────────────────────────────────────────────────────╮
+
│ Repository                          Name   Policy   Scope    │
+
├──────────────────────────────────────────────────────────────┤
+
│ rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji          allow    followed │
+
╰──────────────────────────────────────────────────────────────╯
+
```
+

+
The policy can be updated by explicitly specifying a different scope:
+

+
```
+
$ rad seed --no-fetch rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji --scope all
+
✓ Seeding policy updated for rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji with scope 'all'
+
$ rad seed
+
╭───────────────────────────────────────────────────────────╮
+
│ Repository                          Name   Policy   Scope │
+
├───────────────────────────────────────────────────────────┤
+
│ rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji          allow    all   │
+
╰───────────────────────────────────────────────────────────╯
+
```
+

+
Running `rad seed` again without an explicit scope parameter should not change the existing policy:
+

+
```
+
$ rad seed --no-fetch rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji
+
✓ Seeding policy exists for rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji with scope 'all'
+
$ rad seed
+
╭───────────────────────────────────────────────────────────╮
+
│ Repository                          Name   Policy   Scope │
+
├───────────────────────────────────────────────────────────┤
+
│ rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji          allow    all   │
+
╰───────────────────────────────────────────────────────────╯
+
```
modified crates/radicle-cli/src/commands/seed.rs
@@ -41,10 +41,19 @@ pub fn run(args: Args, ctx: impl term::Context) -> anyhow::Result<()> {

pub fn update(
    rid: RepoId,
-
    scope: Scope,
+
    scope: Option<Scope>,
    node: &mut Node,
    profile: &Profile,
) -> Result<(), anyhow::Error> {
+
    let scope = match scope {
+
        Some(scope) => scope,
+
        None => profile
+
            .policies()?
+
            .seed_policy(&rid)?
+
            .scope()
+
            .unwrap_or(Scope::Followed),
+
    };
+

    let updated = profile.seed(rid, scope, node)?;
    let outcome = if updated { "updated" } else { "exists" };

modified crates/radicle-cli/src/commands/seed/args.rs
@@ -47,12 +47,8 @@ pub struct Args {
    timeout: u64,

    /// Peer follow scope for this repository
-
    #[arg(
-
        long,
-
        default_value_t = Scope::Followed,
-
        value_parser = terminal::args::ScopeParser
-
    )]
-
    pub(super) scope: Scope,
+
    #[arg(long, value_parser = terminal::args::ScopeParser)]
+
    pub(super) scope: Option<Scope>,

    /// Verbose output
    #[arg(long, short)]
@@ -65,7 +61,7 @@ pub(super) enum Operation {
        rids: NonEmpty<RepoId>,
        should_fetch: bool,
        settings: SyncSettings,
-
        scope: Scope,
+
        scope: Option<Scope>,
    },
}

modified crates/radicle-cli/tests/commands/clone.rs
@@ -295,3 +295,23 @@ fn test_clone_without_seeds() {
        .rad("inspect", &[], working.join("heartwood").as_path())
        .unwrap();
}
+

+
#[test]
+
fn rad_clone_scope() {
+
    let mut environment = Environment::new();
+
    let mut alice = environment.node("alice");
+
    let working = environment.tempdir().join("working");
+

+
    let rid = alice.project("heartwood", "Radicle Heartwood Protocol & Stack");
+

+
    let mut alice = alice.spawn();
+
    alice.handle.unseed(rid).unwrap();
+

+
    test(
+
        "examples/rad-clone-scope.md",
+
        working,
+
        Some(&alice.home),
+
        [],
+
    )
+
    .unwrap();
+
}
modified crates/radicle-cli/tests/commands/policy.rs
@@ -10,6 +10,11 @@ fn rad_seed_and_follow() {
}

#[test]
+
fn rad_seed_scope() {
+
    Environment::alice(["rad-seed-scope"]);
+
}
+

+
#[test]
fn rad_seed_many() {
    let mut environment = Environment::new();
    let alice = environment.node("alice");