55using System . Security . Cryptography ;
66using System . Text ;
77using GitVersion . Configuration ;
8+ using GitVersion . Extensions ;
89using GitVersion . Logging ;
910using LibGit2Sharp ;
11+ using Microsoft . Extensions . Options ;
1012
1113namespace GitVersion . Cache
1214{
@@ -19,15 +21,15 @@ public class GitVersionCacheKeyFactory : IGitVersionCacheKeyFactory
1921 {
2022 private readonly IFileSystem fileSystem ;
2123 private readonly ILog log ;
22- private readonly IGitPreparer gitPreparer ;
24+ private readonly IOptions < Arguments > options ;
2325 private readonly IConfigFileLocator configFileLocator ;
2426
25- public GitVersionCacheKeyFactory ( IFileSystem fileSystem , ILog log , IGitPreparer gitPreparer , IConfigFileLocator configFileLocator )
27+ public GitVersionCacheKeyFactory ( IFileSystem fileSystem , ILog log , IOptions < Arguments > options , IConfigFileLocator configFileLocator )
2628 {
27- this . fileSystem = fileSystem ;
28- this . log = log ;
29- this . gitPreparer = gitPreparer ;
30- this . configFileLocator = configFileLocator ;
29+ this . fileSystem = fileSystem ?? throw new ArgumentNullException ( nameof ( fileSystem ) ) ;
30+ this . log = log ?? throw new ArgumentNullException ( nameof ( log ) ) ;
31+ this . options = options ?? throw new ArgumentNullException ( nameof ( options ) ) ;
32+ this . configFileLocator = configFileLocator ?? throw new ArgumentNullException ( nameof ( configFileLocator ) ) ;
3133 }
3234
3335 public GitVersionCacheKey Create ( Config overrideConfig )
@@ -43,7 +45,7 @@ public GitVersionCacheKey Create(Config overrideConfig)
4345
4446 private string GetGitSystemHash ( )
4547 {
46- var dotGitDirectory = gitPreparer . GetDotGitDirectory ( ) ;
48+ var dotGitDirectory = options . Value . GetDotGitDirectory ( ) ;
4749
4850 // traverse the directory and get a list of files, use that for GetHash
4951 var contents = CalculateDirectoryContents ( Path . Combine ( dotGitDirectory , "refs" ) ) ;
@@ -80,13 +82,13 @@ private List<string> CalculateDirectoryContents(string root)
8082 subDirs = Directory . GetDirectories ( currentDir ) ;
8183 }
8284 // An UnauthorizedAccessException exception will be thrown if we do not have
83- // discovery permission on a folder or file. It may or may not be acceptable
84- // to ignore the exception and continue enumerating the remaining files and
85- // folders. It is also possible (but unlikely) that a DirectoryNotFound exception
85+ // discovery permission on a folder or file. It may or may not be acceptable
86+ // to ignore the exception and continue enumerating the remaining files and
87+ // folders. It is also possible (but unlikely) that a DirectoryNotFound exception
8688 // will be raised. This will happen if currentDir has been deleted by
87- // another application or thread after our call to Directory.Exists. The
88- // choice of which exceptions to catch depends entirely on the specific task
89- // you are intending to perform and also on how much you know with certainty
89+ // another application or thread after our call to Directory.Exists. The
90+ // choice of which exceptions to catch depends entirely on the specific task
91+ // you are intending to perform and also on how much you know with certainty
9092 // about the systems on which this code will run.
9193 catch ( UnauthorizedAccessException e )
9294 {
@@ -143,7 +145,7 @@ private List<string> CalculateDirectoryContents(string root)
143145
144146 private string GetRepositorySnapshotHash ( )
145147 {
146- using var repo = new Repository ( gitPreparer . GetDotGitDirectory ( ) ) ;
148+ using var repo = new Repository ( options . Value . GetDotGitDirectory ( ) ) ;
147149
148150 var head = repo . Head ;
149151 if ( head . Tip == null )
@@ -161,7 +163,7 @@ private static string GetOverrideConfigHash(Config overrideConfig)
161163 return string . Empty ;
162164 }
163165
164- // Doesn't depend on command line representation and
166+ // Doesn't depend on command line representation and
165167 // includes possible changes in default values of Config per se.
166168 var stringBuilder = new StringBuilder ( ) ;
167169 using ( var stream = new StringWriter ( stringBuilder ) )
@@ -176,9 +178,9 @@ private static string GetOverrideConfigHash(Config overrideConfig)
176178
177179 private string GetConfigFileHash ( )
178180 {
179- // will return the same hash even when config file will be moved
181+ // will return the same hash even when config file will be moved
180182 // from workingDirectory to rootProjectDirectory. It's OK. Config essentially is the same.
181- var configFilePath = configFileLocator . SelectConfigFilePath ( gitPreparer ) ;
183+ var configFilePath = configFileLocator . SelectConfigFilePath ( options . Value ) ;
182184 if ( ! fileSystem . Exists ( configFilePath ) )
183185 {
184186 return string . Empty ;
0 commit comments