@@ -299,7 +299,7 @@ public void WorkingDirectoryWithoutGit()
299299 [ Test ]
300300 [ Category ( "NoMono" ) ]
301301 [ Description ( "LibGit2Sharp fails when running under Mono" ) ]
302- public void WorkingDirectoryWithWorktree ( )
302+ public void GetProjectRootDirectory_WorkingDirectoryWithWorktree ( )
303303 {
304304 var versionAndBranchFinder = new ExecuteCore ( fileSystem ) ;
305305
@@ -323,6 +323,20 @@ public void WorkingDirectoryWithWorktree()
323323 } ) ;
324324 }
325325
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+
326340 [ Test ]
327341 public void DynamicRepositoriesShouldNotErrorWithFailedToFindGitDirectory ( )
328342 {
@@ -334,6 +348,48 @@ public void DynamicRepositoriesShouldNotErrorWithFailedToFindGitDirectory()
334348 } ) ;
335349 }
336350
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+
337393 LogMessages RepositoryScope ( ExecuteCore executeCore = null , Action < EmptyRepositoryFixture , VersionVariables > fixtureAction = null )
338394 {
339395 // Make sure GitVersion doesn't trigger build server mode when we are running the tests
0 commit comments