8000 Merge remote-tracking branch 'upstream/vNext' into vNext · gitextensions/libgit2sharp@f81950f · GitHub
[go: up one dir, main page]

Skip to content

Commit f81950f

Browse files
committed
Merge remote-tracking branch 'upstream/vNext' into vNext
2 parents 65550a8 + d9ecbae commit f81950f

Some content is hidden

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

51 files changed

+897
-309
lines changed
-798 KB
Binary file not shown.
-4.77 MB
Binary file not shown.
850 KB
Binary file not shown.
4.48 MB
Binary file not shown.
-602 KB
Binary file not shown.
-4.72 MB
Binary file not shown.
647 KB
Binary file not shown.
4.45 MB
Binary file not shown.

LibGit2Sharp.Tests/AttributesFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ private static void AssertNormalization(Repository repo, string filename, bool s
4040
var blob = repo.Lookup<Blob>(entry.Id);
4141
Assert.NotNull(blob);
4242

43-
Assert.Equal(!shouldHaveBeenNormalized, blob.ContentAsText().Contains("\r"));
43+
Assert.Equal(!shouldHaveBeenNormalized, blob.GetContentText().Contains("\r"));
4444
}
4545

4646
private static void CreateAttributesFile(Repository repo)

LibGit2Sharp.Tests/BlobFixture.cs

Lines changed: 47 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,30 @@ public void CanGetBlobAsText()
1717
{
1818
var blob = repo.Lookup<Blob>("a8233120f6ad708f843d861ce2b7228ec4e3dec6");
1919

20-
var text = blob.ContentAsText();
20+
var text = blob.GetContentText();
2121

2222
Assert.Equal("hey there\n", text);
2323
}
2424
}
2525

26-
[Fact]
27-
public void CanGetBlobAsFilteredText()
26+
[SkippableTheory]
27+
[InlineData("false", "hey there\n")]
28+
[InlineData("input", "hey there\n")]
29+
[InlineData("true", "hey there\r\n")]
30+
public void CanGetBlobAsFilteredText(string autocrlf, string expectedText)
2831
{
29-
using (var repo = new Repository(BareTestRepoPath))
32+
SkipIfNotSupported(autocrlf);
33+
34+
var path = CloneBareTestRepo();
35+
using (var repo = new Repository(path))
3036
{
31-
var blob = repo.Lookup<Blob>("a8233120f6ad708f843d861ce2b7228ec4e3dec6");
37+
repo.Config.Set("core.autocrlf", autocrlf);
3238

33-
var text = blob.ContentAsText(new FilteringOptions("foo.txt"));
39+
var blob = repo.Lookup<Blob>("a8233120f6ad708f843d861ce2b7228ec4e3dec6");
3440

35-
ConfigurationEntry<bool> autocrlf = repo.Config.Get<bool>("core.autocrlf");
41+
var text = blob.GetContentText(new FilteringOptions("foo.txt"));
3642

37-
if (autocrlf != null && autocrlf.Value)
38-
{
39-
Assert.Equal("hey there\r\n", text);
40-
}
41-
else
42-
{
43-
Assert.Equal("hey there\n", text);
44-
}
43+
Assert.Equal(expectedText, text);
4544
}
4645
}
4746

@@ -68,15 +67,15 @@ public void CanGetBlobAsTextWithVariousEncodings(string encodingName, int expect
6867
var commit = repo.Commit("bom", Constants.Signature, Constants.Signature);
6968

7069
var blob = (Blob)commit.Tree[bomFile].Target;
71-
Assert.Equal(expectedContentBytes, blob.Content.Length);
70+
Assert.Equal(expectedContentBytes, blob.GetContentStream().Length);
7271

73-
var textDetected = blob.ContentAsText();
72+
var textDetected = blob.GetContentText();
7473
Assert.Equal(content, textDetected);
7574

76-
var text = blob.ContentAsText(encoding);
75+
var text = blob.GetContentText(encoding);
7776
Assert.Equal(content, text);
7877

79-
var utf7Chars = blob.ContentAsText(Encoding.UTF7).Select(c => ((int)c).ToString("X2")).ToArray();
78+
var utf7Chars = blob.GetContentText(Encoding.UTF7).Select(c => ((int)c).ToString("X2")).ToArray();
8079
Assert.Equal(expectedUtf7Chars, string.Join(" ", utf7Chars));
8180
}
8281
}
@@ -101,56 +100,47 @@ public void CanLookUpBlob()
101100
}
102101
}
103102

