libgit2 / libgit2/rugged

Rugged::Repository.merge_base complains when the merge base is a graft

Open
#846 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
2.3k
Forks
293
PR merge metrics
No merged PRs in 30d

Description

Hello, I have some CI jobs that try to avoid checking out unnecessary commits for merges. They call the GitHub API to see how many commits behind/ahead they are, compared to the base branch, and then fetch the base/merge branch with depth equal to number of commits they are behind/ahead + 1.

When one of the test tools calls Rugged::Repository.merge_base, if the merge base commit is a graft commit (from the shallow fetch), I get an error like:

Traceback (most recent call last):
	1: from show_merge_base.rb:9:in `<main>'
show_merge_base.rb:9:in `merge_base': object not found - no match for id (fab6d6845fe971f1bb15b793c5604ce7aeb0eaa2) (Rugged::OdbError)

where fab6d6845fe971f1bb15b793c5604ce7aeb0eaa2 is the parent of the grafted commit.

I see that git handles it fine :

$ git merge-base HEAD master
6e85c6c9868ba19e1b8c2f41890f02d37d9c8634

Increasing the shallow depth by one prevents the error, but I feel like merge_base shouldn't be looking for commits that aren't needed to calculate the merge base.

I created a repo to make it easier to reproduce the error, and included exact steps: https://github.com/dgholz/libgit2_merge_base

Contributor guide

No contributing guide indexed for this repository

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 linked libgit2_merge_base reproduction and the Rugged::Repository.merge_base entry point; reproduce the failure using the shallow fetch and graft merge base described here. Compare its result with git merge-base and verify that the object-not-found error no longer occurs without increasing the shallow depth.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, git, ruby
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.