Skip to content

Commit b0aae85

Browse files
committed
Merge branch 'master' of github.com:libgit2/libgit2sharp
2 parents 691f705 + 3d72762 commit b0aae85

38 files changed

+1100
-352
lines changed

Diff for: LibGit2Sharp.Tests/CloneFixture.cs

+59-59
Original file line numberDiff line numberDiff line change
@@ -237,65 +237,65 @@ public void CanCloneFromBBWithCredentials(string url, string user, string pass,
237237
}
238238
}
239239

240-
[SkippableTheory]
241-
[InlineData("https://github.com/libgit2/TestGitRepository.git", "github.com", typeof(CertificateX509))]
242-
[InlineData("[email protected]:libgit2/TestGitRepository.git", "github.com", typeof(CertificateSsh))]
243-
public void CanInspectCertificateOnClone(string url, string hostname, Type certType)
244-
{
245-
var scd = BuildSelfCleaningDirectory();
246-
247-
InconclusiveIf(
248-
() =>
249-
certType == typeof (CertificateSsh) && !GlobalSettings.Version.Features.HasFlag(BuiltInFeatures.Ssh),
250-
"SSH not supported");
251-
252-
bool wasCalled = false;
253-
bool checksHappy = false;
254-
255-
var options = new CloneOptions {
256-
CertificateCheck = (cert, valid, host) => {
257-
wasCalled = true;
258-
259-
Assert.Equal(hostname, host);
260-
Assert.Equal(certType, cert.GetType());
261-
262-
if (certType == typeof(CertificateX509)) {
263-
Assert.True(valid);
264-
var x509 = ((CertificateX509)cert).Certificate;
265-
// we get a string with the different fields instead of a structure, so...
266-
Assert.Contains("CN=github.com,", x509.Subject);
267-
checksHappy = true;
268-
return false;
269-
}
270-
271-
if (certType == typeof(CertificateSsh)) {
272-
var hostkey = (CertificateSsh)cert;
273-
Assert.True(hostkey.HasMD5);
274-
/*
275-
* Once you've connected and thus your ssh has stored the hostkey,
276-
* you can get the hostkey for a host with
277-
*
278-
* ssh-keygen -F github.com -l | tail -n 1 | cut -d ' ' -f 2 | tr -d ':'
279-
*
280-
* though GitHub's hostkey won't change anytime soon.
281-
*/
282-
Assert.Equal("1627aca576282d36631b564debdfa648",
283-
BitConverter.ToString(hostkey.HashMD5).ToLower().Replace("-", ""));
284-
checksHappy = true;
285-
return false;
286-
}
287-
288-
return false;
289-
},
290-
};
291-
292-
Assert.Throws<UserCancelledException>(() =>
293-
Repository.Clone(url, scd.DirectoryPath, options)
294-
);
295-
296-
Assert.True(wasCalled);
297-
Assert.True(checksHappy);
298-
}
240+
//[SkippableTheory]
241+
//[InlineData("https://github.com/libgit2/TestGitRepository.git", "github.com", typeof(CertificateX509))]
242+
//[InlineData("[email protected]:libgit2/TestGitRepository.git", "github.com", typeof(CertificateSsh))]
243+
//public void CanInspectCertificateOnClone(string url, string hostname, Type certType)
244+
//{
245+
// var scd = BuildSelfCleaningDirectory();
246+
247+
// InconclusiveIf(
248+
// () =>
249+
// certType == typeof (CertificateSsh) && !GlobalSettings.Version.Features.HasFlag(BuiltInFeatures.Ssh),
250+
// "SSH not supported");
251+
252+
// bool wasCalled = false;
253+
// bool checksHappy = false;
254+
255+
// var options = new CloneOptions {
256+
// CertificateCheck = (cert, valid, host) => {
257+
// wasCalled = true;
258+
259+
// Assert.Equal(hostname, host);
260+
// Assert.Equal(certType, cert.GetType());
261+
262+
// if (certType == typeof(CertificateX509)) {
263+
// Assert.True(valid);
264+
// var x509 = ((CertificateX509)cert).Certificate;
265+
// // we get a string with the different fields instead of a structure, so...
266+
// Assert.Contains("CN=github.com,", x509.Subject);
267+
// checksHappy = true;
268+
// return false;
269+
// }
270+
271+
// if (certType == typeof(CertificateSsh)) {
272+
// var hostkey = (CertificateSsh)cert;
273+
// Assert.True(hostkey.HasMD5);
274+
// /*
275+
// * Once you've connected and thus your ssh has stored the hostkey,
276+
// * you can get the hostkey for a host with
277+
// *
278+
// * ssh-keygen -F github.com -l | tail -n 1 | cut -d ' ' -f 2 | tr -d ':'
279+
// *
280+
// * though GitHub's hostkey won't change anytime soon.
281+
// */
282+
// Assert.Equal("1627aca576282d36631b564debdfa648",
283+
// BitConverter.ToString(hostkey.HashMD5).ToLower().Replace("-", ""));
284+
// checksHappy = true;
285+
// return false;
286+
// }
287+
288+
// return false;
289+
// },
290+
// };
291+
292+
// Assert.Throws<UserCancelledException>(() =>
293+
// Repository.Clone(url, scd.DirectoryPath, options)
294+
// );
295+
296+
// Assert.True(wasCalled);
297+
// Assert.True(checksHappy);
298+
//}
299299

