diff --git a/radicle-cli/examples/rad-rm.md b/radicle-cli/examples/rad-rm.md new file mode 100644 index 00000000..435bbbd5 --- /dev/null +++ b/radicle-cli/examples/rad-rm.md @@ -0,0 +1,22 @@ +To delete a repository from local storage, we use the `rad rm` command. +First let's look at what we have locally: + +``` +$ rad ls +heartwood rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji f2de534 Radicle Heartwood Protocol & Stack +``` + +Now let's delete the `heartwood` project: + +``` +$ rad rm rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji --no-confirm +** Warning: Failed to untrack repository: failed to connect to node: No such file or directory (os error 2) +** Warning: Make sure to untrack this repository when your node is running +ok Successfully removed project rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji from storage +``` + +We can check our repositories again to see if it was deleted: + +``` +$ rad ls +``` diff --git a/radicle-cli/src/commands/rm.rs b/radicle-cli/src/commands/rm.rs index 7d696767..076dfb9f 100644 --- a/radicle-cli/src/commands/rm.rs +++ b/radicle-cli/src/commands/rm.rs @@ -81,7 +81,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> { let id = options.id; if let Ok(Some(_)) = storage.get(signer.public_key(), id.to_owned()) { - let namespace = profile.home.storage().join(id.urn()); + let path = radicle::storage::git::paths::repository(storage, &id); if !options.confirm || term::confirm(format!( @@ -89,9 +89,12 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> { term::format::dim(id.urn()) )) { - rad_untrack::untrack(id.to_owned(), &profile)?; - fs::remove_dir_all(namespace)?; - term::success!("Successfully removed project {}", &id); + if let Err(e) = rad_untrack::untrack(id.to_owned(), &profile) { + term::warning(&format!("Failed to untrack repository: {e}")); + term::warning("Make sure to untrack this repository when your node is running"); + } + fs::remove_dir_all(path)?; + term::success!("Successfully removed project {id} from storage"); } } else { anyhow::bail!("project {} does not exist", &id) diff --git a/radicle-cli/tests/commands.rs b/radicle-cli/tests/commands.rs index c15995c2..74a83b05 100644 --- a/radicle-cli/tests/commands.rs +++ b/radicle-cli/tests/commands.rs @@ -154,6 +154,20 @@ fn rad_patch() { test("examples/rad-patch.md", working.path(), Some(home), []).unwrap(); } +#[test] +fn rad_rm() { + let mut environment = Environment::new(); + let profile = environment.profile("alice"); + let working = tempfile::tempdir().unwrap(); + let home = &profile.home; + + // Setup a test repository. + fixtures::repository(working.path()); + + test("examples/rad-init.md", working.path(), Some(home), []).unwrap(); + test("examples/rad-rm.md", working.path(), Some(home), []).unwrap(); +} + #[test] fn rad_clone() { logger::init(log::Level::Debug);