Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli: Change rad init default to not announce
✗ 0/1 checks passed ade wants to merge 3 commits into master · opened 2 months ago

As part of the continued effort of safe by default, rad init has been updated to --no-announce, --announce has been introduced to enable the prior behaviour. Additionally a message is supplied to the user about their repository not being announced.

Some checks failed — 0 passed, 1 failed View logs ↗
14 files changed +104 -18 b04f487b 94f6f11f
added crates/radicle-cli/examples/rad-init-no-announce.md
@@ -0,0 +1,47 @@
+
To create your first radicle repository, navigate to a git repository, and run the
+
`init` command. Make sure you have [authenticated](../rad-auth.md) beforehand.
+

+
```
+
$ rad init --name heartwood --description "Radicle Heartwood Protocol & Stack" --no-confirm --public -v
+

+
Initializing public radicle 👾 repository in [..]
+

+
✓ Repository heartwood created.
+
{
+
  "name": "heartwood",
+
  "description": "Radicle Heartwood Protocol & Stack",
+
  "defaultBranch": "master"
+
}
+

+
Your Repository ID (RID) is rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji.
+
You can show it any time by running `rad .` from this directory.
+

+
Your repository has not been announced to the network, run `rad sync --announce` when you're ready.
+

+
To push changes, run `git push`.
+
```
+

+
If we try to initialize it again, we get an error:
+

+
```(fail)
+
$ rad init
+
✗ Error: repository is already initialized with remote rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji
+
```
+

+
Repositories can be listed with the `ls` command:
+

+
```
+
$ rad ls
+
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────╮
+
│ Name        RID                                 Visibility   Head      Description                        │
+
├───────────────────────────────────────────────────────────────────────────────────────────────────────────┤
+
│ heartwood   rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji   public       f2de534   Radicle Heartwood Protocol & Stack │
+
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────╯
+
```
+

+
Public repositories are added to our inventory:
+

+
```
+
$ rad node inventory
+
rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji
+
```
modified crates/radicle-cli/examples/rad-init-no-seed.md
@@ -1,6 +1,7 @@
If we initialize a public repository without seeding it, it won't be advertised:
+

```
-
$ rad init --name heartwood --description "radicle heartwood protocol & stack" --no-confirm --public --no-seed
+
$ rad init --name heartwood --description "radicle heartwood protocol & stack" --no-confirm --public --no-seed --announce

Initializing public radicle 👾 repository in [..]

@@ -13,16 +14,19 @@ 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 advertised in our inventory:
+

```
$ rad seed rad:zhbMU4DUXrzB8xT6qAJh6yZ7bFMK
✓ Inventory updated with rad:zhbMU4DUXrzB8xT6qAJh6yZ7bFMK
✓ Seeding policy updated for rad:zhbMU4DUXrzB8xT6qAJh6yZ7bFMK with scope 'followed'
```
+

```
$ rad node inventory
rad:zhbMU4DUXrzB8xT6qAJh6yZ7bFMK
modified crates/radicle-cli/examples/rad-init-private-no-seed.md
@@ -3,7 +3,7 @@ to be seeded. This means that the repo will be available locally, to us,
and even if other peers know about it, they won't be able to fetch it
from us.
```
-
$ rad init --name heartwood --description "radicle heartwood protocol & stack" --no-confirm --private --no-seed
+
$ rad init --name heartwood --description "radicle heartwood protocol & stack" --no-confirm --private --no-seed --announce

Initializing private radicle 👾 repository in [..]

modified crates/radicle-cli/examples/rad-init-private.md
@@ -1,7 +1,7 @@
Alice can initialize a *private* repo using the `--private` flag.

```
-
$ rad init --name heartwood --description "radicle heartwood protocol & stack" --no-confirm --private
+
$ rad init --name heartwood --description "radicle heartwood protocol & stack" --no-confirm --private --announce

Initializing private radicle 👾 repository in [..]

modified crates/radicle-cli/examples/rad-init-sync-not-connected.md
@@ -1,7 +1,7 @@
When initializing a repository without any peer connections, we get this output:

```
-
$ rad init --name heartwood --description "Radicle Heartwood Protocol & Stack" --no-confirm --public --scope followed
+
$ rad init --name heartwood --description "Radicle Heartwood Protocol & Stack" --no-confirm --public --scope followed --announce

Initializing public radicle 👾 repository in [..]

modified crates/radicle-cli/examples/rad-init-sync-preferred.md
@@ -1,7 +1,7 @@
Let's try initializing a new repository with a preferred seed configured.

```
-
$ rad init --name heartwood --description "Radicle Heartwood Protocol & Stack" --no-confirm --public --scope followed
+
$ rad init --name heartwood --description "Radicle Heartwood Protocol & Stack" --no-confirm --public --scope followed --announce

Initializing public radicle 👾 repository in [..]

modified crates/radicle-cli/examples/rad-init-sync-timeout.md
@@ -2,7 +2,7 @@ Sometimes, `init` will fail to sync with the network. This is not a big deal,
as the node will keep attempting to sync in the background.

```
-
$ rad init --name heartwood --description "Radicle Heartwood Protocol & Stack" --no-confirm --public --scope followed
+
$ rad init --name heartwood --description "Radicle Heartwood Protocol & Stack" --no-confirm --public --scope followed --announce

Initializing public radicle 👾 repository in [..]

modified crates/radicle-cli/examples/rad-init-sync.md
@@ -3,7 +3,7 @@ To create your first radicle repository, navigate to a git repository, and run
the `init` command:

```
-
$ rad init --name heartwood --description "Radicle Heartwood Protocol & Stack" --no-confirm --public --scope followed
+
$ rad init --name heartwood --description "Radicle Heartwood Protocol & Stack" --no-confirm --public --scope followed --announce

