From 5ae617abf096d31181496e6b5b048e81872c462f Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Mon, 18 Mar 2024 13:00:32 +0100 Subject: [PATCH] helper: Don't sync if we aren't seeding --- radicle-cli/examples/git/git-push.md | 1 + radicle-cli/examples/rad-sync.md | 10 ++++++++++ radicle-remote-helper/src/push.rs | 25 ++++++++++++++++--------- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/radicle-cli/examples/git/git-push.md b/radicle-cli/examples/git/git-push.md index d216d7a9..9abbaa9d 100644 --- a/radicle-cli/examples/git/git-push.md +++ b/radicle-cli/examples/git/git-push.md @@ -71,6 +71,7 @@ error: failed to push some refs to 'rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLr ``` If you pass an unsupported push option, you get an error: + ``` (stderr) (fail) $ git push -o alien rad HEAD:alice/2 error: unknown push option "alien" diff --git a/radicle-cli/examples/rad-sync.md b/radicle-cli/examples/rad-sync.md index 47047ed5..e2444639 100644 --- a/radicle-cli/examples/rad-sync.md +++ b/radicle-cli/examples/rad-sync.md @@ -109,3 +109,13 @@ $ rad sync rad:z39mP9rQAaGmERfUMPULfPUi473tY ✗ Error: no seeds found for rad:z39mP9rQAaGmERfUMPULfPUi473tY ✗ Error: nothing to announce, repository rad:z39mP9rQAaGmERfUMPULfPUi473tY is not available locally ``` + +Also note that you cannot sync an unseeded repo: +``` +$ rad unseed rad:z39mP9rQAaGmERfUMPULfPUi473tY +[...] +``` +``` (fail) +$ rad sync rad:z39mP9rQAaGmERfUMPULfPUi473tY +✗ Error: repository rad:z39mP9rQAaGmERfUMPULfPUi473tY is not seeded +``` diff --git a/radicle-remote-helper/src/push.rs b/radicle-remote-helper/src/push.rs index a5763502..48ff27f8 100644 --- a/radicle-remote-helper/src/push.rs +++ b/radicle-remote-helper/src/push.rs @@ -90,6 +90,9 @@ pub enum Error { /// Patch edit message error. #[error(transparent)] PatchEdit(#[from] cli::patch::Error), + /// Policy config error. + #[error("node policy: {0}")] + Policy(#[from] node::policy::config::Error), /// Patch not found in store. #[error("patch `{0}` not found")] NotFound(patch::PatchId), @@ -332,16 +335,20 @@ pub fn run( } if !opts.no_sync { - // Connect to local node and announce refs to the network. - // If our node is not running, we simply skip this step, as the - // refs will be announced eventually, when the node restarts. - let node = radicle::Node::new(profile.socket()); - if node.is_running() { - // Nb. allow this to fail. The push to local storage was still successful. - sync(stored.id, ok.into_values().flatten(), node, profile).ok(); + if profile.policies()?.is_seeding(&stored.id)? { + // Connect to local node and announce refs to the network. + // If our node is not running, we simply skip this step, as the + // refs will be announced eventually, when the node restarts. + let node = radicle::Node::new(profile.socket()); + if node.is_running() { + // Nb. allow this to fail. The push to local storage was still successful. + sync(stored.id, ok.into_values().flatten(), node, profile).ok(); + } else if hints { + hint("offline push, your node is not running"); + hint("to sync with the network, run `rad node start`"); + } } else if hints { - hint("offline push, your node is not running"); - hint("to sync with the network, run `rad node start`"); + hint("you are not seeding this repository; skipping sync"); } } }