use std::path::PathBuf;
use anyhow::{Context, Result};
use gitcortex_store::branch;
use super::serve_lock;
pub fn run() -> Result<()> {
let repo_root = repo_root()?;
let _repository_lock = serve_lock::acquire_mutation(&repo_root)?;
let repo_id = branch::storage_repo_id(&repo_root);
let data_dir = branch::data_dir(&repo_id);
if !branch::has_repo_data(&repo_id)? {
println!("nothing to clean (no graph data at {})", data_dir.display());
return Ok(());
}
branch::wipe_repo_data(&repo_id)
.with_context(|| format!("failed to clean {}", data_dir.display()))?;
println!("cleaned: {}", data_dir.display());
println!("run `gcx init` or make a commit to trigger a fresh full index");
Ok(())
}
fn repo_root() -> Result<PathBuf> {
let output = std::process::Command::new("git")
.args(["rev-parse", "--show-toplevel"])
.output()
.context("git rev-parse failed")?;
Ok(PathBuf::from(
String::from_utf8(output.stdout)?.trim().to_owned(),
))
}