workon/
convert_to_bare.rs1use std::fs::{rename, write};
2
3use git2::Repository;
4use log::debug;
5
6use crate::error::Result;
7use crate::workon_root;
8
9pub fn convert_to_bare(mut repo: Repository) -> Result<Repository> {
19 debug!("Converting to bare repository");
20 let mut config = repo.config()?;
22 config.set_bool("core.bare", true)?;
23 let root = workon_root(&repo)?;
24 rename(repo.path(), root.join(".bare"))?;
26 write(root.join(".git"), "gitdir: ./.bare")?;
28
29 repo = Repository::open(root.join(".bare"))?;
30 repo.remote_add_fetch("origin", "+refs/heads/*:refs/remotes/origin/*")?;
31
32 Ok(repo)
33}