Skip to content

Commit 83f710c

Browse files
committed
Merge remote-tracking branch 'origin/vNext' into add-revwalk-globs
2 parents aba6add + f8f29a9 commit 83f710c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+6912
-243
lines changed

Lib/MoQ/Moq.dll

496 KB
Binary file not shown.

Lib/MoQ/Moq.xml

Lines changed: 5768 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/NativeBinaries/amd64/git2.dll

3 KB
Binary file not shown.

Lib/NativeBinaries/amd64/git2.pdb

872 KB
Binary file not shown.

Lib/NativeBinaries/x86/git2.dll

-2.5 KB
Binary file not shown.

Lib/NativeBinaries/x86/git2.pdb

1.11 MB
Binary file not shown.

LibGit2Sharp.Tests/AttributesFixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public void StagingHonorsTheAttributesFiles()
2121
}
2222
}
2323

24-
private void AssertNormalization(Repository repo, string filename, bool shouldHaveBeenNormalized, string expectedSha)
24+
private static void AssertNormalization(Repository repo, string filename, bool shouldHaveBeenNormalized, string expectedSha)
2525
{
2626
var sb = new StringBuilder();
2727
sb.Append("I'm going to be dynamically processed\r\n");
@@ -44,7 +44,7 @@ private void AssertNormalization(Repository repo, string filename, bool shouldHa
4444
Assert.Equal(!shouldHaveBeenNormalized, blob.ContentAsUtf8().Contains("\r"));
4545
}
4646

47-
private void CreateAttributesFile(Repository repo)
47+
private static void CreateAttributesFile(Repository repo)
4848
{
4949
const string relativePath = ".gitattributes";
5050
string fullFilePath = Path.Combine(repo.Info.WorkingDirectory, relativePath);

LibGit2Sharp.Tests/CommitFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ private static void CreateAndStageANewFile(Repository repo)
650650
repo.Index.Stage(relativeFilepath);
651651
}
652652

653-
private void AssertCommitHasBeenAmended(Repository repo, Commit amendedCommit, Commit originalCommit)
653+
private static void AssertCommitHasBeenAmended(Repository repo, Commit amendedCommit, Commit originalCommit)
654654
{
655655
Commit headCommit = repo.Head.Tip;
656656
Assert.Equal(amendedCommit, headCommit);

LibGit2Sharp.Tests/DiffTreeToTargetFixture.cs

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,146 @@ private static void SetUpSimpleDiffContext(Repository repo)
2323
File.AppendAllText(fullpath, "!!!\n");
2424
}
2525

26+
[Fact]
27+
/*
28+
* No direct git equivalent but should output
29+
*
30+
* diff --git a/file.txt b/file.txt
31+
* index ce01362..4f125e3 100644
32+
* --- a/file.txt
33+
* +++ b/file.txt
34+
* @@ -1 +1,3 @@
35+
* hello
36+
* +world
37+
* +!!!
38+
*/
39+
public void CanCompareASimpleTreeAgainstTheWorkDir()
40+
{
41+
var scd = BuildSelfCleaningDirectory();
42+
43+
using (var repo = Repository.Init(scd.RootedDirectoryPath))
44+
{
45+
SetUpSimpleDiffContext(repo);
46+
47+
TreeChanges changes = repo.Diff.Compare(repo.Head.Tip.Tree, DiffTarget.WorkingDirectory);
48+
49+
var expected = new StringBuilder()
50+
.Append("diff --git a/file.txt b/file.txt\n")
51+
.Append("index ce01362..4f125e3 100644\n")
52+
.Append("--- a/file.txt\n")
53+
.Append("+++ b/file.txt\n")
54+
.Append("@@ -1 +1,3 @@\n")
55+
.Append(" hello\n")
56+
.Append("+world\n")
57+
.Append("+!!!\n");
58+
59+
Assert.Equal(expected.ToString(), changes.Patch);
60+
}
61+
}
62+
63+
[Fact]
64+
/*
65+
* $ git diff HEAD
66+
* diff --git a/file.txt b/file.txt
67+
* index ce01362..4f125e3 100644
68+
* --- a/file.txt
69+
* +++ b/file.txt
70+
* @@ -1 +1,3 @@
71+
* hello
72+
* +world
73+
* +!!!
74+
*/
75+
public void CanCompareASimpleTreeAgainstTheWorkDirAndTheIndex()
76+
{
77+
var scd = BuildSelfCleaningDirectory();
78+
79+
using (var repo = Repository.Init(scd.RootedDirectoryPath))
80+
{
81+
SetUpSimpleDiffContext(repo);
82+
83+
TreeChanges changes = repo.Diff.Compare(repo.Head.Tip.Tree, DiffTarget.BothWorkingDirectoryAndIndex);
84+
85+
var expected = new StringBuilder()
86+
.Append("diff --git a/file.txt b/file.txt\n")
87+
.Append("index ce01362..4f125e3 100644\n")
88+
.Append("--- a/file.txt\n")
89+
.Append("+++ b/file.txt\n")
90+
.Append("@@ -1 +1,3 @@\n")
91+
.Append(" hello\n")
92+
.Append("+world\n")
93+
.Append("+!!!\n");
94+
95+
Assert.Equal(expected.ToString(), changes.Patch);
96+
}
97+
}
98+
99+
100+
[Fact]
101+
/*
102+
* $ git diff
103+
*
104+
* $ git diff HEAD
105+
* diff --git a/file.txt b/file.txt
106+
* deleted file mode 100644
107+
* index ce01362..0000000
108+
* --- a/file.txt
109+
* +++ /dev/null
110+
* @@ -1 +0,0 @@
111+
* -hello
112+
*
113+
* $ git diff --cached
114+
* diff --git a/file.txt b/file.txt
115+
* deleted file mode 100644
116+
* index ce01362..0000000
117+
* --- a/file.txt
118+
* +++ /dev/null
119+
* @@ -1 +0,0 @@
120+
* -hello
121+
*/
122+
public void ShowcaseTheDifferenceBetweenTheTwoKindOfComparison()
123+
{
124+
var scd = BuildSelfCleaningDirectory();
125+
126+
using (var repo = Repository.Init(scd.RootedDirectoryPath))
127+
{
128+
SetUpSimpleDiffContext(repo);
129+
130+
var fullpath = Path.Combine(repo.Info.WorkingDirectory, "file.txt");
131+
File.Move(fullpath, fullpath + ".bak");
132+
repo.Index.Stage(fullpath);
133+
File.Move(fullpath + ".bak", fullpath);
134+
135+
FileStatus state = repo.Index.RetrieveStatus("file.txt");
136+
Assert.Equal(FileStatus.Removed | FileStatus.Untracked, state);
137+
138+
139+
TreeChanges wrkDirToIdxToTree = repo.Diff.Compare(repo.Head.Tip.Tree, DiffTarget.BothWorkingDirectoryAndIndex);
140+
var expected = new StringBuilder()
141+
.Append("diff --git a/file.txt b/file.txt\n")
142+
.Append("deleted file mode 100644\n")
143+
.Append("index ce01362..0000000\n")
144+
.Append("--- a/file.txt\n")
145+
.Append("+++ /dev/null\n")
146+
.Append("@@ -1 +0,0 @@\n")
147+
.Append("-hello\n");
148+
149+
Assert.Equal(expected.ToString(), wrkDirToIdxToTree.Patch);
150+
151+
TreeChanges wrkDirToTree = repo.Diff.Compare(repo.Head.Tip.Tree, DiffTarget.WorkingDirectory);
152+
expected = new StringBuilder()
153+
.Append("diff --git a/file.txt b/file.txt\n")
154+
.Append("index ce01362..4f125e3 100644\n")
155+
.Append("--- a/file.txt\n")
156+
.Append("+++ b/file.txt\n")
157+
.Append("@@ -1 +1,3 @@\n")
158+
.Append(" hello\n")
159+
.Append("+world\n")
160+
.Append("+!!!\n");
161+
162+
Assert.Equal(expected.ToString(), wrkDirToTree.Patch);
163+
}
164+
}
165+
26166
[Fact]
27167
/*
28168
* $ git diff --cached
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System.Linq;
2+
using LibGit2Sharp.Tests.TestHelpers;
3+
using Xunit;
4+
5+
namespace LibGit2Sharp.Tests
6+
{
7+
public class DiffWorkdirToIndexFixture : BaseFixture
8+
{
9+
/*
10+
* $ git diff
11+
* diff --git a/deleted_unstaged_file.txt b/deleted_unstaged_file.txt
12+
* deleted file mode 100644
13+
* index f2e4113..0000000
14+
* --- a/deleted_unstaged_file.txt
15+
* +++ /dev/null
16+
* @@ -1 +0,0 @@
17+
* -stuff
18+
* diff --git a/modified_unstaged_file.txt b/modified_unstaged_file.txt
19+
* index 9217230..da6fd65 100644
20+
* --- a/modified_unstaged_file.txt
21+
* +++ b/modified_unstaged_file.txt
22+
* @@ -1 +1,2 @@
23+
* +some more text
24+
* more files! more files!
25+
*/
26+
[Fact]
27+
public void CanCompareTheWorkDirAgainstTheIndex()
28+
{
29+
using (var repo = new Repository(StandardTestRepoPath))
30+
{
31+
TreeChanges changes = repo.Diff.Compare();
32+
33+
Assert.Equal(2, changes.Count());
34+
Assert.Equal("deleted_unstaged_file.txt", changes.Deleted.Single().Path);
35+
Assert.Equal("modified_unstaged_file.txt", changes.Modified.Single().Path);
36+
}
37+
}
38+
}
39+
}

