@@ -299,7 +299,7 @@ public void WorkingDirectoryWithoutGit()
299
299
[ Test ]
300
300
[ Category ( "NoMono" ) ]
301
301
[ Description ( "LibGit2Sharp fails when running under Mono" ) ]
302
- public void WorkingDirectoryWithWorktree ( )
302
+ public void GetProjectRootDirectory_WorkingDirectoryWithWorktree ( )
303
303
{
304
304
var versionAndBranchFinder = new ExecuteCore ( fileSystem ) ;
305
305
@@ -323,6 +323,20 @@ public void WorkingDirectoryWithWorktree()
323
323
} ) ;
324
324
}
325
325
326
+ [ Test ]
327
+ public void GetProjectRootDirectory_NoWorktree ( )
328
+ {
329
+ var versionAndBranchFinder = new ExecuteCore ( fileSystem ) ;
330
+
331
+ RepositoryScope ( versionAndBranchFinder , ( fixture , vv ) =>
332
+ {
333
+ var targetUrl = "https://github.com/GitTools/GitVersion.git" ;
334
+ var gitPreparer = new GitPreparer ( targetUrl , null , new Authentication ( ) , false , fixture . RepositoryPath ) ;
335
+ var expectedPath = fixture . RepositoryPath . TrimEnd ( '/' , '\\ ' ) ;
336
+ gitPreparer . GetProjectRootDirectory ( ) . TrimEnd ( '/' , '\\ ' ) . ShouldBe ( expectedPath ) ;
337
+ } ) ;
338
+ }
339
+
326
340
[ Test ]
327
341
public void DynamicRepositoriesShouldNotErrorWithFailedToFindGitDirectory ( )
328
342
{
@@ -334,6 +348,48 @@ public void DynamicRepositoriesShouldNotErrorWithFailedToFindGitDirectory()
334
348
} ) ;
335
349
}
336
350
351
+ [ Test ]
352
+ public void GetDotGitDirectory_NoWorktree ( )
353
+ {
354
+ var versionAndBranchFinder = new ExecuteCore ( fileSystem ) ;
355
+
356
+ RepositoryScope ( versionAndBranchFinder , ( fixture , vv ) =>
357
+ {
358
+ var targetUrl = "https://github.com/GitTools/GitVersion.git" ;
359
+ var gitPreparer = new GitPreparer ( targetUrl , null , new Authentication ( ) , false , fixture . RepositoryPath ) ;
360
+ var expectedPath = Path . Combine ( fixture . RepositoryPath , ".git" ) ;
361
+ gitPreparer . GetDotGitDirectory ( ) . ShouldBe ( expectedPath ) ;
362
+ } ) ;
363
+ }
364
+
365
+ [ Test ]
366
+ [ Category ( "NoMono" ) ]
367
+ [ Description ( "LibGit2Sharp fails when running under Mono" ) ]
368
+ public void GetDotGitDirectory_Worktree ( )
369
+ {
370
+ var versionAndBranchFinder = new ExecuteCore ( fileSystem ) ;
371
+
372
+ RepositoryScope ( versionAndBranchFinder , ( fixture , vv ) =>
373
+ {
374
+ var worktreePath = Path . Combine ( Directory . GetParent ( fixture . RepositoryPath ) . FullName , Guid . NewGuid ( ) . ToString ( ) ) ;
375
+ try
376
+ {
377
+ // create a branch and a new worktree for it
378
+ var repo = new Repository ( fixture . RepositoryPath ) ;
379
+ repo . Worktrees . Add ( "worktree" , worktreePath , false ) ;
380
+
381
+ var targetUrl = "https://github.com/GitTools/GitVersion.git" ;
382
+ var gitPreparer = new GitPreparer ( targetUrl , null , new Authentication ( ) , false , worktreePath ) ;
383
+ var expectedPath = Path . Combine ( fixture . RepositoryPath , ".git" ) ;
384
+ gitPreparer . GetDotGitDirectory ( ) . ShouldBe ( expectedPath ) ;
385
+ }
386
+ finally
387
+ {
388
+ DirectoryHelper . DeleteDirectory ( worktreePath ) ;
389
+ }
390
+ } ) ;
391
+ }
392
+
337
393
LogMessages RepositoryScope ( ExecuteCore executeCore = null , Action < EmptyRepositoryFixture , VersionVariables > fixtureAction = null )
338
394
{
339
395
// Make sure GitVersion doesn't trigger build server mode when we are running the tests
0 commit comments