use std::{env, ffi::OsStr, fs, fs::File, io, io::Write, path::Path};
use crate::ok;
pub fn init_repo() -> io::Result<()> {
if Path::new(".rvcs").exists() {
fs::remove_dir_all(".rvcs")?;
}
fs::create_dir_all(".rvcs/objects")?;
fs::create_dir_all(".rvcs/commits/master")?;
File::create(".rvcs/commits/master/HEAD")?;
let mut fb = File::create(".rvcs/CURRENT_BRANCH")?;
fb.write_all(b"master")?;
let current = env::current_dir()?;
println!(
"{} Sucessfully initialized repository in `{}`.",
ok(),
format!(
"{}/.rvcs",
current
.file_name()
.unwrap_or(OsStr::new(""))
.to_str()
.unwrap()
)
);
Ok(())
}