rust-lang / rust-lang/git2-rs

git2rs equivalent to "git push --mirror remote"

Open
#1,105 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
2.1k
Forks
450
Avg merge
11m
Merged PRs (30d)
1

Description

Hi, I am making a tool to mirror my repo from one git hosting platform to github. What I want to do is using git2rs to achieve:

  1. git clone --bare https://platfrom.repo.git
  2. cd to the cloned repo
  3. git push --mirror https://github.repo.git

Step 1 and 2 are successful, but I am not able to implement step 3. Can anyone tell me what is the git2rs equivalent to step 3?

I tried the following appoach:

  • query all refs of local repo and push to remote, the issue is that the deleted tags/branches are not pushed
  • do not specify refs, set the config for remote as mirror, nothing is pushed after the program runs
pub fn push_mirror(repo_path: &PathBuf, remote_url: &str) -> Result<(), git2::Error> {
    let repo = Repository::open(repo_path)?;

    if repo.find_remote("mirror").is_ok() {
        repo.remote_delete("mirror")?;
    }

    let mut remote = repo.remote_with_fetch("mirror", remote_url, "+refs/*:refs/*")?;

    let mut config = repo.config()?;
    config.set_bool("remote.mirror.mirror", true)?;

    let mut push_opts = PushOptions::new();
    remote.push(&[] as &[&str], Some(&mut push_opts))?;

    Ok(())
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the push_mirror function shown in the issue and inspect how git2::Remote::push handles an empty refspec and the remote.mirror configuration. Reproduce the operation with a bare local repository and remote, including deleted refs; done means the remote matches the local mirror, including deletions.

Written by the indexing model from the issue text.

Assessment

Tech stack
git, rust
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.