rust-lang / rust-lang/git2-rs

Fetch receiving 0 bytes

Open
#1,183 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'm attempting to implement pull from a remote repo, based on the fetch and pull code examples in the repo. The relevant chunk of code is as follows:

        match Repository::open(&repo_path_string) {
            Ok(repo) => {
                let remote_name = "origin";
                let remote_branch = "master";
                let mut remote = repo
                    .find_remote(remote_name)
                    .expect("could not find remote");
                let mut fo = git2::FetchOptions::new();
                fo.download_tags(git2::AutotagOption::All);
                match remote.fetch(&[remote_branch], Some(&mut fo), None) {
                    Ok(_) => {
                        let stats = remote.stats();
                        if stats.local_objects() > 0 {
                            println!(
                                "\rReceived {}/{} objects in {} bytes (used {} local \
             objects)",
                                stats.indexed_objects(),
                                stats.total_objects(),
                                stats.received_bytes(),
                                stats.local_objects()
                            );
                        } else {
                            println!(
                                "\rReceived {}/{} objects in {} bytes",
                                stats.indexed_objects(),
                                stats.total_objects(),
                                stats.received_bytes()
                            );
                        }
                    }
                    Err(e) => {
                        return not_ok_json_response(
                            Status::InternalServerError,
                            make_bad_json_data_response(
                                format!("could not fetch repo: {}", e).to_string(),
                            ),
                        )
                    }
                };
...

This code compiles and runs but the remote commits do not appear in the local repo (master or remotes/origin/master - there's a subsequent fast-forward merge which succeeds but is presumably chewing on nothing).

On the console I see

Received 4/4 objects in 0 bytes (used 2 local objects)

The 0 bytes seems suspicious. git pull retrieves the commits as expected.

What am I missing?

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 comparing the shown remote.fetch call with the repository's fetch and pull code examples, then inspect the reported remote.stats values and whether the remote-tracking reference changes. Done means the fetched remote commits appear in the local repository and the subsequent fast-forward uses them rather than an empty result.

Written by the indexing model from the issue text.

Assessment

Tech stack
git, rust
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.