|
| 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 | +} |
0 commit comments