104-
[Fact]
105-
public void CanReadBlobContent()
106-
{
107-
using (var repo = new Repository(BareTestRepoPath))
108-
{
109-
var blob = repo.Lookup<Blob>("a8233120f6ad708f843d861ce2b7228ec4e3dec6");
110-
byte[] bytes = blob.Content;
111-
Assert.Equal(10, bytes.Length);
112-
113-
string content = Encoding.UTF8.GetString(bytes);
114-
Assert.Equal("hey there\n", content);
115-
}
116-
}
117-
118103
[Fact]
119104
public void CanReadBlobStream()
120105
{
121106
using (var repo = new Repository(BareTestRepoPath))
122107
{
123108
var blob = repo.Lookup<Blob>("a8233120f6ad708f843d861ce2b7228ec4e3dec6");
124109

125-
using (var tr = new StreamReader(blob.ContentStream(), Encoding.UTF8))
110+
var contentStream = blob.GetContentStream();
111+
Assert.Equal(blob.Size, contentStream.Length);
112+
113+
using (var tr = new StreamReader(contentStream, Encoding.UTF8))
126114
{
127115
string content = tr.ReadToEnd();
128116
Assert.Equal("hey there\n", content);
129117
}
130118
}
131119
}
132120

133-
[Fact]
134-
public void CanReadBlobFilteredStream()
121+
[SkippableTheory]
122+
[InlineData("false", "hey there\n")]
123+
[InlineData("input", "hey there\n")]
124+
[InlineData("true", "hey there\r\n")]
125+
public void CanReadBlobFilteredStream(string autocrlf, string expectedContent)
135126
{
136-
using (var repo = new Repository(BareTestRepoPath))
127+
SkipIfNotSupported(autocrlf);
128+
129+
var path = CloneBareTestRepo();
130+
using (var repo = new Repository(path))
137131
{
132+
repo.Config.Set("core.autocrlf", autocrlf);
133+
138134
var blob = repo.Lookup<Blob>("a8233120f6ad708f843d861ce2b7228ec4e3dec6");
139135

140-
using (var tr = new StreamReader(blob.ContentStream(new FilteringOptions("foo.txt")), Encoding.UTF8))
136+
var contentStream = blob.GetContentStream(new FilteringOptions("foo.txt"));
137+
Assert.Equal(expectedContent.Length, contentStream.Length);
138+
139+
using (var tr = new StreamReader(contentStream, Encoding.UTF8))
141140
{
142141
string content = tr.ReadToEnd();
143142

144-
ConfigurationEntry<bool> autocrlf = repo.Config.Get<bool>("core.autocrlf");
145-
146-
if (autocrlf != null && autocrlf.Value)
147-
{
148-
Assert.Equal("hey there\r\n", content);
149-
}
150-
else
151-
{
152-
Assert.Equal(&q 10000 uot;hey there\n", content);
153-
}
143+
Assert.Equal(expectedContent, content);
154144
}
155145
}
156146
}
@@ -167,40 +157,15 @@ public void CanReadBlobFilteredStreamOfUnmodifiedBinary()
167157
{
168158
Blob blob = repo.ObjectDatabase.CreateBlob(stream);
169159

170-
using (var filtered = blob.ContentStream(new FilteringOptions("foo.txt")))
160+
using (var filtered = blob.GetContentStream(new FilteringOptions("foo.txt")))
171161
{
162+
Assert.Equal(blob.Size, filtered.Length);
172163
Assert.True(StreamEquals(stream, filtered));
173164
}
174165
}
175166
}
176167
}
177168

178-
public static void CopyStream(Stream input, Stream output)
179-
{
180-
// Reused from the following Stack Overflow post with permission
181-
// of Jon Skeet (obtained on 25 Feb 2013)
182-
// http://stackoverflow.com/questions/411592/how-do-i-save-a-stream-to-a-file/411605#411605
183-
var buffer = new byte[8*1024];
184-
int len;
185-
while ((len = input.Read(buffer, 0, buffer.Length)) > 0)
186-
{
187-
output.Write(buffer, 0, len);
188-
}
189-
}
190-
191-
public static bool StreamEquals(Stream one, Stream two)
192-
{
193-
int onebyte, twobyte;
194-
195-
while ((onebyte = one.ReadByte()) >= 0 && (twobyte = two.ReadByte()) >= 0)
196-
{
197-
if (onebyte != twobyte)
198-
return false;
199-
}
200-
201-
return true;
202-
}
203-
204169
[Fact]
205170
public void CanStageAFileGeneratedFromABlobContentStream()
206171
{
@@ -224,7 +189,7 @@ public void CanStageAFileGeneratedFromABlobContentStream()
224189

225190
var blob = repo.Lookup<Blob>(entry.Id.Sha);
226191

227-
using (Stream stream = blob.ContentStream())
192+
using (Stream stream = blob.GetContentStream())
228193
using (Stream file = File.OpenWrite(Path.Combine(repo.Info.WorkingDirectory, "small.fromblob.txt")))
229194
{
230195
CopyStream(stream, file);
@@ -246,5 +211,11 @@ public void CanTellIfTheBlobContentLooksLikeBinary()
246211
Assert.Equal(false, blob.IsBinary);
247212
}
248213
}
214+
215+
private static void SkipIfNotSupported(string autocrlf)
216+
{
217+
InconclusiveIf(() => autocrlf == "true" && IsRunningOnLinux(), "Non-Windows does not support core.autocrlf = true");
218+
InconclusiveIf(() => autocrlf == "input" && !IsRunningOnLinux(), "Windows does not support core.autocrlf = input");
219+
}
249220
}
250221
}

