public VersionVariables ExecuteGitVersion(string targetUrl, string dynamicRepositoryLocation, Authentication authentication, string targetBranch, bool noFetch, string workingDirectory, string commitId) { // Normalise if we are running on build server var applicableBuildServers = BuildServerList.GetApplicableBuildServers(); var buildServer = applicableBuildServers.FirstOrDefault(); var fetch = noFetch || (buildServer != null && buildServer.PreventFetch()); var gitPreparer = new GitPreparer(targetUrl, dynamicRepositoryLocation, authentication, fetch, workingDirectory); var dotGitDirectory = gitPreparer.GetDotGitDirectory(); var projectRoot = gitPreparer.GetProjectRootDirectory(); Logger.WriteInfo(string.Format("Project root is: " + projectRoot)); if (string.IsNullOrEmpty(dotGitDirectory) || string.IsNullOrEmpty(projectRoot)) { // TODO Link to wiki article throw new Exception(string.Format("Failed to prepare or find the .git directory in path '{0}'.", workingDirectory)); } using (var repo = GetRepository(dotGitDirectory)) { var versionVariables = gitVersionCache.LoadVersionVariablesFromDiskCache(repo, dotGitDirectory); if (versionVariables == null) { versionVariables = ExecuteInternal(targetBranch, commitId, repo, gitPreparer, projectRoot, buildServer); gitVersionCache.WriteVariablesToDiskCache(repo, dotGitDirectory, versionVariables); } return(versionVariables); } }
public VersionVariables ExecuteGitVersion(string targetUrl, string dynamicRepositoryLocation, Authentication authentication, string targetBranch, bool noFetch, string workingDirectory, string commitId, Config overrideConfig = null, bool noCache = false, bool noNormalize = false) { BuildServerList.Init(environment, log); // Normalize if we are running on build server var applicableBuildServers = BuildServerList.GetApplicableBuildServers(log); var buildServer = applicableBuildServers.FirstOrDefault(); var normalizeGitDirectory = !noNormalize && buildServer != null; var fetch = noFetch || buildServer != null && buildServer.PreventFetch(); var shouldCleanUpRemotes = buildServer != null && buildServer.ShouldCleanUpRemotes(); var gitPreparer = new GitPreparer(log, targetUrl, dynamicRepositoryLocation, authentication, fetch, workingDirectory); gitPreparer.Initialise(normalizeGitDirectory, ResolveCurrentBranch(buildServer, targetBranch, !string.IsNullOrWhiteSpace(dynamicRepositoryLocation)), shouldCleanUpRemotes); var dotGitDirectory = gitPreparer.GetDotGitDirectory(); var projectRoot = gitPreparer.GetProjectRootDirectory(); // TODO Can't use this, it still needs work //var gitRepository = GitRepositoryFactory.CreateRepository(new RepositoryInfo //{ // Url = targetUrl, // Branch = targetBranch, // Authentication = new AuthenticationInfo // { // Username = authentication.Username, // Password = authentication.Password // }, // Directory = workingDirectory //}); log.Info($"Project root is: {projectRoot}"); log.Info($"DotGit directory is: {dotGitDirectory}"); if (string.IsNullOrEmpty(dotGitDirectory) || string.IsNullOrEmpty(projectRoot)) { // TODO Link to wiki article throw new Exception($"Failed to prepare or find the .git directory in path '{workingDirectory}'."); } var cacheKey = GitVersionCacheKeyFactory.Create(fileSystem, log, gitPreparer, overrideConfig, configFileLocator); var versionVariables = noCache ? default : gitVersionCache.LoadVersionVariablesFromDiskCache(gitPreparer, cacheKey); if (versionVariables == null) { versionVariables = ExecuteInternal(targetBranch, commitId, gitPreparer, overrideConfig); if (!noCache) { try { gitVersionCache.WriteVariablesToDiskCache(gitPreparer, cacheKey, versionVariables); } catch (AggregateException e) { log.Warning($"One or more exceptions during cache write:{Environment.NewLine}{e}"); } } } return(versionVariables); }
public VersionVariables ExecuteGitVersion(string targetUrl, string dynamicRepositoryLocation, Authentication authentication, string targetBranch, bool noFetch, string workingDirectory, string commitId, Config overrideConfig = null) { // Normalise if we are running on build server var applicableBuildServers = BuildServerList.GetApplicableBuildServers(); var buildServer = applicableBuildServers.FirstOrDefault(); var fetch = noFetch || (buildServer != null && buildServer.PreventFetch()); var gitPreparer = new GitPreparer(targetUrl, dynamicRepositoryLocation, authentication, fetch, workingDirectory); gitPreparer.Initialise(buildServer != null, ResolveCurrentBranch(buildServer, targetBranch, !string.IsNullOrWhiteSpace(dynamicRepositoryLocation))); var dotGitDirectory = gitPreparer.GetDotGitDirectory(); var projectRoot = gitPreparer.GetProjectRootDirectory(); // TODO Can't use this, it still needs work //var gitRepository = GitRepositoryFactory.CreateRepository(new RepositoryInfo //{ // Url = targetUrl, // Branch = targetBranch, // Authentication = new AuthenticationInfo // { // Username = authentication.Username, // Password = authentication.Password // }, // Directory = workingDirectory //}); Logger.WriteInfo(string.Format("Project root is: {0}", projectRoot)); Logger.WriteInfo(string.Format("DotGit directory is: {0}", dotGitDirectory)); if (string.IsNullOrEmpty(dotGitDirectory) || string.IsNullOrEmpty(projectRoot)) { // TODO Link to wiki article throw new Exception(string.Format("Failed to prepare or find the .git directory in path '{0}'.", workingDirectory)); } var cacheKey = GitVersionCacheKeyFactory.Create(fileSystem, gitPreparer, overrideConfig); var versionVariables = gitVersionCache.LoadVersionVariablesFromDiskCache(gitPreparer, cacheKey); if (versionVariables == null) { versionVariables = ExecuteInternal(targetBranch, commitId, gitPreparer, buildServer, overrideConfig); try { gitVersionCache.WriteVariablesToDiskCache(gitPreparer, cacheKey, versionVariables); } catch (AggregateException e) { Logger.WriteWarning(string.Format("One or more exceptions during cache write:{0}{1}", Environment.NewLine, e)); } } return(versionVariables); }
public VersionVariables ExecuteGitVersion(string targetUrl, string dynamicRepositoryLocation, Authentication authentication, string targetBranch, bool noFetch, string workingDirectory, string commitId, Config overrideConfig = null) { // Normalise if we are running on build server var applicableBuildServers = BuildServerList.GetApplicableBuildServers(); var buildServer = applicableBuildServers.FirstOrDefault(); var fetch = noFetch || (buildServer != null && buildServer.PreventFetch()); var gitPreparer = new GitPreparer(targetUrl, dynamicRepositoryLocation, authentication, fetch, workingDirectory); var dotGitDirectory = gitPreparer.GetDotGitDirectory(); var projectRoot = gitPreparer.GetProjectRootDirectory(); // TODO Can't use this, it still needs work //var gitRepository = GitRepositoryFactory.CreateRepository(new RepositoryInfo //{ // Url = targetUrl, // Branch = targetBranch, // Authentication = new AuthenticationInfo // { // Username = authentication.Username, // Password = authentication.Password // }, // Directory = workingDirectory //}); Logger.WriteInfo(string.Format("Project root is: " + projectRoot)); if (string.IsNullOrEmpty(dotGitDirectory) || string.IsNullOrEmpty(projectRoot)) { // TODO Link to wiki article throw new Exception(string.Format("Failed to prepare or find the .git directory in path '{0}'.", workingDirectory)); } using (var repo = GetRepository(dotGitDirectory)) { var versionVariables = gitVersionCache.LoadVersionVariablesFromDiskCache(repo, dotGitDirectory); if (versionVariables == null) { versionVariables = ExecuteInternal(targetBranch, commitId, repo, gitPreparer, projectRoot, buildServer, overrideConfig: overrideConfig); gitVersionCache.WriteVariablesToDiskCache(repo, dotGitDirectory, versionVariables); } return(versionVariables); } }