@@ -41,10 +41,10 @@ public void LibGit2_GetConfiguration_ReturnsConfiguration()
41
41
[ Fact ]
42
42
public void LibGit2Configuration_Enumerate_CallbackReturnsTrue_InvokesCallbackForEachEntry ( )
43
43
{
44
- string repoPath = CreateRepository ( ) ;
45
- Git ( repoPath , "config --local foo.name lancelot" ) . AssertSuccess ( ) ;
46
- Git ( repoPath , "config --local foo.quest seek-holy-grail" ) . AssertSuccess ( ) ;
47
- Git ( repoPath , "config --local foo.favcolor blue" ) . AssertSuccess ( ) ;
44
+ string repoPath = CreateRepository ( out string workDirPath ) ;
45
+ Git ( repoPath , workDirPath , "config --local foo.name lancelot" ) . AssertSuccess ( ) ;
46
+ Git ( repoPath , workDirPath , "config --local foo.quest seek-holy-grail" ) . AssertSuccess ( ) ;
47
+ Git ( repoPath , workDirPath , "config --local foo.favcolor blue" ) . AssertSuccess ( ) ;
48
48
49
49
var expectedVisitedEntries = new List < ( string name , string value ) >
50
50
{
@@ -79,10 +79,10 @@ bool cb(string name, string value)
79
79
[ Fact ]
80
80
public void LibGit2Configuration_Enumerate_CallbackReturnsFalse_InvokesCallbackForEachEntryUntilReturnsFalse ( )
81
81
{
82
- string repoPath = CreateRepository ( ) ;
83
- Git ( repoPath , "config --local foo.name lancelot" ) . AssertSuccess ( ) ;
84
- Git ( repoPath , "config --local foo.quest seek-holy-grail" ) . AssertSuccess ( ) ;
85
- Git ( repoPath , "config --local foo.favcolor blue" ) . AssertSuccess ( ) ;
82
+ string repoPath = CreateRepository ( out string workDirPath ) ;
83
+ Git ( repoPath , workDirPath , "config --local foo.name lancelot" ) . AssertSuccess ( ) ;
84
+ Git ( repoPath , workDirPath , "config --local foo.quest seek-holy-grail" ) . AssertSuccess ( ) ;
85
+ Git ( repoPath , workDirPath , "config --local foo.favcolor blue" ) . AssertSuccess ( ) ;
86
86
87
87
var expectedVisitedEntries = new List < ( string name , string value ) >
88
88
{
@@ -116,8 +116,8 @@ bool cb(string name, string value)
116
116
[ Fact ]
117
117
public void LibGit2Configuration_TryGetValue_Name_Exists_ReturnsTrueOutString ( )
118
118
{
119
- string repoPath = CreateRepository ( ) ;
120
- Git ( repoPath , "config --local user.name john.doe" ) . AssertSuccess ( ) ;
119
+ string repoPath = CreateRepository ( out string workDirPath ) ;
120
+ Git ( repoPath , workDirPath , "config --local user.name john.doe" ) . AssertSuccess ( ) ;
121
121
122
122
var trace = new NullTrace ( ) ;
123
123
var git = new LibGit2 ( trace ) ;
@@ -149,8 +149,8 @@ public void LibGit2Configuration_TryGetValue_Name_DoesNotExists_ReturnsFalse()
149
149
[ Fact ]
150
150
public void LibGit2Configuration_TryGetValue_SectionProperty_Exists_ReturnsTrueOutString ( )
151
151
{
152
- string repoPath = CreateRepository ( ) ;
153
- Git ( repoPath , "config --local user.name john.doe" ) . AssertSuccess ( ) ;
152
+ string repoPath = CreateRepository ( out string workDirPath ) ;
153
+ Git ( repoPath , workDirPath , "config --local user.name john.doe" ) . AssertSuccess ( ) ;
154
154
155
155
var trace = new NullTrace ( ) ;
156
156
var git = new LibGit2 ( trace ) ;
@@ -183,8 +183,8 @@ public void LibGit2Configuration_TryGetValue_SectionProperty_DoesNotExists_Retur
183
183
[ Fact ]
184
184
public void LibGit2Configuration_TryGetValue_SectionScopeProperty_Exists_ReturnsTrueOutString ( )
185
185
{
186
- string repoPath = CreateRepository ( ) ;
187
- Git ( repoPath , "config --local user.example.com.name john.doe" ) . AssertSuccess ( ) ;
186
+ string repoPath = CreateRepository ( out string workDirPath ) ;
187
+ Git ( repoPath , workDirPath , "config --local user.example.com.name john.doe" ) . AssertSuccess ( ) ;
188
188
189
189
var trace = new NullTrace ( ) ;
190
190
var git = new LibGit2 ( trace ) ;
@@ -200,8 +200,8 @@ public void LibGit2Configuration_TryGetValue_SectionScopeProperty_Exists_Returns
200
200
[ Fact ]
201
201
public void LibGit2Configuration_TryGetValue_SectionScopeProperty_NullScope_ReturnsTrueOutUnscopedString ( )
202
202
{
203
- string repoPath = CreateRepository ( ) ;
204
- Git ( repoPath , "config --local user.name john.doe" ) . AssertSuccess ( ) ;
203
+ string repoPath = CreateRepository ( out string workDirPath ) ;
204
+ Git ( repoPath , workDirPath , "config --local user.name john.doe" ) . AssertSuccess ( ) ;
205
205
206
206
var trace = new NullTrace ( ) ;
207
207
var git = new LibGit2 ( trace ) ;
@@ -235,8 +235,8 @@ public void LibGit2Configuration_TryGetValue_SectionScopeProperty_DoesNotExists_
235
235
[ Fact ]
236
236
public void LibGit2Configuration_GetString_Name_Exists_ReturnsString ( )
237
237
{
238
- string repoPath = CreateRepository ( ) ;
239
- Git ( repoPath , "config --local user.name john.doe" ) . AssertSuccess ( ) ;
238
+ string repoPath = CreateRepository ( out string workDirPath ) ;
239
+ Git ( repoPath , workDirPath , "config --local user.name john.doe" ) . AssertSuccess ( ) ;
240
240
241
241
var trace = new NullTrace ( ) ;
242
242
var git = new LibGit2 ( trace ) ;
@@ -265,8 +265,8 @@ public void LibGit2Configuration_GetString_Name_DoesNotExists_ThrowsException()
265
265
[ Fact ]
266
266
public void LibGit2Configuration_GetString_SectionProperty_Exists_ReturnsString ( )
267
267
{
268
- string repoPath = CreateRepository ( ) ;
269
- Git ( repoPath , "config --local user.name john.doe" ) . AssertSuccess ( ) ;
268
+ string repoPath = CreateRepository ( out string workDirPath ) ;
269
+ Git ( repoPath , workDirPath , "config --local user.name john.doe" ) . AssertSuccess ( ) ;
270
270
271
271
var trace = new NullTrace ( ) ;
272
272
var git = new LibGit2 ( trace ) ;
@@ -296,8 +296,8 @@ public void LibGit2Configuration_GetString_SectionProperty_DoesNotExists_ThrowsE
296
296
[ Fact ]
297
297
public void LibGit2Configuration_GetString_SectionScopeProperty_Exists_ReturnsString ( )
298
298
{
299
- string repoPath = CreateRepository ( ) ;
300
- Git ( repoPath , "config --local user.example.com.name john.doe" ) . AssertSuccess ( ) ;
299
+ string repoPath = CreateRepository ( out string workDirPath ) ;
300
+ Git ( repoPath , workDirPath , "config --local user.example.com.name john.doe" ) . AssertSuccess ( ) ;
301
301
302
302
var trace = new NullTrace ( ) ;
303
303
var git = new LibGit2 ( trace ) ;
@@ -312,8 +312,8 @@ public void LibGit2Configuration_GetString_SectionScopeProperty_Exists_ReturnsSt
312
312
[ Fact ]
313
313
public void LibGit2Configuration_GetString_SectionScopeProperty_NullScope_ReturnsUnscopedString ( )
314
314
{
315
- string repoPath = CreateRepository ( ) ;
316
- Git ( repoPath , "config --local user.name john.doe" ) . AssertSuccess ( ) ;
315
+ string repoPath = CreateRepository ( out string workDirPath ) ;
316
+ Git ( repoPath , workDirPath , "config --local user.name john.doe" ) . AssertSuccess ( ) ;
317
317
318
318
var trace = new NullTrace ( ) ;
319
319
var git = new LibGit2 ( trace ) ;
@@ -344,10 +344,9 @@ public void LibGit2Configuration_GetString_SectionScopeProperty_DoesNotExists_Th
344
344
[ Fact ]
345
345
public void LibGit2Configuration_GetRepositoryPath_ReturnsRepositoryPath ( )
346
346
{
347
- string repoBasePath = CreateRepository ( ) ;
348
- string expectedRepoGitPath = Path . Combine ( repoBasePath , ".git" ) + "/" ;
349
- string fileL0Path = Path . Combine ( repoBasePath , "file.txt" ) ;
350
- string directoryL0Path = Path . Combine ( repoBasePath , "directory" ) ;
347
+ string expectedRepoGitPath = CreateRepository ( out string workDirPath ) + "/" ;
348
+ string fileL0Path = Path . Combine ( workDirPath , "file.txt" ) ;
349
+ string directoryL0Path = Path . Combine ( workDirPath , "directory" ) ;
351
350
string fileL1Path = Path . Combine ( directoryL0Path , "inner-file.txt" ) ;
352
351
string directoryL1Path = Path . Combine ( directoryL0Path , "sub-directory" ) ;
353
352
@@ -425,34 +424,55 @@ private static string RealPath(string path)
425
424
throw new PlatformNotSupportedException ( ) ;
426
425
}
427
426
428
- private static string CreateRepository ( )
427
+ private static string CreateBareRepository ( )
428
+ {
429
+ string tempDirectory = Path . GetTempPath ( ) ;
430
+ string repoName = $ "repo-{ Guid . NewGuid ( ) . ToString ( "N" ) . Substring ( 0 , 8 ) } ";
431
+ var gitDirPath = Path . Combine ( tempDirectory , repoName ) ;
432
+
433
+ if ( Directory . Exists ( gitDirPath ) )
434
+ {
435
+ Directory . Delete ( gitDirPath ) ;
436
+ }
437
+
438
+ Directory . CreateDirectory ( gitDirPath ) ;
439
+
440
+ Git ( gitDirPath , gitDirPath , "init --bare" ) . AssertSuccess ( ) ;
441
+
442
+ return gitDirPath ;
443
+ }
444
+
445
+ private static string CreateRepository ( ) => CreateRepository ( out _ ) ;
446
+
447
+ private static string CreateRepository ( out string workDirPath )
429
448
{
430
449
string tempDirectory = Path . GetTempPath ( ) ;
431
450
string repoName = $ "repo-{ Guid . NewGuid ( ) . ToString ( "N" ) . Substring ( 0 , 8 ) } ";
432
- string repoPath = Path . Combine ( tempDirectory , repoName ) ;
451
+ workDirPath = Path . Combine ( tempDirectory , repoName ) ;
452
+ string gitDirPath = Path . Combine ( workDirPath , ".git" ) ;
433
453
434
- if ( Directory . Exists ( repoPath ) )
454
+ if ( Directory . Exists ( workDirPath ) )
435
455
{
436
- Directory . Delete ( repoPath ) ;
456
+ Directory . Delete ( workDirPath ) ;
437
457
}
438
458
439
- Directory . CreateDirectory ( repoPath ) ;
459
+ Directory . CreateDirectory ( workDirPath ) ;
440
460
441
- Git ( repoPath , "init" ) . AssertSuccess ( ) ;
461
+ Git ( gitDirPath , workDirPath , "init" ) . AssertSuccess ( ) ;
442
462
443
- return repoPath ;
463
+ return gitDirPath ;
444
464
}
445
465
446
- private static GitResult Git ( string repositoryPath , string command )
466
+ private static GitResult Git ( string repositoryPath , string workingDirectory , string command )
447
467
{
448
468
var procInfo = new ProcessStartInfo ( "git" , command )
449
469
{
450
470
RedirectStandardOutput = true ,
451
471
RedirectStandardError = true ,
472
+ WorkingDirectory = workingDirectory
452
473
} ;
453
474
454
- string gitDirectory = Path . Combine ( repositoryPath , ".git" ) ;
455
- procInfo . Environment [ "GIT_DIR" ] = gitDirectory ;
475
+ procInfo . Environment [ "GIT_DIR" ] = repositoryPath ;
456
476
457
477
Process proc = Process . Start ( procInfo ) ;
458
478
if ( proc is null )
0 commit comments