project deleteion cleans up virtual_branches.toml

This commit is contained in:
Kiril Videlov 2024-04-24 17:38:07 +02:00 committed by Kiril Videlov
parent 65f2dc1fa5
commit bb48dff72a
2 changed files with 19 additions and 4 deletions

View File

@ -261,10 +261,9 @@ impl Controller {
tracing::error!(project_id = %project.id, ?error, "failed to remove .git/gitbutler.json data",);
}
let virtual_branches_path = project.path.join(".git/virtual_branches.toml");
if virtual_branches_path.exists() {
if let Err(error) = std::fs::remove_file(virtual_branches_path) {
tracing::error!(project_id = %project.id, ?error, "failed to remove .git/virtual_branches.toml data",);
if project.gb_dir().exists() {
if let Err(error) = std::fs::remove_dir_all(project.gb_dir()) {
tracing::error!(project_id = %project.id, ?error, "failed to remove {:?} on project delete", project.gb_dir());
}
}

View File

@ -114,3 +114,19 @@ mod add {
}
}
}
mod delete {
use super::*;
#[tokio::test]
async fn success() {
let (controller, _tmp) = new();
let repository = gitbutler_testsupport::TestProject::default();
let path = repository.path();
let project = controller.add(path).unwrap();
assert!(controller.delete(&project.id).await.is_ok());
assert!(controller.delete(&project.id).await.is_ok()); // idempotent
assert!(controller.get(&project.id).is_err());
assert!(!project.gb_dir().exists());
assert!(!project.path.join(".gitbutler.json").exists());
}
}