300300
[Theory]
301301
[InlineData("git://github.com/libgit2/TestGitRepository")]

Diff for: LibGit2Sharp.Tests/DiffBlobToBlobFixture.cs

+34
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,40 @@ public void ComparingBlobsWithNoSpacesIndentHeuristicOptionMakesNoDifference()
202202
}
203203
}
204204

205+
[Fact]
206+
public void DiffSetsTheAddedAndDeletedLinesCorrectly()
207+
{
208+
var path = SandboxStandardTestRepoGitDir();
209+
210+
using (var repo = new Repository(path))
211+
{
212+
var oldContent =
213+
@"1
214+
2
215+
3
216+
4";
217+
218+
var newContent =
219+
@"1
220+
2
221+
3
222+
5";
223+
var oldBlob = repo.ObjectDatabase.CreateBlob(new MemoryStream(Encoding.UTF8.GetBytes(oldContent)));
224+
var newBlob = repo.ObjectDatabase.CreateBlob(new MemoryStream(Encoding.UTF8.GetBytes(newContent)));
225+
226+
ContentChanges changes = repo.Diff.Compare(oldBlob, newBlob);
227+
228+
Assert.Single(changes.AddedLines);
229+
Assert.Single(changes.DeletedLines);
230+
231+
Assert.Equal("4", changes.DeletedLines.First().Content);
232+
Assert.Equal("5", changes.AddedLines.First().Content);
233+
234+
Assert.Equal(4, changes.DeletedLines.First().LineNumber);
235+
Assert.Equal(4, changes.AddedLines.First().LineNumber);
236+
}
237+
}
238+
205239
static string CanonicalChangedLines(ContentChanges changes)
206240
{
207241
// Create an ordered representation of lines that have been added or removed

Diff for: LibGit2Sharp.Tests/DiffTreeToTargetFixture.cs

+21-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ private static void SetUpSimpleDiffContext(IRepository repo)
1717

1818
File.AppendAllText(fullpath, "world\n");
1919

20-
Commands.Stage(repo,fullpath);
20+
Commands.Stage(repo, fullpath);
2121

2222
File.AppendAllText(fullpath, "!!!\n");
2323
}
@@ -509,5 +509,25 @@ public void CanCompareANullTreeAgainstTheWorkdirAndTheIndex()
509509
}
510510
}
511511
}
512+
513+
[Fact]
514+
public void CompareSetsCorrectAddedAndDeletedLines()
515+
{
516+
string repoPath = InitNewRepository();
517+
518+
using (var repo = new Repository(repoPath))
519+
{
520+
SetUpSimpleDiffContext(repo);
521+
522+
using (var changes = repo.Diff.Compare<Patch>(repo.Head.Tip.Tree,
523+
DiffTargets.WorkingDirectory | DiffTargets.Index))
524+
{
525+
foreach (var entry in changes)
526+
{
527+
Assert.Equal(2, entry.AddedLines.Count());
528+
}
529+
}
530+
}
531+
}
512532
}
513533
}

