Skip to content

Commit 4a5000b

Browse files
yorahnulltoken
authored andcommitted
Make Diff mockable
1 parent 9fffc4f commit 4a5000b

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

LibGit2Sharp/Diff.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ private static FilePath[] ToFilePaths(IEnumerable<string> paths)
5050
return filePaths.ToArray();
5151
}
5252

53+
/// <summary>
54+
/// Needed for mocking purposes.
55+
/// </summary>
56+
protected Diff()
57+
{ }
58+
5359
internal Diff(Repository repo)
5460
{
5561
this.repo = repo;
@@ -62,7 +68,7 @@ internal Diff(Repository repo)
6268
/// <param name = "newTree">The <see cref = "Tree"/> you want to compare to.</param>
6369
/// <param name = "paths">The list of paths (either files or directories) that should be compared.</param>
6470
/// <returns>A <see cref = "TreeChanges"/> containing the changes between the <paramref name = "oldTree"/> and the <paramref name = "newTree"/>.</returns>
65-
public TreeChanges Compare(Tree oldTree, Tree newTree, IEnumerable<string> paths = null)
71+
public virtual TreeChanges Compare(Tree oldTree, Tree newTree, IEnumerable<string> paths = null)
6672
{
6773
using(GitDiffOptions options = BuildOptions(paths))
6874
using (DiffListSafeHandle diff = BuildDiffListFromTrees(oldTree.Id, newTree.Id, options))
@@ -89,7 +95,7 @@ private DiffListSafeHandle BuildDiffListFromTrees(ObjectId oldTree, ObjectId new
8995
/// <param name = "oldBlob">The <see cref = "Blob"/> you want to compare from.</param>
9096
/// <param name = "newBlob">The <see cref = "Blob"/> you want to compare to.</param>
9197
/// <returns>A <see cref = "ContentChanges"/> containing the changes between the <paramref name = "oldBlob"/> and the <paramref name = "newBlob"/>.</returns>
92-
public ContentChanges Compare(Blob oldBlob, Blob newBlob)
98+
public virtual ContentChanges Compare(Blob oldBlob, Blob newBlob)
9399
{
94100
using (GitDiffOptions options = BuildOptions())
95101
{
@@ -114,7 +120,7 @@ private static IDictionary<DiffTarget, Func<Repository, TreeComparisonHandleRetr
114120
/// <param name = "diffTarget">The target to compare to.</param>
115121
/// <param name = "paths">The list of paths (either files or directories) that should be compared.</param>
116122
/// <returns>A <see cref = "TreeChanges"/> containing the changes between the <see cref="Tree"/> and the selected target.</returns>
117-
public TreeChanges Compare(Tree oldTree, DiffTarget diffTarget, IEnumerable<string> paths = null)
123+
public virtual TreeChanges Compare(Tree oldTree, DiffTarget diffTarget, IEnumerable<string> paths = null)
118124
{
119125
var comparer = handleRetrieverDispatcher[diffTarget](repo);
120126

0 commit comments

Comments
 (0)