use std::path::Path; /// Mirror a repository. /// /// Works like: /// /// ```shell /// git clone --mirror URL /// ``` pub fn mirror>( url: &str, path: P, ) -> Result<(), Box> { let repo = git2::Repository::init_bare(path)?; let remote_name = "origin"; let mut remote = repo.remote_with_fetch( remote_name, url, "+refs/*:refs/*", )?; let mut config = repo.config()?; config.set_bool( &format!("remote.{}.mirror", remote_name), true, )?; let refspecs: [&str; 0] = []; remote.fetch(&refspecs, None, None)?; Ok(()) } /// Update remotes. /// /// Works like: /// /// ```shell /// git remote update /// ``` pub fn update>( path: P, ) -> Result<(), Box> { let repo = git2::Repository::open_bare(path)?; for remote_opt in &repo.remotes()? { if let Some(remote_name) = remote_opt { let mut remote = repo.find_remote(remote_name)?; let mut fetch_options = git2::FetchOptions::new(); fetch_options .prune(git2::FetchPrune::On) .download_tags(git2::AutotagOption::All); let refspecs: [&str; 0] = []; remote.fetch(&refspecs, Some(&mut fetch_options), None)?; } } Ok(()) }