Diff for: LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs

+50-13
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Text;
55
using LibGit2Sharp.Tests.TestHelpers;
66
using Xunit;
7-
using Xunit.Extensions;
87

98
namespace LibGit2Sharp.Tests
109
{
@@ -20,7 +19,7 @@ public void ComparingATreeAgainstItselfReturnsNoDifference()
2019
{
2120
Tree tree = repo.Head.Tip.Tree;
2221

23-
using(var changes = repo.Diff.Compare<TreeChanges>(tree, tree))
22+
using (var changes = repo.Diff.Compare<TreeChanges>(tree, tree))
2423
{
2524
Assert.Empty(changes);
2625
}
@@ -112,13 +111,13 @@ public void CanDetectABinaryChange()
112111

113112
File.AppendAllText(filepath, "abcdef");
114113

115-
using(var patch = repo.Diff.Compare<Patch>(commit.Tree, DiffTargets.WorkingDirectory, new[] { filename }))
114+
using (var patch = repo.Diff.Compare<Patch>(commit.Tree, DiffTargets.WorkingDirectory, new[] { filename }))
116115
Assert.True(patch[filename].IsBinaryComparison);
117116

118117
Commands.Stage(repo, filename);
119118
var commit2 = repo.Commit("Update binary file", Constants.Signature, Constants.Signature);
120119

121-
using(var patch2 = repo.Diff.Compare<Patch>(commit.Tree, commit2.Tree, new[] { filename }))
120+
using (var patch2 = repo.Diff.Compare<Patch>(commit.Tree, commit2.Tree, new[] { filename }))
122121
Assert.True(patch2[filename].IsBinaryComparison);
123122
}
124123
}
@@ -138,13 +137,13 @@ public void CanDetectABinaryDeletion()
138137

139138
File.Delete(filepath);
140139

141-
using(var patch = repo.Diff.Compare<Patch>(commit.Tree, DiffTargets.WorkingDirectory, new [] {filename}))
140+
using (var patch = repo.Diff.Compare<Patch>(commit.Tree, DiffTargets.WorkingDirectory, new[] { filename }))
142141
Assert.True(patch[filename].IsBinaryComparison);
143142

144143
Commands.Remove(repo, filename);
145144
var commit2 = repo.Commit("Delete binary file", Constants.Signature, Constants.Signature);
146145

147-
using(var patch2 = repo.Diff.Compare<Patch>(commit.Tree, commit2.Tree, new[] { filename }))
146+
using (var patch2 = repo.Diff.Compare<Patch>(commit.Tree, commit2.Tree, new[] { filename }))
148147
Assert.True(patch2[filename].IsBinaryComparison);
149148
}
150149
}
@@ -704,7 +703,7 @@ public void CanIncludeUnmodifiedEntriesWhenEnabled()
704703
Touch(repo.Info.WorkingDirectory, "a.txt", "abc\ndef\n");
705704
Touch(repo.Info.WorkingDirectory, "b.txt", "abc\ndef\n");
706705

707-
Commands.Stage(repo, new[] {"a.txt", "b.txt"});
706+
Commands.Stage(repo, new[] { "a.txt", "b.txt" });
708707
Commit old = repo.Commit("Initial", Constants.Signature, Constants.Signature);
709708

