aboutsummaryrefslogtreecommitdiffstats
path: root/src/git.rs
blob: d58da3c6da87cdb44cf72ca5354cf005723625c6 (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
29
30
31
32
use std::path::Path;


pub fn mirror() -> Result<(), Box<dyn std::error::Error>> {
    // let builder = git2::build::RepoBuilder::new()
    //     .bare(true)
    //     .clone(
    //         "https://github.com/teddywing/google-calendar-rsvp.git",
    //         Path::new("/tmp/grsvp"),
    //     );

    let repo = git2::Repository::init_bare(Path::new("/tmp/grsvp"))?;

    let remote_name = "origin";

    let mut remote = repo.remote_with_fetch(
        remote_name,
        "https://github.com/teddywing/google-calendar-rsvp.git",
        "+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(())
}