use anyhow::Result;
use std::fs;
use std::path::Path;
fn copy_dir_all(src: &Path, dst: &Path) -> Result<()> {
fs::create_dir_all(dst)?;
for entry in fs::read_dir(src)? {
let entry = entry?;
let ty = entry.file_type()?;
if ty.is_dir() {
copy_dir_all(&entry.path(), &dst.join(entry.file_name()))?;
} else {
fs::copy(entry.path(), dst.join(entry.file_name()))?;
}
}
Ok(())
}
pub fn convert_bare_to_git_dir(bare_path: &Path, git_dir: &Path) -> Result<()> {
if fs::rename(bare_path, git_dir).is_err() {
copy_dir_all(bare_path, git_dir)?;
fs::remove_dir_all(bare_path)?;
}
let config_path = git_dir.join("config");
if config_path.exists() {
let content = fs::read_to_string(&config_path)?;
let updated = content.replace("bare = true", "bare = false");
fs::write(&config_path, updated)?;
}
Ok(())
}