710709
File.AppendAllText(Path.Combine(repo.Info.WorkingDirectory, "b.txt"), "ghi\njkl\n");
@@ -728,12 +727,12 @@ public void CanDetectTheExactRenamingExactCopyingOfNonModifiedAndModifiedFilesWh
728727
var path = Repository.Init(scd.DirectoryPath);
729728
using (var repo = new Repository(path))
730729
{
731-
const string originalPath = "original.txt";
732-
const string renamedPath = "renamed.txt";
730+
const string originalPath = "original.txt";
731+
const string renamedPath = "renamed.txt";
733732
const string originalPath2 = "original2.txt";
734-
const string copiedPath1 = "copied.txt";
733+
const string copiedPath1 = "copied.txt";
735734
const string originalPath3 = "original3.txt";
736-
const string copiedPath2 = "copied2.txt";
735+
const string copiedPath2 = "copied2.txt";
737736

738737
Touch(repo.Info.WorkingDirectory, originalPath, "a\nb\nc\nd\n");
739738
Touch(repo.Info.WorkingDirectory, originalPath2, "1\n2\n3\n4\n");
@@ -986,7 +985,7 @@ public void CanHandleTwoTreeEntryChangesWithTheSamePathUsingSimilarityNone()
986985
Assert.Single(changes.Deleted);
987986
Assert.Single(changes.TypeChanged);
988987

989-
TreeEntryChanges change = changes.Single(c => c.Path== path);
988+
TreeEntryChanges change = changes.Single(c => c.Path == path);
990989
Assert.Equal(Mode.SymbolicLink, change.OldMode);
991990
Assert.Equal(Mode.NonExecutableFile, change.Mode);
992991
Assert.Equal(ChangeKind.TypeChanged, change.Status);
@@ -1087,7 +1086,7 @@ public void ComparingReliesOnProvidedConfigEntriesIfAny()
10871086
using (var repo = new Repository(path))
10881087
{
10891088
SetFilemode(repo, true);
1090-
using(var changes = repo.Diff.Compare<TreeChanges>(new[] { file }))
1089+
using (var changes = repo.Diff.Compare<TreeChanges>(new[] { file }))
10911090
{
10921091
Assert.Single(changes);
10931092

@@ -1147,6 +1146,44 @@ public void RetrievingDiffChangesMustAlwaysBeCaseSensitive()
11471146
}
11481147
}
11491148

1149+
[Fact]
1150+
public void RetrievingDiffContainsRightAmountOfAddedAndDeletedLines()
1151+
{
1152+
ObjectId treeOldOid, treeNewOid;
1153+
1154+
string repoPath = InitNewRepository();
1155+
1156+
using (var repo = new Repository(repoPath))
1157+
{
1158+
Blob oldContent = OdbHelper.CreateBlob(repo, "awesome content\n");
1159+
Blob newContent = OdbHelper.CreateBlob(repo, "more awesome content\n");
1160+
1161+
var td = new TreeDefinition()
1162+
.Add("A.TXT", oldContent, Mode.NonExecutableFile)
1163+
.Add("a.txt", oldContent, Mode.NonExecutableFile);
1164+
1165+
treeOldOid = repo.ObjectDatabase.CreateTree(td).Id;
1166+
1167+
td = new TreeDefinition()
1168+
.Add("A.TXT", newContent, Mode.NonExecutableFile)
1169+
.Add("a.txt", newContent, Mode.NonExecutableFile);
1170+
1171+
treeNewOid = repo.ObjectDatabase.CreateTree(td).Id;
1172+
}
1173+
1174+
using (var repo = new Repository(repoPath))
1175+
{
1176+
using (var changes = repo.Diff.Compare<Patch>(repo.Lookup<Tree>(treeOldOid), repo.Lookup<Tree>(treeNewOid)))
1177+
{
1178+
foreach (var entry in changes)
1179+
{
1180+
Assert.Single(entry.AddedLines);
1181+
Assert.Single(entry.DeletedLines);
1182+
}
1183+
}
1184+
}
1185+
}
1186+
11501187
[Fact]
11511188
public void UsingPatienceAlgorithmCompareOptionProducesPatienceDiff()
11521189
{

0 commit comments

Comments
 (0)