helper: Don't sync if we aren't seeding

This commit is contained in:
Alexis Sellier 2024-03-18 13:00:32 +01:00
parent 623ef278d0
commit 5ae617abf0
No known key found for this signature in database
3 changed files with 27 additions and 9 deletions

View File

@ -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: If you pass an unsupported push option, you get an error:
``` (stderr) (fail) ``` (stderr) (fail)
$ git push -o alien rad HEAD:alice/2 $ git push -o alien rad HEAD:alice/2
error: unknown push option "alien" error: unknown push option "alien"

View File

@ -109,3 +109,13 @@ $ rad sync rad:z39mP9rQAaGmERfUMPULfPUi473tY
✗ Error: no seeds found for rad:z39mP9rQAaGmERfUMPULfPUi473tY ✗ Error: no seeds found for rad:z39mP9rQAaGmERfUMPULfPUi473tY
✗ Error: nothing to announce, repository rad:z39mP9rQAaGmERfUMPULfPUi473tY is not available locally ✗ 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
```

View File

@ -90,6 +90,9 @@ pub enum Error {
/// Patch edit message error. /// Patch edit message error.
#[error(transparent)] #[error(transparent)]
PatchEdit(#[from] cli::patch::Error), PatchEdit(#[from] cli::patch::Error),
/// Policy config error.
#[error("node policy: {0}")]
Policy(#[from] node::policy::config::Error),
/// Patch not found in store. /// Patch not found in store.
#[error("patch `{0}` not found")] #[error("patch `{0}` not found")]
NotFound(patch::PatchId), NotFound(patch::PatchId),
@ -332,16 +335,20 @@ pub fn run(
} }
if !opts.no_sync { if !opts.no_sync {
// Connect to local node and announce refs to the network. if profile.policies()?.is_seeding(&stored.id)? {
// If our node is not running, we simply skip this step, as the // Connect to local node and announce refs to the network.
// refs will be announced eventually, when the node restarts. // If our node is not running, we simply skip this step, as the
let node = radicle::Node::new(profile.socket()); // refs will be announced eventually, when the node restarts.
if node.is_running() { let node = radicle::Node::new(profile.socket());
// Nb. allow this to fail. The push to local storage was still successful. if node.is_running() {
sync(stored.id, ok.into_values().flatten(), node, profile).ok(); // 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 { } else if hints {
hint("offline push, your node is not running"); hint("you are not seeding this repository; skipping sync");
hint("to sync with the network, run `rad node start`");
} }
} }
} }