Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli: Fix `rad rm` command
Alexis Sellier committed 3 years ago
commit b2dbf12862e4f24dc291b1126598c0769c96a74a
parent a57b33c785878884c1164c55d5963e277a145d69
3 files changed +43 -4
added 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
+
```
modified 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)
modified radicle-cli/tests/commands.rs
@@ -155,6 +155,20 @@ fn rad_patch() {
}

#[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);