Skip to content

Commit 277ae16

Browse files
committed
Protect TagAnnotation creation from invalid parameters
1 parent 28d1820 commit 277ae16

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

LibGit2Sharp.Tests/ObjectDatabaseFixture.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,5 +450,36 @@ public void CreatingATagAnnotationWithNameOrMessageContainingZeroByteThrows(stri
450450
"name", repo.Head.Tip, Constants.Signature, input));
451451
}
452452
}
453+
454+
[Fact]
455+
public void CreatingATagAnnotationWithBadParametersThrows()
456+
{
457+
using (var repo = new Repository(BareTestRepoPath))
458+
{
459+
Assert.Throws<ArgumentNullException>(() => repo.ObjectDatabase.CreateTagAnnotation(
460+
null, repo.Head.Tip, Constants.Signature, "message"));
461+
Assert.Throws<ArgumentException>(() => repo.ObjectDatabase.CreateTagAnnotation(
462+
string.Empty, repo.Head.Tip, Constants.Signature, "message"));
463+
Assert.Throws<ArgumentNullException>(() => repo.ObjectDatabase.CreateTagAnnotation(
464+
"name", null, Constants.Signature, "message"));
465+
Assert.Throws<ArgumentNullException>(() => repo.ObjectDatabase.CreateTagAnnotation(
466+
"name", repo.Head.Tip, null, "message"));
467+
Assert.Throws<ArgumentNullException>(() => repo.ObjectDatabase.CreateTagAnnotation(
468+
"name", repo.Head.Tip, Constants.Signature, null));
469+
}
470+
}
471+
472+
[Fact]
473+
public void CanCreateATagAnnotationWithAnEmptyMessage()
474+
{
475+
string path = CloneBareTestRepo();
476+
using (var repo = new Repository(path))
477+
{
478+
var tagAnnotation = repo.ObjectDatabase.CreateTagAnnotation(
479+
"name", repo.Head.Tip, Constants.Signature, string.Empty);
480+
481+
Assert.Equal(string.Empty, tagAnnotation.Message);
482+
}
483+
}
453484
}
454485
}

LibGit2Sharp/ObjectDatabase.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ internal Commit CreateCommit(string message, Signature author, Signature committ
222222
/// <returns>The created <see cref="TagAnnotation"/>.</returns>
223223
public virtual TagAnnotation CreateTagAnnotation(string name, GitObject target, Signature tagger, string message)
224224
{
225+
Ensure.ArgumentNotNullOrEmptyString(name, "name");
226+
Ensure.ArgumentNotNull(message, "message");
227+
Ensure.ArgumentNotNull(target, "target");
228+
Ensure.ArgumentNotNull(tagger, "tagger");
225229
Ensure.ArgumentDoesNotContainZeroByte(name, "name");
226230
Ensure.ArgumentDoesNotContainZeroByte(message, "message");
227231

0 commit comments

Comments
 (0)