public void InnerExecute() { Tuple <CachedVersion, GitVersionContext> result; var gitDirectory = GitDirFinder.TreeWalkForDotGitDir(SolutionDirectory); if (gitDirectory == null) { throw new DirectoryNotFoundException(string.Format("Unable to locate a git repository in \"{0}\". Make sure that the solution is located in a git controlled folder. If you are using continous integration make sure that the sources are checked out on the build agent.", SolutionDirectory)); } var configuration = ConfigurationProvider.Provide(gitDirectory, fileSystem); if (!VersionAndBranchFinder.TryGetVersion(SolutionDirectory, out result, configuration, NoFetch)) { return; } var authentication = new Authentication(); var cachedVersion = result.Item1; var gitVersionContext = result.Item2; var config = gitVersionContext.Configuration; var assemblyVersioningScheme = config.AssemblyVersioningScheme; var versioningMode = config.VersioningMode; var variablesFor = VariableProvider.GetVariablesFor( cachedVersion.SemanticVersion, assemblyVersioningScheme, versioningMode, config.ContinuousDeploymentFallbackTag, gitVersionContext.IsCurrentCommitTagged); WriteIntegrationParameters(cachedVersion, BuildServerList.GetApplicableBuildServers(authentication), variablesFor); }
public static VersionVariables GetVersion(string directory, Authentication authentication, bool noFetch, IFileSystem fileSystem) { var gitDir = GitDirFinder.TreeWalkForDotGitDir(directory); using (var repo = RepositoryLoader.GetRepo(gitDir)) { var ticks = DirectoryDateFinder.GetLastDirectoryWrite(directory); var key = string.Format("{0}:{1}:{2}", repo.Head.CanonicalName, repo.Head.Tip.Sha, ticks); CachedVersion result; if (versionCacheVersions.TryGetValue(key, out result)) { if (result.Timestamp != ticks) { Logger.WriteInfo("Change detected. flushing cache."); result.VersionVariables = ExecuteCore.ExecuteGitVersion(fileSystem, null, null, authentication, null, noFetch, directory, null); } return(result.VersionVariables); } Logger.WriteInfo("Version not in cache. Calculating version."); return((versionCacheVersions[key] = new CachedVersion { VersionVariables = ExecuteCore.ExecuteGitVersion(fileSystem, null, null, authentication, null, noFetch, directory, null), Timestamp = ticks }).VersionVariables); } }
public static bool TryGetVersion(string directory, out Tuple <CachedVersion, GitVersionContext> versionAndBranch, Config configuration, bool noFetch) { var gitDirectory = GitDirFinder.TreeWalkForDotGitDir(directory); if (string.IsNullOrEmpty(gitDirectory)) { var message = "No .git directory found in provided solution path. This means the assembly may not be versioned correctly. " + "To fix this warning either clone the repository using git or remove the `GitVersionTask` nuget package. " + "To temporarily work around this issue add a AssemblyInfo.cs with an appropriate `AssemblyVersionAttribute`. " + "If it is detected that this build is occurring on a CI server an error may be thrown."; Logger.WriteWarning(message); versionAndBranch = null; return(false); } if (!processedDirectories.Contains(directory)) { processedDirectories.Add(directory); var authentication = new Authentication(); foreach (var buildServer in BuildServerList.GetApplicableBuildServers(authentication)) { Logger.WriteInfo(string.Format("Executing PerformPreProcessingSteps for '{0}'.", buildServer.GetType().Name)); buildServer.PerformPreProcessingSteps(gitDirectory, noFetch); } } versionAndBranch = VersionCache.GetVersion(gitDirectory, configuration); return(true); }
public override bool Execute() { try { Tuple <CachedVersion, GitVersionContext> versionAndBranch; var gitDirectory = GitDirFinder.TreeWalkForDotGitDir(SolutionDirectory); var configuration = ConfigurationProvider.Provide(gitDirectory, fileSystem); if (VersionAndBranchFinder.TryGetVersion(SolutionDirectory, out versionAndBranch, configuration, NoFetch)) { var thisType = typeof(GetVersion); var cachedVersion = versionAndBranch.Item1; var gitVersionContext = versionAndBranch.Item2; var config = gitVersionContext.Configuration; var variables = VariableProvider.GetVariablesFor( cachedVersion.SemanticVersion, config.AssemblyVersioningScheme, config.VersioningMode, config.ContinuousDeploymentFallbackTag, gitVersionContext.IsCurrentCommitTagged); foreach (var variable in variables) { thisType.GetProperty(variable.Key).SetValue(this, variable.Value, null); } } return(true); } catch (WarningException errorException) { logger.LogWarning(errorException.Message); return(true); } catch (Exception exception) { logger.LogError("Error occurred: " + exception); return(false); } finally { Logger.Reset(); } }
public void InnerExecute() { TempFileTracker.DeleteTempFiles(); InvalidFileChecker.CheckForInvalidFiles(CompileFiles, ProjectFile); var gitDirectory = GitDirFinder.TreeWalkForDotGitDir(SolutionDirectory); if (string.IsNullOrEmpty(gitDirectory)) { return; } var configuration = ConfigurationProvider.Provide(gitDirectory, fileSystem); Tuple <CachedVersion, GitVersionContext> semanticVersion; if (!VersionAndBranchFinder.TryGetVersion(SolutionDirectory, out semanticVersion, configuration, NoFetch)) { return; } CreateTempAssemblyInfo(semanticVersion.Item1, semanticVersion.Item2.Configuration); }
public void From_RefsDirectory() { var refsDirectory = Path.Combine(gitDirectory, "refs"); Assert.AreEqual(gitDirectory, GitDirFinder.TreeWalkForDotGitDir(refsDirectory)); }
public void From_GitDirectory() { Assert.AreEqual(gitDirectory, GitDirFinder.TreeWalkForDotGitDir(gitDirectory)); }
public void From_WorkingDirectory_Parent() { var parentDirectory = Directory.GetParent(workDirectory).FullName; Assert.Null(GitDirFinder.TreeWalkForDotGitDir(parentDirectory)); }