Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli: Move `init` errors up so it fails sooner
cloudhead committed 2 years ago
commit befc76e0304f1891ce5fe7921acf2c486d5a5054
parent f2e74fdad2f1cfe0d85c642e40ed3a43710f06d6
3 files changed +35 -18
modified radicle-cli/examples/rad-init-no-git.md
@@ -5,3 +5,18 @@ it will fail:
$ rad init
✗ Error: a Git repository was not found at the current path
```
+

+
Ok so let's initialize one.
+

+
```
+
$ git init -q
+
```
+

+
Now we try again.
+

+
``` (fail)
+
$ rad init
+
✗ Error: repository head must point to a commit
+
```
+

+
Looks like we need a commit.
modified radicle-cli/examples/rad-init.md
@@ -22,6 +22,13 @@ You can start your node with `rad node start`.
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
+
```
+

Projects can be listed with the `ls` command:

```
modified radicle-cli/src/commands/init.rs
@@ -188,6 +188,18 @@ pub fn init(options: Options, profile: &profile::Profile) -> anyhow::Result<()>
        Err(e) => return Err(e.into()),
    };

+
    if let Ok((remote, _)) = git::rad_remote(&repo) {
+
        if let Some(remote) = remote.url() {
+
            bail!("repository is already initialized with remote {remote}");
+
        }
+
    }
+

+
    let head: String = repo
+
        .head()
+
        .ok()
+
        .and_then(|head| head.shorthand().map(|h| h.to_owned()))
+
        .ok_or_else(|| anyhow!("repository head must point to a commit"))?;
+

    term::headline(format!(
        "Initializing{}radicle 👾 project in {}",
        if let Some(visibility) = &options.visibility {
@@ -206,21 +218,6 @@ pub fn init(options: Options, profile: &profile::Profile) -> anyhow::Result<()>
        }
    ));

-
    // TODO: Move up.
-
    if let Ok((remote, _)) = git::rad_remote(&repo) {
-
        if let Some(remote) = remote.url() {
-
            bail!("repository is already initialized with remote {remote}");
-
        }
-
    }
-

-
    // TODO: Move up.
-
    let signer = term::signer(profile)?;
-
    let head: String = repo
-
        .head()
-
        .ok()
-
        .and_then(|head| head.shorthand().map(|h| h.to_owned()))
-
        .ok_or_else(|| anyhow!("error: repository head must point to a commit"))?;
-

    let name = options.name.unwrap_or_else(|| {
        let default = path.file_name().map(|f| f.to_string_lossy().to_string());
        term::input(
@@ -258,6 +255,7 @@ pub fn init(options: Options, profile: &profile::Profile) -> anyhow::Result<()>
        Visibility::from_str(selected)?
    };

+
    let signer = term::signer(profile)?;
    let mut node = radicle::Node::new(profile.socket());
    let mut spinner = term::spinner("Initializing...");
    let mut push_cmd = String::from("git push");
@@ -333,9 +331,6 @@ pub fn init(options: Options, profile: &profile::Profile) -> anyhow::Result<()>
        Err(err) => {
            spinner.failed();
            anyhow::bail!(err);
-

-
            // TODO: Handle error: "this repository is already initialized with remote {}"
-
            // TODO: Handle error: "the `{}` branch was either not found, or has no commits"
        }
    }