public static VersionVariables ExecuteGitVersion(IFileSystem fileSystem, string targetUrl, string dynamicRepositoryLocation, Authentication authentication, string targetBranch, bool noFetch, string workingDirectory, string commitId) { // Normalise if we are running on build server var gitPreparer = new GitPreparer(targetUrl, dynamicRepositoryLocation, authentication, noFetch, workingDirectory); var applicableBuildServers = BuildServerList.GetApplicableBuildServers(); var buildServer = applicableBuildServers.FirstOrDefault(); var currentBranch = buildServer == null ? null : buildServer.GetCurrentBranch(); if (!string.IsNullOrEmpty(currentBranch)) { Logger.WriteInfo("Branch from build environment: " + currentBranch); } gitPreparer.Initialise(buildServer != null, currentBranch ?? targetBranch); 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)); } VersionVariables variables; var versionFinder = new GitVersionFinder(); var configuration = ConfigurationProvider.Provide(projectRoot, fileSystem); using (var repo = RepositoryLoader.GetRepo(dotGitDirectory)) { var gitVersionContext = new GitVersionContext(repo, configuration, commitId: commitId); var semanticVersion = versionFinder.FindVersion(gitVersionContext); var config = gitVersionContext.Configuration; variables = VariableProvider.GetVariablesFor(semanticVersion, config.AssemblyVersioningScheme, config.VersioningMode, config.ContinuousDeploymentFallbackTag, gitVersionContext.IsCurrentCommitTagged); } return variables; }
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 static Config Provide(GitPreparer gitPreparer, IFileSystem fileSystem, bool applyDefaults = true, Config overrideConfig = null) { var workingDirectory = gitPreparer.WorkingDirectory; var projectRootDirectory = gitPreparer.GetProjectRootDirectory(); if (HasConfigFileAt(workingDirectory, fileSystem)) { return(Provide(workingDirectory, fileSystem, applyDefaults, overrideConfig)); } return(Provide(projectRootDirectory, fileSystem, applyDefaults, overrideConfig)); }
public static string SelectConfigFilePath(GitPreparer gitPreparer, IFileSystem fileSystem) { var workingDirectory = gitPreparer.WorkingDirectory; var projectRootDirectory = gitPreparer.GetProjectRootDirectory(); if (HasConfigFileAt(workingDirectory, fileSystem)) { return(GetConfigFilePath(workingDirectory, fileSystem)); } return(GetConfigFilePath(projectRootDirectory, fileSystem)); }
public static string SelectConfigFilePath(GitPreparer gitPreparer, IFileSystem fileSystem) { var workingDirectory = gitPreparer.WorkingDirectory; var projectRootDirectory = gitPreparer.GetProjectRootDirectory(); if (HasConfigFileAt(workingDirectory, fileSystem)) { return GetConfigFilePath(workingDirectory, fileSystem); } return GetConfigFilePath(projectRootDirectory, fileSystem); }
public static Config Provide(GitPreparer gitPreparer, IFileSystem fileSystem, bool applyDefaults = true, Config overrideConfig = null) { var workingDirectory = gitPreparer.WorkingDirectory; var projectRootDirectory = gitPreparer.GetProjectRootDirectory(); if (HasConfigFileAt(workingDirectory, fileSystem)) { return Provide(workingDirectory, fileSystem, applyDefaults, overrideConfig); } return Provide(projectRootDirectory, fileSystem, applyDefaults, overrideConfig); }
public VersionVariables ExecuteGitVersion(string targetUrl, string dynamicRepositoryLocation, Authentication authentication, string targetBranch, bool noFetch, string workingDirectory, string commitId, Config overrideConfig = null, bool noCache = false) { // 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 = noCache ? default(VersionVariables) : gitVersionCache.LoadVersionVariablesFromDiskCache(gitPreparer, cacheKey); if (versionVariables == null) { versionVariables = ExecuteInternal(targetBranch, commitId, gitPreparer, buildServer, overrideConfig); if (!noCache) { 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); 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 static void Verify(GitPreparer gitPreparer, IFileSystem fileSystem) { if (!string.IsNullOrWhiteSpace(gitPreparer.TargetUrl)) { // Assuming this is a dynamic repository. At this stage it's unsure whether we have // any .git info so we need to skip verification return; } var workingDirectory = gitPreparer.WorkingDirectory; var projectRootDirectory = gitPreparer.GetProjectRootDirectory(); Verify(workingDirectory, projectRootDirectory, fileSystem); }
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); } }
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; } }
public static VersionVariables ExecuteGitVersion(IFileSystem fileSystem, string targetUrl, string dynamicRepositoryLocation, Authentication authentication, string targetBranch, bool noFetch, string workingDirectory, string commitId) { // Normalise if we are running on build server var gitPreparer = new GitPreparer(targetUrl, dynamicRepositoryLocation, authentication, noFetch, workingDirectory); var applicableBuildServers = BuildServerList.GetApplicableBuildServers(); var buildServer = applicableBuildServers.FirstOrDefault(); var currentBranch = buildServer == null ? null : buildServer.GetCurrentBranch(); if (!string.IsNullOrEmpty(currentBranch)) { Logger.WriteInfo("Branch from build environment: " + currentBranch); } gitPreparer.Initialise(buildServer != null, currentBranch ?? targetBranch); 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)); } VersionVariables variables; var versionFinder = new GitVersionFinder(); var configuration = ConfigurationProvider.Provide(projectRoot, fileSystem); using (var repo = RepositoryLoader.GetRepo(dotGitDirectory)) { var gitVersionContext = new GitVersionContext(repo, configuration, commitId: commitId); var semanticVersion = versionFinder.FindVersion(gitVersionContext); var config = gitVersionContext.Configuration; variables = VariableProvider.GetVariablesFor(semanticVersion, config.AssemblyVersioningScheme, config.VersioningMode, config.ContinuousDeploymentFallbackTag, gitVersionContext.IsCurrentCommitTagged); } return(variables); }
public void WorksCorrectlyWithLocalRepository() { using (var fixture = new EmptyRepositoryFixture(new Config())) { var targetPath = Path.Combine(fixture.RepositoryPath, "tools\\gitversion\\"); Directory.CreateDirectory(targetPath); var gitPreparer = new GitPreparer(null, null, null, false, targetPath); var dotGitDirectory = gitPreparer.GetDotGitDirectory(); var projectRoot = gitPreparer.GetProjectRootDirectory(); dotGitDirectory.ShouldBe(Path.Combine(fixture.RepositoryPath, ".git")); projectRoot.ShouldBe(fixture.RepositoryPath); } }
public static void Verify(GitPreparer gitPreparer, IFileSystem fileSystem) { var workingDirectory = gitPreparer.WorkingDirectory; var projectRootDirectory = gitPreparer.GetProjectRootDirectory(); Verify(workingDirectory, projectRootDirectory, fileSystem); }