rust-lang / git2-rs

libgit2 bindings for Rust
https://docs.rs/git2
Apache License 2.0
1.72k stars 390 forks source link

`git clone --mirror` #521

Open samuela opened 4 years ago

samuela commented 4 years ago

Is there a way to do the equivalent of git clone --mirror <url> with git2-rs? It seems like bare cloning (https://docs.rs/git2/0.11.0/git2/build/struct.RepoBuilder.html#method.bare) is supported but I'm not able to find anything for mirroring.

afranchuk commented 4 years ago

I believe you can make a read-only equivalent of mirror with:

git2::build::RepoBuilder::new()
    .bare(true)
    .remote_create(|repo,name,url| repo.remote_with_fetch(name, url, "+refs/*:refs/*"))

The only difference is that pushes won't use the default mirror semantics (hence why I said read-only). But you may be able to use Repository::remote_add_push to make that work, too?

samuela commented 4 years ago

Thanks @afranchuk !