LibGit2Sharp.Tests/BranchFixture.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ public void LookingOutABranchByNameWithBadParamsThrows()
450450
}
451451
}
452452

453+
[Fact]
453454
public void CanGetInformationFromUnbornBranch()
454455
{
455456
string repoPath = InitNewRepository(true);

LibGit2Sharp.Tests/CommitFixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ public void CanDirectlyAccessABlobOfTheCommit()
480480
var blob = commit["1/branch_file.txt"].Target as Blob;
481481
Assert.NotNull(blob);
482482

483-
Assert.Equal("hi\n", blob.ContentAsText());
483+
Assert.Equal("hi\n", blob.GetContentText());
484484
}
485485
}
486486

@@ -694,7 +694,7 @@ public void CanCommitALittleBit()
694694
private static void AssertBlobContent(TreeEntry entry, string expectedContent)
695695
{
696696
Assert.Equal(TreeEntryTargetType.Blob, entry.TargetType);
697-
Assert.Equal(expectedContent, ((Blob)(entry.Target)).ContentAsText());
697+
Assert.Equal(expectedContent, ((Blob)(entry.Target)).GetContentText());
698698
}
699699

700700
private static void AddCommitToRepo(string path)

LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,10 @@ public void ComparingReliesOnProvidedConfigEntriesIfAny()
466466
// Recreate the file in the workdir without the executable bit
467467
string fullpath = Path.Combine(repo.Info.WorkingDirectory, file);
468468
File.Delete(fullpath);
469-
File.WriteAllBytes(fullpath, ((Blob)(entry.Target)).Content);
469+
using (var stream = ((Blob)(entry.Target)).GetContentStream())
470+
{
471+
Touch(repo.Info.WorkingDirectory, file, stream);
472+
}
470473

471474
// Unset the local core.filemode, if any.
472475
repo.Config.Unset("core.filemode");

LibGit2Sharp.Tests/DiffWorkdirToIndexFixture.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,10 @@ public void ComparingReliesOnProvidedConfigEntriesIfAny()
114114
// Recreate the file in the workdir without the executable bit
115115
string fullpath = Path.Combine(repo.Info.WorkingDirectory, file);
116116
File.Delete(fullpath);
117-
File.WriteAllBytes(fullpath, ((Blob)(entry.Target)).Content);
117+
using (var stream = ((Blob)(entry.Target)).GetContentStream())
118+
{
119+
Touch(repo.Info.WorkingDirectory, file, stream);
120+
}
118121

119122
// Unset the local core.filemode, if any.
120123
repo.Config.Unset("core.filemode", ConfigurationLevel.Local);

LibGit2Sharp.Tests/EqualityFixture.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using LibGit2Sharp.Tests.TestHelpers;
2+
using Xunit;
3+
4+
namespace LibGit2Sharp.Tests
5+
{
6+
public class EqualityFixture : BaseFixture
7+
{
8+
[Fact]
9+
public void EqualityHelperCanTestNullInEquals()
10+
{
11+
var one = new ObjectWithEquality();
12+
var two = new ObjectWithEquality();
13+
var three = new ObjectWithEquality(ObjectId.Zero);
14+
var four = new ObjectWithEquality(ObjectId.Zero);
15+
16+
Assert.True(one.Equals(one));
17+
Assert.True(two.Equals(two));
18+
Assert.True(three.Equals(four));
19+
Assert.True(four.Equals(three));
20+
Assert.False(one.Equals(three));
21+
Assert.False(three.Equals(one));
22+
}
23+
24+
[Fact]
25+
public void EqualityHelperCanTestNullInHashCode()
26+
{
27+
var one = new ObjectWithEquality();
28+
var two = new ObjectWithEquality();
29+
var three = new ObjectWithEquality(ObjectId.Zero);
30+
var four = new ObjectWithEquality(ObjectId.Zero);
31+
32+
Assert.Equal(one.GetHashCode(), two.GetHashCode());
33+
Assert.Equal(three.GetHashCode(), four.GetHashCode());
34+
Assert.NotEqual(one.GetHashCode(), three.GetHashCode());
35+
}
36+
37+
private class ObjectWithEquality : GitObject
38+
{
39+
private readonly ObjectId id;
40+
41+
public ObjectWithEquality(ObjectId id = null)
42+
{
43+
this.id = id;
44+
}
45+
46+
public override ObjectId Id
47+
{
48+
get { return id; }
49+
}
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)
0