88using GitVersion . Configuration ;
99using GitVersion . Logging ;
1010using GitVersion . Model . Configuration ;
11- using LibGit2Sharp ;
1211using Microsoft . Extensions . Options ;
1312
1413namespace GitVersion . VersionCalculation . Cache
@@ -19,13 +18,17 @@ public class GitVersionCacheKeyFactory : IGitVersionCacheKeyFactory
1918 private readonly ILog log ;
2019 private readonly IOptions < GitVersionOptions > options ;
2120 private readonly IConfigFileLocator configFileLocator ;
21+ private readonly IGitRepository gitRepository ;
2222
23- public GitVersionCacheKeyFactory ( IFileSystem fileSystem , ILog log , IOptions < GitVersionOptions > options , IConfigFileLocator configFileLocator )
23+ public GitVersionCacheKeyFactory ( IFileSystem fileSystem , ILog log ,
24+ IOptions < GitVersionOptions > options , IConfigFileLocator configFileLocator ,
25+ IGitRepository gitRepository )
2426 {
2527 this . fileSystem = fileSystem ?? throw new ArgumentNullException ( nameof ( fileSystem ) ) ;
2628 this . log = log ?? throw new ArgumentNullException ( nameof ( log ) ) ;
2729 this . options = options ?? throw new ArgumentNullException ( nameof ( options ) ) ;
2830 this . configFileLocator = configFileLocator ?? throw new ArgumentNullException ( nameof ( configFileLocator ) ) ;
31+ this . gitRepository = gitRepository ?? throw new ArgumentNullException ( nameof ( gitRepository ) ) ;
2932 }
3033
3134 public GitVersionCacheKey Create ( Config overrideConfig )
@@ -141,9 +144,7 @@ private List<string> CalculateDirectoryContents(string root)
141144
142145 private string GetRepositorySnapshotHash ( )
143146 {
144- using var repo = new Repository ( options . Value . GitRootPath ) ;
145-
146- var head = repo . Head ;
147+ var head = gitRepository . Head ;
147148 if ( head . Tip == null )
148149 {
149150 return head . CanonicalName ;
0 commit comments