diff options
| author | Teddy Wing | 2021-05-29 17:21:57 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2021-05-29 17:21:57 +0200 | 
| commit | 8c233d6d29e15c260a2ffa46b747d870cebc80e6 (patch) | |
| tree | f7816c13a2895567e6df0ed0fd3e13b3ec6a1159 /src | |
| parent | 33a08a9159379588871442672f7c7362ba352501 (diff) | |
| download | reflectub-8c233d6d29e15c260a2ffa46b747d870cebc80e6.tar.bz2 | |
Work out how to mirror a Git repository
Based on the guide here:
https://libgit2.org/docs/guides/101-samples/#repositories_clone_mirror
References:
https://github.com/libgit2/libgit2sharp/issues/577
https://github.com/libgit2/libgit2.github.io/pull/31
Diffstat (limited to 'src')
| -rw-r--r-- | src/git.rs | 32 | ||||
| -rw-r--r-- | src/lib.rs | 1 | ||||
| -rw-r--r-- | src/main.rs | 8 | 
3 files changed, 38 insertions, 3 deletions
| diff --git a/src/git.rs b/src/git.rs new file mode 100644 index 0000000..d58da3c --- /dev/null +++ b/src/git.rs @@ -0,0 +1,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(()) +} @@ -1,2 +1,3 @@ +pub mod git;  pub mod github;  pub mod repo; diff --git a/src/main.rs b/src/main.rs index ea540e6..994c86f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,10 @@ -use reflectub::github; +use reflectub::{git, github};  fn main() { -    let repos = github::fetch_repos().unwrap(); +    // let repos = github::fetch_repos().unwrap(); +    // +    // dbg!(&repos); -    dbg!(&repos); +    git::mirror().unwrap();  } | 
