Skip to content

Commit 93d8e45

Browse files
committed
Add test
1 parent 1502b93 commit 93d8e45

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,5 +1256,40 @@ public void UsingPatienceAlgorithmCompareOptionProducesPatienceDiff()
12561256
Assert.Equal(diffPatience, changes);
12571257
}
12581258
}
1259+
1260+
[Fact]
1261+
public void DiffThrowsANotFoundExceptionIfATreeIsMissing()
1262+
{
1263+
string repoPath = SandboxBareTestRepo();
1264+
1265+
// Manually delete the objects directory to simulate a partial clone
1266+
File.Delete(Path.Combine(repoPath, "objects", "58", "1f9824ecaf824221bd36edf5430f2739a7c4f5"));
1267+
1268+
using (var repo = new Repository(repoPath))
1269+
{
1270+
// The commit is there but its tree is missing
1271+
var commit = repo.Lookup<Commit>("4c062a6361ae6959e06292c1fa5e2822d9c96345");
1272+
Assert.NotNull(commit);
1273+
Assert.Equal("581f9824ecaf824221bd36edf5430f2739a7c4f5", commit.Tree.Sha);
1274+
Assert.True(commit.Tree.IsMissing);
1275+
1276+
var tree = repo.Lookup<Tree>("581f9824ecaf824221bd36edf5430f2739a7c4f5");
1277+
Assert.Null(tree);
1278+
1279+
var otherCommit = repo.Lookup<Commit>("be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
1280+
Assert.NotNull(otherCommit);
1281+
Assert.False(otherCommit.Tree.IsMissing);
1282+
1283+
Assert.Throws<NotFoundException>(() =>
1284+
{
1285+
using (repo.Diff.Compare<TreeChanges>(commit.Tree, otherCommit.Tree)) {}
1286+
});
1287+
1288+
Assert.Throws<NotFoundException>(() =>
1289+
{
1290+
using (repo.Diff.Compare<TreeChanges>(otherCommit.Tree, commit.Tree)) {}
1291+
});
1292+
}
1293+
}
12591294
}
12601295
}

0 commit comments

Comments
 (0)