@@ -21,14 +21,24 @@ public ExecuteCore(IFileSystem fileSystem)
21
21
22
22
public VersionVariables ExecuteGitVersion ( string targetUrl , string dynamicRepositoryLocation , Authentication authentication , string targetBranch , bool noFetch , string workingDirectory , string commitId )
23
23
{
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 ) )
26
36
{
27
- var versionVariables = gitVersionCache . LoadVersionVariablesFromDiskCache ( repo , gitDir ) ;
37
+ var versionVariables = gitVersionCache . LoadVersionVariablesFromDiskCache ( repo , dotGitDirectory ) ;
28
38
if ( versionVariables == null )
29
39
{
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 ) ;
32
42
}
33
43
34
44
return versionVariables ;
@@ -63,23 +73,13 @@ static string ResolveCurrentBranch(IBuildServer buildServer, string targetBranch
63
73
return currentBranch ;
64
74
}
65
75
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 )
67
77
{
68
- // Normalise if we are running on build server
69
- var gitPreparer = new GitPreparer ( targetUrl , dynamicRepositoryLocation , authentication , noFetch , workingDirectory ) ;
70
78
var applicableBuildServers = BuildServerList . GetApplicableBuildServers ( ) ;
71
79
var buildServer = applicableBuildServers . FirstOrDefault ( ) ;
72
80
73
81
gitPreparer . Initialise ( buildServer != null , ResolveCurrentBranch ( buildServer , targetBranch ) ) ;
74
82
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
- }
83
83
var versionFinder = new GitVersionFinder ( ) ;
84
84
var configuration = ConfigurationProvider . Provide ( projectRoot , fileSystem ) ;
85
85
0 commit comments