libgit2sharp
libgit2sharp copied to clipboard
Unable to iterate commits on all branches for a specific path (KeyNotFoundException)
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
Must have been fixed at some point because it works fine for me...