Initializing public radicle 👾 repository in [..]

modified crates/radicle-cli/examples/rad-init-with-existing-remote.md
@@ -20,7 +20,7 @@ $ git branch -vv
Then we initialize.

```
-
$ rad init --name heartwood --description "Heartwood Protocol & Stack" --no-confirm --public
+
$ rad init --name heartwood --description "Heartwood Protocol & Stack" --no-confirm --public --announce

Initializing public radicle 👾 repository in [..]

@@ -36,7 +36,7 @@ To push changes, run `git push rad master`.

Finally we run the suggested command.

-
``` (stderr)
+
```(stderr)
$ git push rad master
Everything up-to-date
```
modified crates/radicle-cli/examples/rad-init.md
@@ -3,7 +3,7 @@ To create your first radicle repository, navigate to a git repository, and run t
`init` command.  Make sure you have [authenticated](../rad-auth.md) beforehand.

```
-
$ rad init --name heartwood --description "Radicle Heartwood Protocol & Stack" --no-confirm --public -v
+
$ rad init --name heartwood --description "Radicle Heartwood Protocol & Stack" --no-confirm --public --announce -v

Initializing public radicle 👾 repository in [..]

modified crates/radicle-cli/examples/rad-patch-pull-update.md
@@ -3,7 +3,7 @@ Let's look at how patch updates work.
Alice creates a repository and Bob clones it.

``` ~alice
-
$ rad init --name heartwood --description "radicle heartwood protocol & stack" --no-confirm --public
+
$ rad init --name heartwood --description "radicle heartwood protocol & stack" --no-confirm --public --announce

Initializing public radicle 👾 repository in [..]

modified crates/radicle-cli/src/commands/init.rs
@@ -59,6 +59,7 @@ pub fn init(repo: git::Repository, args: Args, profile: &profile::Profile) -> an
    let interactive = args.interactive();
    let visibility = args.visibility();
    let seed = args.seed();
+
    let should_announce = args.announce();

    let default_branch = match find_default_branch(&repo) {
        Err(err @ DefaultBranchError::Head) => {
@@ -133,6 +134,15 @@ pub fn init(repo: git::Repository, args: Args, profile: &profile::Profile) -> an
        Visibility::from_str(selected)?
    };

+
    let should_announce = match should_announce {
+
        Some(announce) => announce,
+
        None if interactive.yes() => match visibility {
+
            Visibility::Public => term::ask("Announce to the public network now", false),
+
            Visibility::Private { .. } => false,
+
        },
+
        None => false,
+
    };
+

    let signer = term::signer(profile)?;
    let mut node = radicle::Node::new(profile.socket());
    let mut spinner = term::spinner("Initializing...");
@@ -143,7 +153,7 @@ pub fn init(repo: git::Repository, args: Args, profile: &profile::Profile) -> an
        name,
        &description,
        branch.clone(),
-
        visibility,
+
        visibility.clone(),
        &signer,
        &profile.storage,
    ) {
@@ -204,12 +214,17 @@ pub fn init(repo: git::Repository, args: Args, profile: &profile::Profile) -> an
            term::blank();

            // Announce inventory to network.
-
            if let Err(e) = announce(rid, doc, &mut node, &profile.config) {
-
                term::blank();
-
                term::warning(format!(
-
                    "There was an error announcing your repository to the network: {e}"
-
                ));
-
                term::warning("Try again with `rad sync --announce`, or check your logs with `rad node logs`.");
+
            if visibility.is_private() || (visibility.is_public() && should_announce) {
+
                if let Err(e) = announce(rid, doc, &mut node, &profile.config) {
+
                    term::blank();
+
                    term::warning(format!(
+
                        "There was an error announcing your repository to the network: {e}"
+
                    ));
+
                    term::warning("Try again with `rad sync --announce`, or check your logs with `rad node logs`.");
+
                    term::blank();
+
                }
+
            } else {
+
                term::info!("Your repository has not been announced to the network, run `rad sync --announce` when you're ready.");
                term::blank();
            }
            term::info!("To push changes, run {}.", term::format::command(push_cmd));
modified crates/radicle-cli/src/commands/init/args.rs
@@ -55,6 +55,12 @@ pub struct Args {
    /// Don't seed this repository after initializing it
    #[arg(long)]
    no_seed: bool,
+
    /// Announce changes made to the network
+
    #[arg(long, global = true, conflicts_with = "no_announce")]
+
    announce: bool,
+
    /// Do not announce changes made to the network
+
    #[arg(long, global = true, conflicts_with = "announce")]
+
    no_announce: bool,
    /// Verbose mode
    #[arg(short, long)]
    pub(super) verbose: bool,
@@ -83,6 +89,15 @@ impl Args {
    pub(super) fn seed(&self) -> bool {
        !self.no_seed
    }
+

+
    pub(super) fn announce(&self) -> Option<bool> {
+
        match (self.announce, self.no_announce) {
+
            (false, false) => None,
+
            (false, true) => Some(false),
+
            (true, false) => Some(true),
+
            (true, true) => Some(false),
+
        }
+
    }
}

// TODO(finto): this is duplicated from `clone::args`. Consolidate these once
modified crates/radicle-cli/tests/commands.rs
@@ -228,6 +228,11 @@ fn rad_init() {
}

#[test]
+
fn rad_init_no_announce() {
+
    Environment::alice(["rad-init-no-announce"]);
+
}
+

+
#[test]
fn rad_init_bare() {
    let mut env = Environment::new();
    let alice = env.profile("alice");