use anyhow::{bail, Result};
use std::path::Path;
pub fn execute(path: &Path, files: &[String], cached: bool) -> Result<()> {
let repo = crate::ops::open_repo(path)?;
let mut index = repo.index()?;
for file in files {
if index.get_path(Path::new(file), 0).is_none() {
bail!("pathspec '{}' did not match any files known to git", file);
}
index.remove_path(Path::new(file))?;
if !cached {
let full = path.join(file);
if full.exists() {
if full.is_dir() {
std::fs::remove_dir_all(&full)?;
} else {
std::fs::remove_file(&full)?;
}
}
}
println!("rm '{}'", file);
}
index.write()?;
Ok(())
}