cli: Improve `rad init` error when not in Git repo
This commit is contained in:
parent
a84555955d
commit
46b0dfb11c
|
|
@ -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
|
||||
```
|
||||
|
|
@ -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}");
|
||||
|
|
|
|||
|
|
@ -127,6 +127,21 @@ fn rad_init() {
|
|||
.unwrap();
|
||||
}
|
||||
|
||||
#[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();
|
||||
|
|
|
|||
Loading…
Reference in New Issue