Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/NerdBank.GitVersioning/ManagedGit/GitRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,8 @@ private bool TryGetObjectByPath(GitObjectId sha, string objectType, [NotNullWhen

if (string.CompareOrdinal(objectStream.ObjectType, objectType) != 0)
{
throw new GitException($"Got a {objectStream.ObjectType} instead of a {objectType} when opening object {sha}");
value = null;
return false;
}

value = objectStream;
Expand Down
15 changes: 15 additions & 0 deletions test/Nerdbank.GitVersioning.Tests/ManagedGit/GitRepositoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,21 @@ public void GetObjectByShaAndWrongTypeTest()
}
}

[Fact]
public void TryGetObjectByShaAndWrongTypeTest()
{
this.InitializeSourceControl();
this.AddCommits(2);

var headObjectId = GitObjectId.Parse(this.LibGit2Repository.Head.Tip.Sha);

using (var repository = GitRepository.Create(this.RepoPath))
{
Assert.False(repository.TryGetObjectBySha(headObjectId, "tree", out Stream value));
Assert.Null(value);
}
}

[Fact]
public void GetMissingObjectByShaTest()
{
Expand Down
24 changes: 22 additions & 2 deletions test/Nerdbank.GitVersioning.Tests/VersionOracleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@ public void Tags()
// Assert that we don't see any tags.
Assert.Empty(oracle.Tags);

// Create a tag.
// Create a lightweight tag.
this.LibGit2Repository.ApplyTag("mytag");

// Refresh our context before asking again.
Expand All @@ -1057,6 +1057,16 @@ public void Tags()

// Assert that we see the tag.
Assert.Equal("refs/tags/mytag", Assert.Single(oracle2.Tags));

// Add another commit
this.AddCommits(1);

// Refresh our context before asking again.
this.Context = this.CreateGitContext(this.RepoPath);
VersionOracle oracle3 = new(this.Context);

// Assert that HEAD is not pointing to the tag.
Assert.Empty(oracle3.Tags);
}

[Fact]
Expand All @@ -1070,7 +1080,7 @@ public void Tags_Annotated()
// Assert that we don't see any tags.
Assert.Empty(oracle.Tags);

// Create a tag.
// Create an annotated tag.
this.LibGit2Repository.ApplyTag("mytag", this.Signer, "my tag");

// Refresh our context before asking again.
Expand All @@ -1079,6 +1089,16 @@ public void Tags_Annotated()

// Assert that we see the tag.
Assert.Equal("refs/tags/mytag", Assert.Single(oracle2.Tags));

// Add another commit
this.AddCommits(1);

// Refresh our context before asking again.
this.Context = this.CreateGitContext(this.RepoPath);
VersionOracle oracle3 = new(this.Context);

// Assert that HEAD is not pointing to the tag.
Assert.Empty(oracle3.Tags);
}

[Fact]
Expand Down