77using System ;
88using System . IO ;
99using System . Text ;
10+ using LibGit2Sharp ;
1011
1112[ TestFixture ]
1213[ Parallelizable ( ParallelScope . None ) ]
@@ -40,6 +41,35 @@ public void CacheKeySameAfterReNormalizing()
4041 } ) ;
4142 }
4243
44+ [ Test ]
45+ [ Category ( "NoMono" ) ]
46+ [ Description ( "LibGit2Sharp fails here when running under Mono" ) ]
47+ public void CacheKeyForWorktree ( )
48+ {
49+ var versionAndBranchFinder = new ExecuteCore ( fileSystem ) ;
50+
51+ RepositoryScope ( versionAndBranchFinder , ( fixture , vv ) =>
52+ {
53+ var worktreePath = Path . Combine ( Directory . GetParent ( fixture . RepositoryPath ) . FullName , Guid . NewGuid ( ) . ToString ( ) ) ;
54+ try
55+ {
56+ // create a branch and a new worktree for it
57+ var repo = new Repository ( fixture . RepositoryPath ) ;
58+ repo . Worktrees . Add ( "worktree" , worktreePath , false ) ;
59+
60+ var targetUrl = "https://github.com/GitTools/GitVersion.git" ;
61+ var gitPreparer = new GitPreparer ( targetUrl , null , new Authentication ( ) , false , worktreePath ) ;
62+ var configFileLocator = new DefaultConfigFileLocator ( ) ;
63+ var cacheKey = GitVersionCacheKeyFactory . Create ( fileSystem , gitPreparer , null , configFileLocator ) ;
64+ cacheKey . Value . ShouldNotBeEmpty ( ) ;
65+ }
66+ finally
67+ {
68+ DirectoryHelper . DeleteDirectory ( worktreePath ) ;
69+ }
70+ } ) ;
71+ }
72+
4373 [ Test ]
4474 public void CacheFileExistsOnDisk ( )
4575 {
@@ -266,6 +296,47 @@ public void WorkingDirectoryWithoutGit()
266296 } ) ;
267297 }
268298
299+ [ Test ]
300+ [ Category ( "NoMono" ) ]
301+ [ Description ( "LibGit2Sharp fails when running under Mono" ) ]
302+ public void GetProjectRootDirectory_WorkingDirectoryWithWorktree ( )
303+ {
304+ var versionAndBranchFinder = new ExecuteCore ( fileSystem ) ;
305+
306+ RepositoryScope ( versionAndBranchFinder , ( fixture , vv ) =>
307+ {
308+ var worktreePath = Path . Combine ( Directory . GetParent ( fixture . RepositoryPath ) . FullName , Guid . NewGuid ( ) . ToString ( ) ) ;
309+ try
310+ {
311+ // create a branch and a new worktree for it
312+ var repo = new Repository ( fixture . RepositoryPath ) ;
313+ repo . Worktrees . Add ( "worktree" , worktreePath , false ) ;
314+
315+ var targetUrl = "https://github.com/GitTools/GitVersion.git" ;
316+ var gitPreparer = new GitPreparer ( targetUrl , null , new Authentication ( ) , false , worktreePath ) ;
317+ gitPreparer . GetProjectRootDirectory ( ) . TrimEnd ( '/' , '\\ ' ) . ShouldBe ( worktreePath ) ;
318+ }
319+ finally
320+ {
321+ DirectoryHelper . DeleteDirectory ( worktreePath ) ;
322+ }
323+ } ) ;
324+ }
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+
269340 [ Test ]
270341 public void DynamicRepositoriesShouldNotErrorWithFailedToFindGitDirectory ( )
271342 {
@@ -277,6 +348,48 @@ public void DynamicRepositoriesShouldNotErrorWithFailedToFindGitDirectory()
277348 } ) ;
278349 }
279350
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+
280393 LogMessages RepositoryScope ( ExecuteCore executeCore = null , Action < EmptyRepositoryFixture , VersionVariables > fixtureAction = null )
281394 {
282395 // Make sure GitVersion doesn't trigger build server mode when we are running the tests
0 commit comments