8000 Add tar archiving tests · GiTechLab/libgit2sharp@88bf65e · GitHub
[go: up one dir, main page]

Skip to content

Commit 88bf65e

Browse files
committed
Add tar archiving tests
1 parent 36d40bd commit 88bf65e

File tree

4 files changed

+46
-0
lines changed
8000

4 files changed

+46
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
using System.IO;
3+
using System.Text;
4+
using LibGit2Sharp.Tests.TestHelpers;
5+
using Xunit;
6+
7+
namespace LibGit2Sharp.Tests
8+
{
9+
public class ArchiveTarFixture : BaseFixture
10+
{
11+
[Fact]
12+
public void CanArchiveACommitWithDirectoryAsTar()
13+
{
14+
var path = CloneBareTestRepo();
15+
using (var repo = new Repository(path))
16+
{
17+
// This tests generates an archive of the bare test repo, and compares it with
18+
// a pre-generated tar file. The expected tar file has been generated with the
19+
// crlf filter active (on windows), so we need to make sure that even if the test
20+
// is launched on linux then the files content has the crlf filter applied (not
21+
// active by default).
22+
var sb = new StringBuilder();
23+
sb.Append("* text eol=crlf\n");
24+
Touch(Path.Combine(repo.Info.Path, "info"), "attributes", sb.ToString());
25+
26+
var commit = repo.Lookup<Commit>("4c062a6361ae6959e06292c1fa5e2822d9c96345");
27+
28+
var scd = BuildSelfCleaningDirectory();
29+
var archivePath = Path.Combine(scd.RootedDirectoryPath, Guid.NewGuid() + ".tar");
30+
Directory.CreateDirectory(scd.RootedDirectoryPath);
31+
32+
repo.ObjectDatabase.Archive(commit, archivePath);
33+
34+
using (var expectedStream = new StreamReader(Path.Combine(ResourcesDirectory.FullName, "expected_archives/commit_with_directory.tar")))
35+
using (var actualStream = new StreamReader(archivePath))
36+
{
37+
string expected = expectedStream.ReadToEnd();
38+
string actual = actualStream.ReadToEnd();
39+
40+
Assert.Equal(expected, actual);
41+
}
42+
}
43+
}
44+
}
45+
}

LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
</ItemGroup>
6060
<ItemGroup>
6161
<Compile Include="BlameFixture.cs" />
62+
<Compile Include="ArchiveTarFixture.cs" />
6263
<Compile Include="CheckoutFixture.cs" />
6364
<Compile Include="RefSpecFixture.cs" />
6465
<Compile Include="EqualityFixture.cs" />
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)
0