8000 Merge branch 'upstream_vNext' into vNext · gitextensions/libgit2sharp@65550a8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 65550a8

Browse files
committed
Merge branch 'upstream_vNext' into vNext
2 parents 2539d17 + abc7b61 commit 65550a8

Some content is hidden

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

54 files changed

+1656
-755
lines changed

LibGit2Sharp.Tests/BlobFixture.cs

Lines changed: 84 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.IO;
1+
using System;
2+
using System.IO;
23
using System.Linq;
34
using System.Text;
45
using LibGit2Sharp.Tests.TestHelpers;
@@ -22,6 +23,28 @@ public void CanGetBlobAsText()
2223
}
2324
}
2425

26+
[Fact]
27+
public void CanGetBlobAsFilteredText()
28+
{
29+
using (var repo = new Repository(BareTestRepoPath))
30+
{
31+
var blob = repo.Lookup<Blob>("a8233120f6ad708f843d861ce2b7228ec4e3dec6");
32+
33+
var text = blob.ContentAsText(new FilteringOptions("foo.txt"));
34+
35+
ConfigurationEntry<bool> autocrlf = repo.Config.Get<bool>("core.autocrlf");
36+
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+
}
45+
}
46+
}
47+
2548
[Theory]
2649
[InlineData("ascii", 4, "31 32 33 34")]
2750
[InlineData("utf-7", 4, "31 32 33 34")]
@@ -99,14 +122,59 @@ public void CanReadBlobStream()
99122
{
100123
var blob = repo.Lookup<Blob>("a8233120f6ad708f843d861ce2b7228ec4e3dec6");
101124

102-
using (var tr = new StreamReader(blob.ContentStream, Encoding.UTF8))
125+
using (var tr = new StreamReader(blob.ContentStream(), Encoding.UTF8))
103126
{
104127
string content = tr.ReadToEnd();
105128
Assert.Equal("hey there\n", content);
106129
}
107130
}
108131
}
109132

133+
[Fact]
134+
public void CanReadBlobFilteredStream()
135+
{
136+
using (var repo = new Repository(BareTestRepoPath))
137+
{
138+
var blob = repo.Lookup<Blob>("a8233120f6ad708f843d861ce2b7228ec4e3dec6");
139+
140+
using (var tr = new StreamReader(blob.ContentStream(new FilteringOptions("foo.txt")), Encoding.UTF8))
141+
{
142+
string content = tr.ReadToEnd();
143+
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("hey there\n", content);
153+
}
154+
}
155+
}
156+
}
157+
158+
[Fact]
159+
public void CanReadBlobFilteredStreamOfUnmodifiedBinary()
160+
{
161+
var binaryContent = new byte[] { 0, 1, 2, 3, 4, 5 };
162+
163+
string path = CloneBareTestRepo();
164+
using (var repo = new Repository(path))
165+
{
166+
using (var stream = new MemoryStream(binaryContent))
167+
{
168+
Blob blob = repo.ObjectDatabase.CreateBlob(stream);
169+
170+
using (var filtered = blob.ContentStream(new FilteringOptions("foo.txt")))
171+
{
172+
Assert.True(StreamEquals(stream, filtered));
173+
}
174+
}
175+
}
176+
}
177+
110178
public static void CopyStream(Stream input, Stream output)
111179
{
112180
// Reused from the following Stack Overflow post with permission
@@ -120,6 +188,19 @@ public static void CopyStream(Stream input, Stream output)
120188
}
121189
}
122190

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+
123204
[Fact]
124205
public void CanStageAFileGeneratedFromABlobContentStream()
125206
{
@@ -143,7 +224,7 @@ public void CanStageAFileGeneratedFromABlobContentStream()
143224

144225
var blob = repo.Lookup<Blob>(entry.Id.Sha);
145226

146-
using (Stream stream = blob.ContentStream)
227+
using (Stream stream = blob.ContentStream())
147228
using (Stream file = File.OpenWrite(Path.Combine(repo.Info.WorkingDirectory, "small.fromblob.txt")))
148229
{
149230
CopyStream(stream, file);

LibGit2Sharp.Tests/BranchFixture.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,40 @@ public void CanCreateBranch(string name)
4242
}
4343
}
4444

45+
[Fact]
46+
public void CanCreateAnUnbornBranch()
47+
{
48+
string path = CloneStandardTestRepo();
49+
using (var repo = new Repository(path))
50+
{
51+
// No branch named orphan
52+
Assert.Null(repo.Branches["orphan"]);
53+
54+
// HEAD doesn't point to an unborn branch
55+
Assert.False(repo.Info.IsHeadUnborn);
56+
57+
// Let's move the HEAD to this branch to be created
58+
repo.Refs.UpdateTarget("HEAD", "refs/heads/orphan");
59+
Assert.True(repo.Info.IsHeadUnborn);
60+
61+
// The branch still doesn't exist
62+
Assert.Null(repo.Branches["orphan"]);
63+
64+
// Create a commit against HEAD
65+
Commit c = repo.Commit("New initial root commit", Constants.Signature, Constants.Signature);
66+
67+
// Ensure this commit has no parent
68+
Assert.Equal(0, c.Parents.Count());
69+
70+
// The branch now exists...
71+
Branch orphan = repo.Branches["orphan"];
72+
Assert.NotNull(orphan);
73+
74+
// ...and points to that newly created commit
75+
Assert.Equal(c, orphan.Tip);
76+
}
77+
}
78+
4579
[Fact]
4680
public void CanCreateBranchUsingAbbreviatedSha()
4781
{

LibGit2Sharp.Tests/CloneFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public void CallsProgressCallbacks(string url)
116116
var scd = BuildSelfCleaningDirectory();
117117

118118
Repository.Clone(url, scd.DirectoryPath,
119-
onTransferProgress: _ => { transferWasCalled = true; return 0; },
119+
onTransferProgress: _ => { transferWasCalled = true; return true; },
120120
onCheckoutProgress: (a, b, c) => checkoutWasCalled = true);
121121

122122
Assert.True(transferWasCalled);

0 commit comments

Comments
 (0)
0