libgit2 / libgit2/libgit2sharp
Unable to iterate commits on all branches for a specific path (KeyNotFoundException)
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 3.5k
- Forks
- 925
- PR merge metrics
- No merged PRs in 30d
Description
When you attempt to use repository.QueryBy(string, CommitFilter) and specify all branches as the IncludeReachableFrom parameter, a KeyNotFound exception is thrown.
Reproduction steps
Add the following test to FileHistoryFixture to reproduce the issue
[Fact]
public void CanListChangesThatIncludeMultipleBranches()
{
var repoPath = CreateEmptyRepository();
const string path1 = "Test1.txt";
const string path2 = "Test2.txt";
using (var repo = new Repository(repoPath))
{
// Make initial changes.
var initial = MakeAndCommitChange(repo, repoPath, path1, "Hello World", "initial commit");
MakeAndCommitChange(repo, repoPath, path2, "Goodbye world", "unrelated file change 1");
var update1 = MakeAndCommitChange(repo, repoPath, path1, "Hello World!", "added punctuation");
var branch = repo.CreateBranch("branch");
Commands.Checkout(repo, branch);
var branchUpdate = MakeAndCommitChange(repo, repoPath, path1, "Hello World again", "branch change");
MakeAndCommitChange(repo, repoPath, path2, "Goodbye cruel world", "unrelated file change 2");
Commands.Checkout(repo, repo.Branches["master"]);
var update2 = MakeAndCommitChange(repo, repoPath, path1, "Hola Mundo", "switching to spanish");
var commits = repo.Commits
.QueryBy(path1, new CommitFilter { IncludeReachableFrom = repo.Branches, SortBy = CommitSortStrategies.Topological})
.ToList();
Assert.Equal(4, commits.Count);
Assert.Equal(branchUpdate.Sha, commits[0].Commit.Sha);
Assert.Equal(update2.Sha, commits[1].Commit.Sha);
Assert.Equal(update1.Sha, commits[2].Commit.Sha);
Assert.Equal(initial.Sha, commits[3].Commit.Sha);
}
}
Version of LibGit2Sharp (release number or SHA1)
f8e2d42ed9051fa5a5348c1a13d006f0cc069bc7
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Add the supplied regression test to FileHistoryFixture and run it against repository.Commits.QueryBy with the multi-branch CommitFilter. Trace the QueryBy path that handles IncludeReachableFrom and compare its behavior with the expected four commits. Done means the test no longer throws KeyNotFoundException and returns the four commits in the asserted order.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, git
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100