use std::env::current_dir;
use anyhow::Result;
use thiserror::Error;
use crate::{containing_table_info, XATTR_HEAD};
use super::{restore::reset_path, NewFileHandling};
#[derive(Error, Debug)]
pub enum ResetErr {
#[error("Current directory not contained by a table")]
NotInTable,
}
pub fn reset(commit_uuid: &str, verbose: bool, new_file_handling: NewFileHandling) -> Result<()> {
let cur = current_dir()?;
let info = containing_table_info(&cur)?.ok_or(ResetErr::NotInTable)?;
let table_path = info.path_abs();
reset_path(table_path, commit_uuid, true, verbose, new_file_handling)?;
xattr::set(table_path, XATTR_HEAD.to_osstring(), commit_uuid.as_bytes())?;
Ok(())
}