Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli: Improve `rad init` error when not in Git repo
cloudhead committed 2 years ago
commit 46b0dfb11c197053e5557ed19dbe06044951bad9
parent a84555955d800c0859f242b31d37b354722fa57a
3 files changed +29 -1
added radicle-cli/examples/rad-init-no-git.md
@@ -0,0 +1,7 @@
+
If you try to `init` from a directory that doesn't contain a Git repository,
+
it will fail:
+

+
``` (fail)
+
$ rad init
+
✗ Initialization failed: a Git repository was not found at the current path
+
```
modified radicle-cli/src/commands/init.rs
@@ -180,6 +180,13 @@ pub fn init(options: Options, profile: &profile::Profile) -> anyhow::Result<()>
    let path = options.path.unwrap_or_else(|| cwd.clone());
    let path = path.as_path().canonicalize()?;
    let interactive = options.interactive;
+
    let repo = match git::Repository::open(&path) {
+
        Ok(r) => r,
+
        Err(e) if radicle::git::ext::is_not_found_err(&e) => {
+
            anyhow::bail!("a Git repository was not found at the current path")
+
        }
+
        Err(e) => return Err(e.into()),
+
    };

    term::headline(format!(
        "Initializing{}radicle 👾 project in {}",
@@ -195,7 +202,6 @@ pub fn init(options: Options, profile: &profile::Profile) -> anyhow::Result<()>
        }
    ));

-
    let repo = git::Repository::open(&path)?;
    if let Ok((remote, _)) = git::rad_remote(&repo) {
        if let Some(remote) = remote.url() {
            bail!("repository is already initialized with remote {remote}");
modified radicle-cli/tests/commands.rs
@@ -128,6 +128,21 @@ fn rad_init() {
}

#[test]
+
fn rad_init_no_git() {
+
    let mut environment = Environment::new();
+
    let profile = environment.profile("alice");
+
    let working = tempfile::tempdir().unwrap();
+

+
    test(
+
        "examples/rad-init-no-git.md",
+
        working.path(),
+
        Some(&profile.home),
+
        [],
+
    )
+
    .unwrap();
+
}
+

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