cli: Fix `rad rm` command

This commit is contained in:
Alexis Sellier 2023-02-09 17:09:40 +01:00
parent a57b33c785
commit b2dbf12862
No known key found for this signature in database
3 changed files with 43 additions and 4 deletions

View File

@ -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
```

View File

@ -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)

View File

@ -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);