LibGit2Sharp.Tests/IndexFixture.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public void ReadIndexWithBadParamsFails()
8484

8585
[Theory]
8686
[InlineData("1/branch_file.txt", FileStatus.Unaltered, true, FileStatus.Unaltered, true, 0)]
87+
[InlineData("README", FileStatus.Unaltered, true, FileStatus.Unaltered, true, 0)]
8788
[InlineData("deleted_unstaged_file.txt", FileStatus.Missing, true, FileStatus.Removed, false, -1)]
8889
[InlineData("modified_unstaged_file.txt", FileStatus.Modified, true, FileStatus.Staged, true, 0)]
8990
[InlineData("new_untracked_file.txt", FileStatus.Untracked, false, FileStatus.Added, true, 1)]

LibGit2Sharp.Tests/LazyFixture.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using LibGit2Sharp.Core.Compat;
3-
using LibGit2Sharp.Tests.TestHelpers;
43
using Xunit;
54

65
namespace LibGit2Sharp.Tests

LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
<DocumentationFile />
4444
</PropertyGroup>
4545
<ItemGroup>
46+
<Reference Include="Moq, Version=4.0.10827.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
47+
<SpecificVersion>False</SpecificVersion>
48+
<HintPath>..\Lib\MoQ\Moq.dll</HintPath>
49+
</Reference>
4650
<Reference Include="System" />
4751
<Reference Include="System.Core" />
4852
<Reference Include="xunit">
@@ -53,12 +57,15 @@
5357
</Reference>
5458
</ItemGroup>
5559
<ItemGroup>
60+
<Compile Include="MetaFixture.cs" />
61+
<Compile Include="MockedRepositoryFixture.cs" />
5662
<Compile Include="ConfigurationFixture.cs" />
5763
<Compile Include="AttributesFixture.cs" />
5864
<Compile Include="CommitAncestorFixture.cs" />
5965
<Compile Include="NoteFixture.cs" />
6066
<Compile Include="DiffBlobToBlobFixture.cs" />
6167
<Compile Include="DiffTreeToTargetFixture.cs" />
68+
<Compile Include="DiffWorkdirToIndexFixture.cs" />
6269
<Compile Include="ObjectDatabaseFixture.cs" />
6370
<Compile Include="DiffTreeToTreeFixture.cs" />
6471
<Compile Include="RepositoryOptionsFixture.cs" />

