cli: Fix `rad rm` command
This commit is contained in:
parent
a57b33c785
commit
b2dbf12862
|
|
@ -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
|
||||||
|
```
|
||||||
|
|
@ -81,7 +81,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
let id = options.id;
|
let id = options.id;
|
||||||
|
|
||||||
if let Ok(Some(_)) = storage.get(signer.public_key(), id.to_owned()) {
|
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
|
if !options.confirm
|
||||||
|| term::confirm(format!(
|
|| term::confirm(format!(
|
||||||
|
|
@ -89,9 +89,12 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
term::format::dim(id.urn())
|
term::format::dim(id.urn())
|
||||||
))
|
))
|
||||||
{
|
{
|
||||||
rad_untrack::untrack(id.to_owned(), &profile)?;
|
if let Err(e) = rad_untrack::untrack(id.to_owned(), &profile) {
|
||||||
fs::remove_dir_all(namespace)?;
|
term::warning(&format!("Failed to untrack repository: {e}"));
|
||||||
term::success!("Successfully removed project {}", &id);
|
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 {
|
} else {
|
||||||
anyhow::bail!("project {} does not exist", &id)
|
anyhow::bail!("project {} does not exist", &id)
|
||||||
|
|
|
||||||
|
|
@ -154,6 +154,20 @@ fn rad_patch() {
|
||||||
test("examples/rad-patch.md", working.path(), Some(home), []).unwrap();
|
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]
|
#[test]
|
||||||
fn rad_clone() {
|
fn rad_clone() {
|
||||||
logger::init(log::Level::Debug);
|
logger::init(log::Level::Debug);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue