1
1
using LibGit2Sharp . Tests . TestHelpers ;
2
- using System . Collections . Generic ;
2
+ using System ;
3
3
using System . IO ;
4
4
using System . Linq ;
5
5
using Xunit ;
@@ -9,18 +9,25 @@ namespace LibGit2Sharp.Tests
9
9
public class PackBuilderFixture : BaseFixture
10
10
{
11
11
[ Fact ]
12
- public void ObjectsWrittenSameAsOriginal ( )
12
+ public void TestDefaultBuildDelegate ( )
13
+ {
14
+ TestIfSameRepoAfterPacking ( null ) ;
15
+ }
16
+
17
+ [ Fact ]
18
+ public void TestCommitsPerBranchBuildDelegate ( )
19
+ {
20
+ TestIfSameRepoAfterPacking ( TestBuildDelegate ) ;
21
+ }
22
+
23
+ internal void TestIfSameRepoAfterPacking ( Action < PackBuilder > buildingDelegate )
13
24
{
14
25
// read a repo
15
- // pack with default action
26
+ // pack with the provided action
16
27
// write the pack file in a mirror repo
17
28
// read new repo
18
29
// compare
19
30
20
- //string orgRepoPath = @"D:\TestRepos\packbuilder_testrepo_wd\packbuilder_testrepo_git_org\dot_git";
21
- //string mrrRepoPath = @"D:\TestRepos\packbuilder_testrepo_wd\packbuilder_testrepo_git_mrr_1\dot_git";
22
- //string packFilePath = @"D:\TestRepos\packbuilder_testrepo_wd\packbuilder_testrepo_git_mrr_1\dot_git\objects\pack";
23
-
24
31
string orgRepoPath = SandboxPackBuilderTestRepo ( ) ;
25
32
SelfCleaningDirectory scd = BuildSelfCleaningDirectory ( orgRepoPath + "_mrr" ) ;
26
33
string mrrRepoPath = scd . DirectoryPath ;
@@ -37,7 +44,7 @@ public void ObjectsWrittenSameAsOriginal()
37
44
38
45
Repository orgRepo = new Repository ( orgRepoPath ) ;
39
46
40
- PackBuilderResults results = orgRepo . ObjectDatabase . Pack ( packBuilderOptions , null ) ;
47
+ PackBuilderResults results = orgRepo . ObjectDatabase . Pack ( packBuilderOptions , buildingDelegate ) ;
41
48
42
49
// written objects count is the same as in objects database
43
50
Assert . Equal ( orgRepo . ObjectDatabase . Count ( ) , results . WrittenObjectsCount ) ;
@@ -57,53 +64,13 @@ public void ObjectsWrittenSameAsOriginal()
57
64
mrrRepo . Dispose ( ) ;
58
65
}
59
66
60
- [ Fact ]
61
- public void ObjectsWrittenSameAsOriginalUsingDelegate ( )
62
- {
63
- string orgRepoPath = SandboxPackBuilderTestRepo ( ) ;
64
- SelfCleaningDirectory scd = BuildSelfCleaningDirectory ( orgRepoPath + "_mrr" ) ;
65
- string mrrRepoPath = scd . DirectoryPath ;
66
- string mrrRepoPathPackDirPath = mrrRepoPath + "/.git/objects" ;
67
-
68
- DirectoryHelper . CopyFilesRecursively ( new DirectoryInfo ( orgRepoPath ) , new DirectoryInfo ( mrrRepoPath ) ) ;
69
- DirectoryHelper . DeleteDirectory ( mrrRepoPathPackDirPath ) ;
70
- Directory . CreateDirectory ( mrrRepoPathPackDirPath ) ;
71
- Directory . CreateDirectory ( mrrRepoPathPackDirPath + "/pack" ) ;
72
-
73
- PackBuilderOptions packBuilderOptions = new PackBuilderOptions ( ) ;
74
- packBuilderOptions . MaximumNumberOfThreads = 0 ;
75
- packBuilderOptions . PackFilePath = mrrRepoPathPackDirPath + "/pack" ;
76
-
77
- Repository orgRepo = new Repository ( orgRepoPath ) ;
78
-
79
- // pack using the custom build method
80
- PackBuilderResults results = orgRepo . ObjectDatabase . Pack ( packBuilderOptions , TestBuildDelegate ) ;
81
-
82
- // written objects count is the same as in objects database
83
- Assert . Equal ( results . WrittenObjectsCount , orgRepo . ObjectDatabase . Count ( ) ) ;
84
-
85
- // loading a repo from the written pack file.
86
- Repository mrrRepo = new Repository ( mrrRepoPath ) ;
87
-
88
- // make sure the objects of the original repo are the same as the ones in the mirror repo
89
- // doing that by making sure the count is the same, and the set differnce is empty
90
- Assert . True ( mrrRepo . ObjectDatabase . Count ( ) == orgRepo . ObjectDatabase . Count ( ) && ! mrrRepo . ObjectDatabase . Except ( orgRepo . ObjectDatabase ) . Any ( ) ) ;
91
-
92
- Assert . Equal ( orgRepo . Commits . Count ( ) , mrrRepo . Commits . Count ( ) ) ;
93
- Assert . Equal ( orgRepo . Branches . Count ( ) , mrrRepo . Branches . Count ( ) ) ;
94
- Assert . Equal ( orgRepo . Refs . Count ( ) , mrrRepo . Refs . Count ( ) ) ;
95
-
96
- orgRepo . Dispose ( ) ;
97
- mrrRepo . Dispose ( ) ;
98
- }
99
-
100
- internal void TestBuildDelegate ( PackBuilder builder )
67
+ internal void TestBuildDelegate ( PackBuilder builder )
101
68
{
102
- foreach ( Branch branch in builder . Repository . Branches )
69
+ foreach ( Branch branch in builder . Repository . Branches )
103
70
{
104
71
foreach ( Commit commit in branch . Commits )
105
72
{
106
- builder . AddRecursively ( commit ) ;
73
+ builder . AddRecursively ( commit . Id ) ;
107
74
}
108
75
}
109
76
}
0 commit comments