rust-lang / rust-lang/git2-rs

When cloning with `RepoBuilder`, specifying branch makes repository bare

Open
#824 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

I found a strange behavior in 0.13, not in the latest version 0.14. Since I couldn't find the CHANGELOG, I was not sure that the following bug was fixed intentionally, so I'm submitting an issue.


Here is a code that clones a remote repository on https using RepoBuilder.

use std::path::PathBuf;

use git2::{build::RepoBuilder};

fn main() {
    let mut builder = RepoBuilder::new();
    builder.branch("my-branch");   // <- this line
    let res = builder.clone("https://github.com/username/repo-name.git", &PathBuf::from("/tmp/x"));
    println!("{:?}", res.is_ok());
}

Without specifying builder (without "this line"), the repository is cloned normally (/tmp/x/ contains .git and the contents of the main branch). However, if the branch is specified (with "this line"), the behavior is as if git clone --bare was run: /tmp/x/ contains:

FETCH_HEAD   HEAD         config       description  hooks/       info/        objects/     refs/

Why specifying the branch makes repository bare? Is it a bug?

It seems I have libgit2 1.4.2 installed on the system. This behavior was confirmed only in 0.13.25; for 0.14.2, it didn't happen.

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 by reproducing the provided RepoBuilder::branch and clone example with git2-rs 0.13.25, then compare its behavior with 0.14.2 and the installed libgit2 1.4.2. Inspect the RepoBuilder branch and clone entry points; done means determining whether the bare repository result is an unintended version-specific bug or an intentional change.

Written by the indexing model from the issue text.

Assessment

Tech stack
git, rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.