diff --git a/radicle-cli/examples/rad-init-no-seed.md b/radicle-cli/examples/rad-init-no-seed.md new file mode 100644 index 00000000..0597b3cc --- /dev/null +++ b/radicle-cli/examples/rad-init-no-seed.md @@ -0,0 +1,29 @@ +If we initialize a public repository without seeding it, it won't be advertized: +``` +$ rad init --name heartwood --description "radicle heartwood protocol & stack" --no-confirm --public --no-seed + +Initializing public radicle 👾 repository in [..] + +✓ Repository heartwood created. + +Your Repository ID (RID) is rad:zhbMU4DUXrzB8xT6qAJh6yZ7bFMK. +You can show it any time by running `rad .` from this directory. + +Your repository will be announced to the network when you start your node. +You can start your node with `rad node start`. +To push changes, run `git push`. +``` +``` +$ rad node inventory +``` + +If we then seed it, it becomes advertized in our inventory: +``` +$ rad seed rad:zhbMU4DUXrzB8xT6qAJh6yZ7bFMK +✓ Inventory updated with rad:zhbMU4DUXrzB8xT6qAJh6yZ7bFMK +✓ Seeding policy updated for rad:zhbMU4DUXrzB8xT6qAJh6yZ7bFMK with scope 'all' +``` +``` +$ rad node inventory +rad:zhbMU4DUXrzB8xT6qAJh6yZ7bFMK +``` diff --git a/radicle-cli/examples/rad-init-private-no-seed.md b/radicle-cli/examples/rad-init-private-no-seed.md new file mode 100644 index 00000000..575ad8ef --- /dev/null +++ b/radicle-cli/examples/rad-init-private-no-seed.md @@ -0,0 +1,34 @@ +Let's say we initialize a private repository and specify that we don't want it +to be seeded. +``` +$ rad init --name heartwood --description "radicle heartwood protocol & stack" --no-confirm --private --no-seed + +Initializing private radicle 👾 repository in [..] + +✓ Repository heartwood created. + +Your Repository ID (RID) is rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu. +You can show it any time by running `rad .` from this directory. + +You have created a private repository. +This repository will only be visible to you, and to peers you explicitly allow. + +To make it public, run `rad publish`. +To push changes, run `git push`. +``` + +``` +$ rad seed +No seeding policies to show. +``` + +We can decide to seed it later: +``` +$ rad seed rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu +✓ Seeding policy updated for rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu with scope 'all' +``` + +But it still won't show up in our inventory, since it's private: +``` +$ rad node inventory +``` diff --git a/radicle-cli/examples/rad-init-private.md b/radicle-cli/examples/rad-init-private.md index ff44f6e5..02654415 100644 --- a/radicle-cli/examples/rad-init-private.md +++ b/radicle-cli/examples/rad-init-private.md @@ -16,3 +16,15 @@ This repository will only be visible to you, and to peers you explicitly allow. To make it public, run `rad publish`. To push changes, run `git push`. ``` + +The repository does not show up in our inventory, since it is not advertized, +despite being seeded: +``` +$ rad node inventory +$ rad seed +╭────────────────────────────────────────────────────────────────╮ +│ Repository Name Policy Scope │ +├────────────────────────────────────────────────────────────────┤ +│ rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu heartwood allow all │ +╰────────────────────────────────────────────────────────────────╯ +``` diff --git a/radicle-cli/examples/rad-init.md b/radicle-cli/examples/rad-init.md index 36d84702..f2eef99b 100644 --- a/radicle-cli/examples/rad-init.md +++ b/radicle-cli/examples/rad-init.md @@ -29,7 +29,7 @@ $ rad init ✗ Error: repository is already initialized with remote rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji ``` -Projects can be listed with the `ls` command: +Repositories can be listed with the `ls` command: ``` $ rad ls @@ -39,3 +39,10 @@ $ rad ls │ heartwood rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji public f2de534 Radicle Heartwood Protocol & Stack │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ``` + +Public repositories are added to our inventory: + +``` +$ rad node inventory +rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji +``` diff --git a/radicle-cli/examples/rad-node.md b/radicle-cli/examples/rad-node.md index f5b2688e..8a0ec5f2 100644 --- a/radicle-cli/examples/rad-node.md +++ b/radicle-cli/examples/rad-node.md @@ -92,7 +92,7 @@ Note that if we unseed a repository, it is no longer part of our inventory: ``` $ rad unseed rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji ✓ Seeding policy for rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji removed -$ rad node routing --nid z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi +$ rad node inventory ``` Likewise, if we seed a repository we don't have locally, it won't show up as @@ -100,20 +100,17 @@ part of our inventory: ``` $ rad seed rad:z3trNYnLWS11cJWC6BbxDs5niGo82 [...] -$ rad node routing --nid z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi +$ rad node inventory ``` But if we start seeding the repository we have locally again, it'll show up in our inventory: ``` $ rad seed rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji -[...] -$ rad node routing --nid z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi -╭─────────────────────────────────────────────────────╮ -│ RID NID │ -├─────────────────────────────────────────────────────┤ -│ rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji z6MknSL…StBU8Vi │ -╰─────────────────────────────────────────────────────╯ +✓ Inventory updated with rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji +✓ Seeding policy updated for rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji with scope 'all' +$ rad node inventory +rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji ``` Some commands also give us a hint if the node isn't running: diff --git a/radicle-cli/examples/rad-publish.md b/radicle-cli/examples/rad-publish.md index 75ed34e7..e1145a00 100644 --- a/radicle-cli/examples/rad-publish.md +++ b/radicle-cli/examples/rad-publish.md @@ -3,13 +3,21 @@ Let's say we have a private repo. To make it public, we use the `publish` comman ``` $ rad inspect --visibility private +$ rad node inventory $ rad publish +✓ Updating inventory.. ✓ Repository is now public ! Warning: Your node is not running. Start your node with `rad node start` to announce your repository to the network $ rad inspect --visibility public ``` +The repository is now in our inventory: +``` +$ rad node inventory +rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu +``` + If we try to publish again, we get an error: ``` (fail) diff --git a/radicle-cli/examples/rad-unseed.md b/radicle-cli/examples/rad-unseed.md index 4f07caf7..f258e51e 100644 --- a/radicle-cli/examples/rad-unseed.md +++ b/radicle-cli/examples/rad-unseed.md @@ -35,3 +35,11 @@ $ rad ls --all │ heartwood rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji local f2de534 Radicle Heartwood Protocol & Stack │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ``` + +Hence, we also see that it isn't in our inventory and isn't seeded: + +``` +$ rad node inventory +$ rad seed +No seeding policies to show. +``` diff --git a/radicle-cli/src/commands/publish.rs b/radicle-cli/src/commands/publish.rs index d340689e..01d81d3b 100644 --- a/radicle-cli/src/commands/publish.rs +++ b/radicle-cli/src/commands/publish.rs @@ -114,18 +114,19 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> { } anyhow::bail!("fatal: repository storage is corrupt"); } + let mut node = radicle::Node::new(profile.socket()); + let spinner = term::spinner("Updating inventory.."); + + // The repository is now part of our inventory. + profile.add_inventory(rid, &mut node)?; + spinner.finish(); term::success!( "Repository is now {}", term::format::visibility(&doc.visibility) ); - let mut node = radicle::Node::new(profile.socket()); - if node.is_running() { - let spinner = term::spinner("Announcing to network.."); - node.announce_inventory()?; - spinner.finish(); - } else { + if !node.is_running() { term::warning(format!( "Your node is not running. Start your node with {} to announce your repository \ to the network", diff --git a/radicle-cli/src/commands/seed.rs b/radicle-cli/src/commands/seed.rs index 133dfd2f..ddda1f99 100644 --- a/radicle-cli/src/commands/seed.rs +++ b/radicle-cli/src/commands/seed.rs @@ -137,6 +137,13 @@ pub fn update( let updated = profile.seed(rid, scope, node)?; let outcome = if updated { "updated" } else { "exists" }; + if let Ok(repo) = profile.storage.repository(rid) { + if repo.identity_doc()?.visibility.is_public() { + profile.add_inventory(rid, node)?; + term::success!("Inventory updated with {}", term::format::tertiary(rid)); + } + } + term::success!( "Seeding policy {outcome} for {} with scope '{scope}'", term::format::tertiary(rid), diff --git a/radicle-cli/tests/commands.rs b/radicle-cli/tests/commands.rs index 9f0efd82..d1092ff6 100644 --- a/radicle-cli/tests/commands.rs +++ b/radicle-cli/tests/commands.rs @@ -201,6 +201,23 @@ fn rad_init() { .unwrap(); } +#[test] +fn rad_init_no_seed() { + let mut environment = Environment::new(); + let alice = environment.node(Config::test(Alias::new("alice"))); + let working = environment.tmp().join("working"); + + fixtures::repository(working.join("alice")); + + test( + "examples/rad-init-no-seed.md", + working.join("alice"), + Some(&alice.home), + [], + ) + .unwrap(); +} + #[test] fn rad_init_with_existing_remote() { let mut environment = Environment::new(); @@ -2168,6 +2185,23 @@ fn rad_init_private() { .unwrap(); } +#[test] +fn rad_init_private_no_seed() { + let mut environment = Environment::new(); + let alice = environment.node(Config::test(Alias::new("alice"))); + let working = environment.tmp().join("working"); + + fixtures::repository(working.join("alice")); + + test( + "examples/rad-init-private-no-seed.md", + working.join("alice"), + Some(&alice.home), + [], + ) + .unwrap(); +} + #[test] fn rad_init_private_seed() { let mut environment = Environment::new(); diff --git a/radicle/src/profile.rs b/radicle/src/profile.rs index e9d941b4..b76f82cd 100644 --- a/radicle/src/profile.rs +++ b/radicle/src/profile.rs @@ -32,7 +32,7 @@ use crate::node::{ use crate::prelude::{Did, NodeId, RepoId}; use crate::storage::git::transport; use crate::storage::git::Storage; -use crate::storage::{ReadRepository, ReadStorage}; +use crate::storage::ReadRepository; use crate::{cli, cob, git, node, storage, web}; /// Environment variables used by radicle. @@ -453,15 +453,9 @@ impl Profile { Ok(updated) => Ok(updated), Err(e) if e.is_connection_err() => { let mut config = self.policies_mut()?; - let result = config.seed(&rid, scope)?; + let updated = config.seed(&rid, scope)?; - if result && self.storage.contains(&rid)? { - let now = LocalTime::now(); - let mut db = self.database_mut()?; - - node::routing::Store::add_inventory(&mut db, [&rid], *self.id(), now.into())?; - } - Ok(result) + Ok(updated) } Err(e) => Err(e.into()), }