@@ -21,14 +21,24 @@ public ExecuteCore(IFileSystem fileSystem)
2121
2222 public VersionVariables ExecuteGitVersion ( string targetUrl , string dynamicRepositoryLocation , Authentication authentication , string targetBranch , bool noFetch , string workingDirectory , string commitId )
2323 {
24- var gitDir = Repository . Discover ( workingDirectory ) ;
25- using ( var repo = GetRepository ( gitDir ) )
24+ // Normalise if we are running on build server
25+ var gitPreparer = new GitPreparer ( targetUrl , dynamicRepositoryLocation , authentication , noFetch , workingDirectory ) ;
26+ var dotGitDirectory = gitPreparer . GetDotGitDirectory ( ) ;
27+ var projectRoot = gitPreparer . GetProjectRootDirectory ( ) ;
28+ Logger . WriteInfo ( string . Format ( "Project root is: " + projectRoot ) ) ;
29+ if ( string . IsNullOrEmpty ( dotGitDirectory ) || string . IsNullOrEmpty ( projectRoot ) )
30+ {
31+ // TODO Link to wiki article
32+ throw new Exception ( string . Format ( "Failed to prepare or find the .git directory in path '{0}'." , workingDirectory ) ) ;
33+ }
34+
35+ using ( var repo = GetRepository ( dotGitDirectory ) )
2636 {
27- var versionVariables = gitVersionCache . LoadVersionVariablesFromDiskCache ( repo , gitDir ) ;
37+ var versionVariables = gitVersionCache . LoadVersionVariablesFromDiskCache ( repo , dotGitDirectory ) ;
2838 if ( versionVariables == null )
2939 {
30- versionVariables = ExecuteInternal ( targetUrl , dynamicRepositoryLocation , authentication , targetBranch , noFetch , workingDirectory , commitId , repo ) ;
31- gitVersionCache . WriteVariablesToDiskCache ( repo , gitDir , versionVariables ) ;
40+ versionVariables = ExecuteInternal ( targetBranch , commitId , repo , gitPreparer , projectRoot ) ;
41+ gitVersionCache . WriteVariablesToDiskCache ( repo , dotGitDirectory , versionVariables ) ;
3242 }
3343
3444 return versionVariables ;
@@ -63,23 +73,13 @@ static string ResolveCurrentBranch(IBuildServer buildServer, string targetBranch
6373 return currentBranch ;
6474 }
6575
66- VersionVariables ExecuteInternal ( string targetUrl , string dynamicRepositoryLocation , Authentication authentication , string targetBranch , bool noFetch , string workingDirectory , string commitId , IRepository repo )
76+ VersionVariables ExecuteInternal ( string targetBranch , string commitId , IRepository repo , GitPreparer gitPreparer , string projectRoot )
6777 {
68- // Normalise if we are running on build server
69- var gitPreparer = new GitPreparer ( targetUrl , dynamicRepositoryLocation , authentication , noFetch , workingDirectory ) ;
7078 var applicableBuildServers = BuildServerList . GetApplicableBuildServers ( ) ;
7179 var buildServer = applicableBuildServers . FirstOrDefault ( ) ;
7280
7381 gitPreparer . Initialise ( buildServer != null , ResolveCurrentBranch ( buildServer , targetBranch ) ) ;
7482
75- var dotGitDirectory = gitPreparer . GetDotGitDirectory ( ) ;
76- var projectRoot = gitPreparer . GetProjectRootDirectory ( ) ;
77- Logger . WriteInfo ( string . Format ( "Project root is: " + projectRoot ) ) ;
78- if ( string . IsNullOrEmpty ( dotGitDirectory ) || string . IsNullOrEmpty ( projectRoot ) )
79- {
80- // TODO Link to wiki article
81- throw new Exception ( string . Format ( "Failed to prepare or find the .git directory in path '{0}'." , workingDirectory ) ) ;
82- }
8383 var versionFinder = new GitVersionFinder ( ) ;
8484 var configuration = ConfigurationProvider . Provide ( projectRoot , fileSystem ) ;
8585
0 commit comments