blob: 423a01fefb282bb221f0cadcf7a49a4a6e67075f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
use std::path::Path;
pub fn mirror<P: AsRef<Path>>(
url: &str,
path: P,
) -> Result<(), Box<dyn std::error::Error>> {
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(())
}
|