8000 Merge pull request #1936 from jairbubbles/throw-notfoundexception-if-… · Calidus/libgit2sharp@ec8ff4a · GitHub
[go: up one dir, main page]

Skip to content

Commit ec8ff4a

Browse files
authored
Merge pull request libgit2#1936 from jairbubbles/throw-notfoundexception-if-trees-are-missing-when
Throw NotFoundException if trees are missing when computing diff
2 parents d8ec410 + 9780ddf commit ec8ff4a

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
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 tree object 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
}

LibGit2Sharp/Core/Proxy.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -797,8 +797,8 @@ public static unsafe DiffHandle git_diff_tree_to_tree(
797797
ObjectId newTree,
798798
GitDiffOptions options)
799799
{
800-
using (var osw1 = new ObjectSafeWrapper(oldTree, repo, true))
801-
using (var osw2 = new ObjectSafeWrapper(newTree, repo, true))
800+
using (var osw1 = new ObjectSafeWrapper(oldTree, repo, true, throwIfMissing: true))
801+
using (var osw2 = new ObjectSafeWrapper(newTree, repo, true, throwIfMissing: true))
802802
{
803803
git_diff* diff;
804804
int res = NativeMethods.git_diff_tree_to_tree(out diff, repo, osw1.ObjectPtr, osw2.ObjectPtr, options);

0 commit comments

Comments
 (0)
0