Skip to content

Commit 08c204a

Browse files
Fixed issue #1362: enumerating the notes collection for a repository that has no notes throws an exception.
1 parent f12a329 commit 08c204a

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

LibGit2Sharp.Tests/NoteFixture.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,21 @@ public void CanRetrieveTheListOfNotesForAGivenNamespace()
308308
}
309309
}
310310

311+
[Fact]
312+
public void CanRetrieveNotesWhenThereAreNotAny()
313+
{
314+
string path = InitNewRepository(); // doesn't reproduce an error when using a sandbox repository so we have to create an actual repo.
315+
using (var repo = new Repository(path))
316+
{
317+
foreach (var note in repo.Notes)
318+
{
319+
Assert.NotNull(note);
320+
}
321+
Assert.Equal(0, repo.Notes.Count());
322+
}
323+
}
324+
325+
311326
private static T[] SortedNotes<T>(IEnumerable<Note> notes, Func<Note, T> selector)
312327
{
313328
return notes.OrderBy(n => n.Message, StringComparer.Ordinal).Select(selector).ToArray();

LibGit2Sharp/Core/Proxy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1392,7 +1392,7 @@ public static unsafe ICollection<TResult> git_note_foreach<TResult>(RepositoryHa
13921392
return git_foreach(resultSelector, c => NativeMethods.git_note_foreach(repo,
13931393
notes_ref,
13941394
(ref GitOid x, ref GitOid y, IntPtr p) => c(x, y, p),
1395-
IntPtr.Zero));
1395+
IntPtr.Zero), GitErrorCode.NotFound);
13961396
}
13971397

13981398
public static unsafe string git_note_message(NoteHandle note)

0 commit comments

Comments
 (0)