LibGit2Sharp.Tests/MetaFixture.cs

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
using System.Text;
2+
using Xunit;
3+
using System.Reflection;
4+
using System;
5+
using System.Linq;
6+
using System.Collections.Generic;
7+
8+
namespace LibGit2Sharp.Tests
9+
{
10+
public class MetaFixture
11+
{
12+
private static readonly Type[] excludedTypes = new[] { typeof(Repository) };
13+
14+
// Related to https://github.com/libgit2/libgit2sharp/pull/185
15+
[Fact]
16+
public void TypesInLibGit2SharpMustBeExtensibleInATestingContext()
17+
{
18+
var nonTestableTypes = new Dictionary<Type, IEnumerable<string>>();
19+
20+
IEnumerable<Type> libGit2SharpTypes = Assembly.GetAssembly(typeof(Repository)).GetExportedTypes().Where(t => !excludedTypes.Contains(t) && t.Namespace == typeof(Repository).Namespace);
21+
22+
foreach (Type type in libGit2SharpTypes)
23+
{
24+
if (type.IsInterface || type.IsEnum || IsStatic(type))
25+
continue;
26+
27+
ConstructorInfo[] publicConstructor = type.GetConstructors(BindingFlags.Public | BindingFlags.Instance);
28+
if (publicConstructor.Any())
29+
{
30+
continue;
31+
}
32+
33+
var nonVirtualMethodNamesForType = GetNonVirtualPublicMethodsNames(type).ToList();
34+
if (nonVirtualMethodNamesForType.Any())
35+
{
36+
nonTestableTypes.Add(type, nonVirtualMethodNamesForType);
37+
continue;
38+
}
39+
40+
if (!HasEmptyProtectedConstructor(type))
41+
{
42+
nonTestableTypes.Add(type, new List<string>());
43+
}
44+
}
45+
46+
if (nonTestableTypes.Any())
47+
{
48+
Assert.True(false, Environment.NewLine + BuildNonTestableTypesMessage(nonTestableTypes));
49+
}
50+
}
51+
52+
private static string BuildNonTestableTypesMessage(Dictionary<Type, IEnumerable<string>> nonTestableTypes)
53+
{
54+
var sb = new StringBuilder();
55+
56+
foreach (var kvp in nonTestableTypes)
57+
{
58+
sb.AppendFormat("'{0}' cannot be easily abstracted in a testing context. Please make sure it either has a public constructor, or an empty protected constructor.{1}",
59+
kvp.Key, Environment.NewLine);
60+
61+
foreach (string methodName in kvp.Value)
62+
{
63+
sb.AppendFormat(" - Method '{0}' must be virtual{1}", methodName, Environment.NewLine);
64+
}
65+
}
66+
67+
return sb.ToString();
68+
}
69+
70+
private static IEnumerable<string> GetNonVirtualPublicMethodsNames(Type type)
71+
{
72+
var publicMethods = type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
73+
74+
return from mi in publicMethods where !mi.IsVirtual && !mi.IsStatic select mi.ToString();
75+
}
76+
77+
private static bool HasEmptyProtectedConstructor(Type type)
78+
{
79+
ConstructorInfo[] nonPublicConstructors = type.GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance);
80+
81+
return nonPublicConstructors.Any(ci => !ci.IsPrivate && !ci.IsAssembly && !ci.IsFinal && !ci.GetParameters().Any());
82+
}
83+
84+
private static bool IsStatic(Type type)
85+
{
86+
return type.IsAbstract && type.IsSealed;
87+
}
88+
}
89+
}

0 commit comments

Comments
 (0)