diff --git a/GitVersionCore.Tests/BuildServers/BuildServerBaseTests.cs b/GitVersionCore.Tests/BuildServers/BuildServerBaseTests.cs index 9d98291c49..580cd52d84 100644 --- a/GitVersionCore.Tests/BuildServers/BuildServerBaseTests.cs +++ b/GitVersionCore.Tests/BuildServers/BuildServerBaseTests.cs @@ -35,11 +35,6 @@ public override bool CanApplyToCurrentContext() throw new NotImplementedException(); } - public override void PerformPreProcessingSteps(string gitDirectory, bool noFetch) - { - throw new NotImplementedException(); - } - public override string GenerateSetVersionMessage(string versionToUseForBuildNumber) { return versionToUseForBuildNumber; diff --git a/GitVersionCore.Tests/BuildServers/ContinuaCiTests.cs b/GitVersionCore.Tests/BuildServers/ContinuaCiTests.cs index a3c62f535c..a4a27dd783 100644 --- a/GitVersionCore.Tests/BuildServers/ContinuaCiTests.cs +++ b/GitVersionCore.Tests/BuildServers/ContinuaCiTests.cs @@ -8,8 +8,7 @@ public class ContinuaCiTests [Test] public void GenerateBuildVersion() { - var authentication = new Authentication(); - var versionBuilder = new ContinuaCi(authentication); + var versionBuilder = new ContinuaCi(); var continuaCiVersion = versionBuilder.GenerateSetVersionMessage("0.0.0-Beta4.7"); Assert.AreEqual("@@continua[setBuildVersion value='0.0.0-Beta4.7']", continuaCiVersion); } diff --git a/GitVersionCore.Tests/BuildServers/MyGetTests.cs b/GitVersionCore.Tests/BuildServers/MyGetTests.cs index e88d9b29a7..b5c3378c0c 100644 --- a/GitVersionCore.Tests/BuildServers/MyGetTests.cs +++ b/GitVersionCore.Tests/BuildServers/MyGetTests.cs @@ -7,8 +7,7 @@ public class MyGetTests [Test] public void Develop_branch() { - var authentication = new Authentication(); - var versionBuilder = new MyGet(authentication); + var versionBuilder = new MyGet(); var message = versionBuilder.GenerateSetVersionMessage("0.0.0-Unstable4"); Assert.AreEqual(null, message); } @@ -16,8 +15,7 @@ public void Develop_branch() [Test] public void EscapeValues() { - var authentication = new Authentication(); - var versionBuilder = new MyGet(authentication); + var versionBuilder = new MyGet(); var message = versionBuilder.GenerateSetParameterMessage("Foo", "0.8.0-unstable568 Branch:'develop' Sha:'ee69bff1087ebc95c6b43aa2124bd58f5722e0cb'"); Assert.AreEqual("##myget[setParameter name='GitVersion.Foo' value='0.8.0-unstable568 Branch:|'develop|' Sha:|'ee69bff1087ebc95c6b43aa2124bd58f5722e0cb|'']", message[0]); } @@ -25,8 +23,7 @@ public void EscapeValues() [Test] public void BuildNumber() { - var authentication = new Authentication(); - var versionBuilder = new MyGet(authentication); + var versionBuilder = new MyGet(); var message = versionBuilder.GenerateSetParameterMessage("LegacySemVerPadded", "0.8.0-unstable568"); Assert.AreEqual("##myget[buildNumber '0.8.0-unstable568']", message[1]); } diff --git a/GitVersionCore.Tests/BuildServers/TeamCityTests.cs b/GitVersionCore.Tests/BuildServers/TeamCityTests.cs index d8e4b9375a..4226dce52c 100644 --- a/GitVersionCore.Tests/BuildServers/TeamCityTests.cs +++ b/GitVersionCore.Tests/BuildServers/TeamCityTests.cs @@ -7,8 +7,7 @@ public class TeamCityTests [Test] public void Develop_branch() { - var authentication = new Authentication(); - var versionBuilder = new TeamCity(authentication); + var versionBuilder = new TeamCity(); var tcVersion = versionBuilder.GenerateSetVersionMessage("0.0.0-Unstable4"); Assert.AreEqual("##teamcity[buildNumber '0.0.0-Unstable4']", tcVersion); } @@ -16,8 +15,7 @@ public void Develop_branch() [Test] public void EscapeValues() { - var authentication = new Authentication(); - var versionBuilder = new TeamCity(authentication); + var versionBuilder = new TeamCity(); var tcVersion = versionBuilder.GenerateSetParameterMessage("Foo", "0.8.0-unstable568 Branch:'develop' Sha:'ee69bff1087ebc95c6b43aa2124bd58f5722e0cb'"); Assert.AreEqual("##teamcity[setParameter name='GitVersion.Foo' value='0.8.0-unstable568 Branch:|'develop|' Sha:|'ee69bff1087ebc95c6b43aa2124bd58f5722e0cb|'']", tcVersion[0]); Assert.AreEqual("##teamcity[setParameter name='system.GitVersion.Foo' value='0.8.0-unstable568 Branch:|'develop|' Sha:|'ee69bff1087ebc95c6b43aa2124bd58f5722e0cb|'']", tcVersion[1]); diff --git a/GitVersionCore.Tests/ConfigProviderTests.cs b/GitVersionCore.Tests/ConfigProviderTests.cs index dccdd8da58..cca19039e1 100644 --- a/GitVersionCore.Tests/ConfigProviderTests.cs +++ b/GitVersionCore.Tests/ConfigProviderTests.cs @@ -13,14 +13,14 @@ [TestFixture] public class ConfigProviderTests { - string gitDirectory; + string repoPath; IFileSystem fileSystem; [SetUp] public void Setup() { fileSystem = new TestFileSystem(); - gitDirectory = "c:\\MyGitRepo\\.git"; + repoPath = "c:\\MyGitRepo"; } [Test] @@ -41,7 +41,7 @@ public void CanReadDocument() "; SetupConfigFileContent(text); - var config = ConfigurationProvider.Provide(gitDirectory, fileSystem); + var config = ConfigurationProvider.Provide(repoPath, fileSystem); config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinor); config.NextVersion.ShouldBe("2.0.0"); config.TagPrefix.ShouldBe("[vV|version-]"); @@ -61,7 +61,7 @@ public void CanReadOldDocument() release-branch-tag: rc "; SetupConfigFileContent(text); - var error = Should.Throw(() => ConfigurationProvider.Provide(gitDirectory, fileSystem)); + var error = Should.Throw(() => ConfigurationProvider.Provide(repoPath, fileSystem)); error.Message.ShouldContainWithoutWhitespace(@"GitVersionConfig.yaml contains old configuration, please fix the following errors: assemblyVersioningScheme has been replaced by assembly-versioning-scheme develop-branch-tag has been replaced by branch specific configuration.See https://github.com/ParticularLabs/GitVersion/wiki/Branch-Specific-Configuration @@ -79,7 +79,7 @@ public void OverwritesDefaultsWithProvidedConfig() tag: dev"; SetupConfigFileContent(text); var defaultConfig = new Config(); - var config = ConfigurationProvider.Provide(gitDirectory, fileSystem); + var config = ConfigurationProvider.Provide(repoPath, fileSystem); config.NextVersion.ShouldBe("2.0.0"); config.AssemblyVersioningScheme.ShouldBe(defaultConfig.AssemblyVersioningScheme); @@ -97,7 +97,7 @@ public void CanProvideConfigForNewBranch() bug[/-]: tag: bugfix"; SetupConfigFileContent(text); - var config = ConfigurationProvider.Provide(gitDirectory, fileSystem); + var config = ConfigurationProvider.Provide(repoPath, fileSystem); config.Branches["bug[/-]"].Tag.ShouldBe("bugfix"); } @@ -106,7 +106,7 @@ public void CanProvideConfigForNewBranch() [MethodImpl(MethodImplOptions.NoInlining)] public void CanWriteOutEffectiveConfiguration() { - var config = ConfigurationProvider.GetEffectiveConfigAsString(gitDirectory, fileSystem); + var config = ConfigurationProvider.GetEffectiveConfigAsString(repoPath, fileSystem); Approvals.Verify(config); } @@ -116,7 +116,7 @@ public void CanReadDefaultDocument() { const string text = ""; SetupConfigFileContent(text); - var config = ConfigurationProvider.Provide(gitDirectory, fileSystem); + var config = ConfigurationProvider.Provide(repoPath, fileSystem); config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinorPatch); config.Branches["develop"].Tag.ShouldBe("unstable"); config.Branches["release[/-]"].Tag.ShouldBe("beta"); @@ -156,6 +156,6 @@ public void VerifyAliases() void SetupConfigFileContent(string text) { - fileSystem.WriteAllText(Path.Combine(Directory.GetParent(gitDirectory).FullName, "GitVersionConfig.yaml"), text); + fileSystem.WriteAllText(Path.Combine(repoPath, "GitVersionConfig.yaml"), text); } } \ No newline at end of file diff --git a/GitVersionCore.Tests/JsonVersionBuilderTests.Json.approved.txt b/GitVersionCore.Tests/JsonVersionBuilderTests.Json.approved.txt index 9ec84519fc..c6d9d56272 100644 --- a/GitVersionCore.Tests/JsonVersionBuilderTests.Json.approved.txt +++ b/GitVersionCore.Tests/JsonVersionBuilderTests.Json.approved.txt @@ -16,5 +16,6 @@ "BranchName":"feature1", "Sha":"commitSha", "NuGetVersionV2":"1.2.3-unstable0004", - "NuGetVersion":"1.2.3-unstable0004" + "NuGetVersion":"1.2.3-unstable0004", + "CommitDate":"2014-03-06" } \ No newline at end of file diff --git a/GitVersionCore.Tests/VariableProviderTests.ProvidesVariablesInContinuousDeliveryModeForPreRelease.approved.txt b/GitVersionCore.Tests/VariableProviderTests.ProvidesVariablesInContinuousDeliveryModeForPreRelease.approved.txt index 449cbb36c0..359222e2bc 100644 --- a/GitVersionCore.Tests/VariableProviderTests.ProvidesVariablesInContinuousDeliveryModeForPreRelease.approved.txt +++ b/GitVersionCore.Tests/VariableProviderTests.ProvidesVariablesInContinuousDeliveryModeForPreRelease.approved.txt @@ -16,5 +16,6 @@ "BranchName":"develop", "Sha":"commitSha", "NuGetVersionV2":"1.2.3-unstable0004", - "NuGetVersion":"1.2.3-unstable0004" + "NuGetVersion":"1.2.3-unstable0004", + "CommitDate":"2014-03-06" } \ No newline at end of file diff --git a/GitVersionCore.Tests/VariableProviderTests.ProvidesVariablesInContinuousDeliveryModeForStable.approved.txt b/GitVersionCore.Tests/VariableProviderTests.ProvidesVariablesInContinuousDeliveryModeForStable.approved.txt index a3f8e75125..0a931d2957 100644 --- a/GitVersionCore.Tests/VariableProviderTests.ProvidesVariablesInContinuousDeliveryModeForStable.approved.txt +++ b/GitVersionCore.Tests/VariableProviderTests.ProvidesVariablesInContinuousDeliveryModeForStable.approved.txt @@ -16,5 +16,6 @@ "BranchName":"develop", "Sha":"commitSha", "NuGetVersionV2":"1.2.3", - "NuGetVersion":"1.2.3" + "NuGetVersion":"1.2.3", + "CommitDate":"2014-03-06" } \ No newline at end of file diff --git a/GitVersionCore.Tests/VariableProviderTests.ProvidesVariablesInContinuousDeploymentModeForPreRelease.approved.txt b/GitVersionCore.Tests/VariableProviderTests.ProvidesVariablesInContinuousDeploymentModeForPreRelease.approved.txt index 47b48fc15d..a0a5b59661 100644 --- a/GitVersionCore.Tests/VariableProviderTests.ProvidesVariablesInContinuousDeploymentModeForPreRelease.approved.txt +++ b/GitVersionCore.Tests/VariableProviderTests.ProvidesVariablesInContinuousDeploymentModeForPreRelease.approved.txt @@ -16,5 +16,6 @@ "BranchName":"develop", "Sha":"commitSha", "NuGetVersionV2":"1.2.3-unstable0005", - "NuGetVersion":"1.2.3-unstable0005" + "NuGetVersion":"1.2.3-unstable0005", + "CommitDate":"2014-03-06" } \ No newline at end of file diff --git a/GitVersionCore.Tests/VariableProviderTests.ProvidesVariablesInContinuousDeploymentModeForStable.approved.txt b/GitVersionCore.Tests/VariableProviderTests.ProvidesVariablesInContinuousDeploymentModeForStable.approved.txt index 9072b37f8f..236320d602 100644 --- a/GitVersionCore.Tests/VariableProviderTests.ProvidesVariablesInContinuousDeploymentModeForStable.approved.txt +++ b/GitVersionCore.Tests/VariableProviderTests.ProvidesVariablesInContinuousDeploymentModeForStable.approved.txt @@ -16,5 +16,6 @@ "BranchName":"develop", "Sha":"commitSha", "NuGetVersionV2":"1.2.3-ci0005", - "NuGetVersion":"1.2.3-ci0005" + "NuGetVersion":"1.2.3-ci0005", + "CommitDate":"2014-03-06" } \ No newline at end of file diff --git a/GitVersionCore.Tests/VariableProviderTests.ProvidesVariablesInContinuousDeploymentModeForStableWhenCurrentCommitIsTagged.approved.txt b/GitVersionCore.Tests/VariableProviderTests.ProvidesVariablesInContinuousDeploymentModeForStableWhenCurrentCommitIsTagged.approved.txt index aa4897ab51..e76a63f0ac 100644 --- a/GitVersionCore.Tests/VariableProviderTests.ProvidesVariablesInContinuousDeploymentModeForStableWhenCurrentCommitIsTagged.approved.txt +++ b/GitVersionCore.Tests/VariableProviderTests.ProvidesVariablesInContinuousDeploymentModeForStableWhenCurrentCommitIsTagged.approved.txt @@ -16,5 +16,6 @@ "BranchName":"", "Sha":"commitSha", "NuGetVersionV2":"1.2.3", - "NuGetVersion":"1.2.3" + "NuGetVersion":"1.2.3", + "CommitDate":"2014-03-06" } \ No newline at end of file diff --git a/GitVersionCore/BuildServers/AppVeyor.cs b/GitVersionCore/BuildServers/AppVeyor.cs index 50bbee424b..8d21861cbe 100644 --- a/GitVersionCore/BuildServers/AppVeyor.cs +++ b/GitVersionCore/BuildServers/AppVeyor.cs @@ -6,28 +6,11 @@ public class AppVeyor : BuildServerBase { - Authentication authentication; - - public AppVeyor(Authentication authentication) - { - this.authentication = authentication; - } - public override bool CanApplyToCurrentContext() { return !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("APPVEYOR")); } - public override void PerformPreProcessingSteps(string gitDirectory, bool noFetch) - { - if (string.IsNullOrEmpty(gitDirectory)) - { - throw new WarningException("Failed to find .git directory on agent."); - } - - GitHelper.NormalizeGitDirectory(gitDirectory, authentication, noFetch); - } - public override string GenerateSetVersionMessage(string versionToUseForBuildNumber) { var buildNumber = Environment.GetEnvironmentVariable("APPVEYOR_BUILD_NUMBER"); diff --git a/GitVersionCore/BuildServers/BuildServerBase.cs b/GitVersionCore/BuildServers/BuildServerBase.cs index 0567f766d2..689355429e 100644 --- a/GitVersionCore/BuildServers/BuildServerBase.cs +++ b/GitVersionCore/BuildServers/BuildServerBase.cs @@ -5,7 +5,6 @@ public abstract class BuildServerBase : IBuildServer { public abstract bool CanApplyToCurrentContext(); - public abstract void PerformPreProcessingSteps(string gitDirectory, bool noFetch); public abstract string GenerateSetVersionMessage(string versionToUseForBuildNumber); public abstract string[] GenerateSetParameterMessage(string name, string value); diff --git a/GitVersionCore/BuildServers/BuildServerList.cs b/GitVersionCore/BuildServers/BuildServerList.cs index b39adbe40a..8002efa07d 100644 --- a/GitVersionCore/BuildServers/BuildServerList.cs +++ b/GitVersionCore/BuildServers/BuildServerList.cs @@ -5,33 +5,16 @@ public static class BuildServerList { - static List BuildServers; - - public static Func> Selector = arguments => DefaultSelector(arguments); - - public static void ResetSelector() - { - Selector = DefaultSelector; - } - - public static IEnumerable GetApplicableBuildServers(Authentication authentication) + static List BuildServers = new List { - return Selector(authentication); - } + new ContinuaCi(), + new TeamCity(), + new AppVeyor(), + new MyGet() + }; - static IEnumerable DefaultSelector(Authentication authentication) + public static IEnumerable GetApplicableBuildServers() { - if (BuildServers == null) - { - BuildServers = new List - { - new ContinuaCi(authentication), - new TeamCity(authentication), - new AppVeyor(authentication), - new MyGet(authentication) - }; - } - var buildServices = new List(); foreach (var buildServer in BuildServers) diff --git a/GitVersionCore/BuildServers/ContinuaCi.cs b/GitVersionCore/BuildServers/ContinuaCi.cs index 6c5620892c..1478fbd65e 100644 --- a/GitVersionCore/BuildServers/ContinuaCi.cs +++ b/GitVersionCore/BuildServers/ContinuaCi.cs @@ -4,13 +4,6 @@ public class ContinuaCi : BuildServerBase { - Authentication authentication; - - public ContinuaCi(Authentication authentication) - { - this.authentication = authentication; - } - public override bool CanApplyToCurrentContext() { const string KeyName = @"Software\VSoft Technologies\Continua CI Agent"; @@ -28,16 +21,6 @@ public override bool CanApplyToCurrentContext() return false; } - public override void PerformPreProcessingSteps(string gitDirectory, bool noFetch) - { - if (string.IsNullOrEmpty(gitDirectory)) - { - throw new WarningException("Failed to find .git directory on agent"); - } - - GitHelper.NormalizeGitDirectory(gitDirectory, authentication, noFetch); - } - public override string[] GenerateSetParameterMessage(string name, string value) { return new[] diff --git a/GitVersionCore/BuildServers/IBuildServer.cs b/GitVersionCore/BuildServers/IBuildServer.cs index 25bfd6273d..ec5af1f0ec 100644 --- a/GitVersionCore/BuildServers/IBuildServer.cs +++ b/GitVersionCore/BuildServers/IBuildServer.cs @@ -5,7 +5,6 @@ public interface IBuildServer { bool CanApplyToCurrentContext(); - void PerformPreProcessingSteps(string gitDirectory, bool noFetch); string GenerateSetVersionMessage(string versionToUseForBuildNumber); string[] GenerateSetParameterMessage(string name, string value); diff --git a/GitVersionCore/BuildServers/MyGet.cs b/GitVersionCore/BuildServers/MyGet.cs index 9c5dfacbe3..0b74e308e7 100644 --- a/GitVersionCore/BuildServers/MyGet.cs +++ b/GitVersionCore/BuildServers/MyGet.cs @@ -5,13 +5,6 @@ public class MyGet : BuildServerBase { - Authentication authentication; - - public MyGet(Authentication authentication) - { - this.authentication = authentication; - } - public override bool CanApplyToCurrentContext() { var buildRunner = Environment.GetEnvironmentVariable("BuildRunner"); @@ -20,16 +13,6 @@ public override bool CanApplyToCurrentContext() && buildRunner.Equals("MyGet", StringComparison.InvariantCultureIgnoreCase); } - public override void PerformPreProcessingSteps(string gitDirectory, bool noFetch) - { - if (string.IsNullOrEmpty(gitDirectory)) - { - throw new WarningException("Failed to find .git directory on agent."); - } - - GitHelper.NormalizeGitDirectory(gitDirectory, authentication, noFetch); - } - public override string[] GenerateSetParameterMessage(string name, string value) { var messages = new List diff --git a/GitVersionCore/BuildServers/TeamCity.cs b/GitVersionCore/BuildServers/TeamCity.cs index 737fabe4e4..2140a886f8 100644 --- a/GitVersionCore/BuildServers/TeamCity.cs +++ b/GitVersionCore/BuildServers/TeamCity.cs @@ -4,28 +4,11 @@ public class TeamCity : BuildServerBase { - Authentication authentication; - - public TeamCity(Authentication authentication) - { - this.authentication = authentication; - } - public override bool CanApplyToCurrentContext() { return !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("TEAMCITY_VERSION")); } - public override void PerformPreProcessingSteps(string gitDirectory, bool noFetch) - { - if (string.IsNullOrEmpty(gitDirectory)) - { - throw new WarningException("Failed to find .git directory on agent. Please make sure agent checkout mode is enabled for you VCS roots - http://confluence.jetbrains.com/display/TCD8/VCS+Checkout+Mode"); - } - - GitHelper.NormalizeGitDirectory(gitDirectory, authentication, noFetch); - } - public override string[] GenerateSetParameterMessage(string name, string value) { return new[] diff --git a/GitVersionCore/Configuration/ConfigurationProvider.cs b/GitVersionCore/Configuration/ConfigurationProvider.cs index 1389792963..b570626ef9 100644 --- a/GitVersionCore/Configuration/ConfigurationProvider.cs +++ b/GitVersionCore/Configuration/ConfigurationProvider.cs @@ -6,9 +6,9 @@ namespace GitVersion public class ConfigurationProvider { - public static Config Provide(string gitDirectory, IFileSystem fileSystem) + public static Config Provide(string workingDirectory, IFileSystem fileSystem) { - var configFilePath = GetConfigFilePath(gitDirectory); + var configFilePath = GetConfigFilePath(workingDirectory); if (fileSystem.Exists(configFilePath)) { @@ -33,9 +33,9 @@ public static string GetEffectiveConfigAsString(string gitDirectory, IFileSystem return stringBuilder.ToString(); } - public static void WriteSample(string gitDirectory, IFileSystem fileSystem) + public static void WriteSample(string workingDirectory, IFileSystem fileSystem) { - var configFilePath = GetConfigFilePath(gitDirectory); + var configFilePath = GetConfigFilePath(workingDirectory); if (!fileSystem.Exists(configFilePath)) { @@ -51,9 +51,9 @@ public static void WriteSample(string gitDirectory, IFileSystem fileSystem) } } - static string GetConfigFilePath(string gitDirectory) + static string GetConfigFilePath(string workingDirectory) { - return Path.Combine(Directory.GetParent(gitDirectory).FullName, "GitVersionConfig.yaml"); + return Path.Combine(workingDirectory, "GitVersionConfig.yaml"); } } } \ No newline at end of file diff --git a/GitVersionCore/ExecuteCore.cs b/GitVersionCore/ExecuteCore.cs new file mode 100644 index 0000000000..134a25d62c --- /dev/null +++ b/GitVersionCore/ExecuteCore.cs @@ -0,0 +1,37 @@ +namespace GitVersion +{ + using System; + using System.Linq; + using GitVersion.Helpers; + + public static class ExecuteCore + { + 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, targetBranch, noFetch, workingDirectory); + gitPreparer.Initialise(BuildServerList.GetApplicableBuildServers().Any()); + 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; + } + } +} \ No newline at end of file diff --git a/GitVersionExe/GitPreparer.cs b/GitVersionCore/GitPreparer.cs similarity index 78% rename from GitVersionExe/GitPreparer.cs rename to GitVersionCore/GitPreparer.cs index bc44d3cded..f3bdd399da 100644 --- a/GitVersionExe/GitPreparer.cs +++ b/GitVersionCore/GitPreparer.cs @@ -1,4 +1,4 @@ -namespace GitVersion +namespace GitVersion { using System; using System.IO; @@ -7,11 +7,21 @@ public class GitPreparer { - Arguments arguments; - - public GitPreparer(Arguments arguments) + string targetUrl; + string dynamicRepositoryLocation; + Authentication authentication; + string targetBranch; + bool noFetch; + string targetPath; + + public GitPreparer(string targetUrl, string dynamicRepositoryLocation, Authentication authentication, string targetBranch, bool noFetch, string targetPath) { - this.arguments = arguments; + this.targetUrl = targetUrl; + this.dynamicRepositoryLocation = dynamicRepositoryLocation; + this.authentication = authentication; + this.targetBranch = targetBranch; + this.noFetch = noFetch; + this.targetPath = targetPath; } public bool IsDynamicGitRepository @@ -21,15 +31,26 @@ public bool IsDynamicGitRepository public string DynamicGitRepositoryPath { get; private set; } - public void InitialiseDynamicRepositoryIfNeeded() + public void Initialise(bool normaliseGitDirectory) { - if (string.IsNullOrWhiteSpace(arguments.TargetUrl)) return; + if (string.IsNullOrWhiteSpace(targetUrl)) + { + if (normaliseGitDirectory) + { + GitHelper.NormalizeGitDirectory(GetDotGitDirectory(), authentication, noFetch); + } + return; + } - var targetPath = CalculateTemporaryRepositoryPath(arguments.TargetUrl, arguments.DynamicRepositoryLocation); - DynamicGitRepositoryPath = CreateDynamicRepository(targetPath, arguments.Authentication, arguments.TargetUrl, arguments.TargetBranch, arguments.NoFetch); + var targetPath = CalculateTemporaryRepositoryPath(targetUrl, dynamicRepositoryLocation); + DynamicGitRepositoryPath = CreateDynamicRepository(targetPath, authentication, targetUrl, targetBranch, noFetch); + if (normaliseGitDirectory) + { + GitHelper.NormalizeGitDirectory(GetDotGitDirectory(), authentication, noFetch); + } } - string CalculateTemporaryRepositoryPath(string targetUrl, string dynamicRepositoryLocation) + static string CalculateTemporaryRepositoryPath(string targetUrl, string dynamicRepositoryLocation) { var userTemp = dynamicRepositoryLocation ?? Path.GetTempPath(); var repositoryName = targetUrl.Split('/', '\\').Last().Replace(".git", string.Empty); @@ -75,7 +96,15 @@ public string GetDotGitDirectory() if (IsDynamicGitRepository) return DynamicGitRepositoryPath; - return GitDirFinder.TreeWalkForDotGitDir(arguments.TargetPath); + return GitDirFinder.TreeWalkForDotGitDir(targetPath); + } + + public string GetProjectRootDirectory() + { + if (IsDynamicGitRepository) + return targetPath; + + return Directory.GetParent(GitDirFinder.TreeWalkForDotGitDir(targetPath)).FullName; } static string CreateDynamicRepository(string targetPath, Authentication authentication, string repositoryUrl, string targetBranch, bool noFetch) diff --git a/GitVersionCore/GitVersionCore.csproj b/GitVersionCore/GitVersionCore.csproj index db45bf0ca9..7be2b5c95a 100644 --- a/GitVersionCore/GitVersionCore.csproj +++ b/GitVersionCore/GitVersionCore.csproj @@ -81,6 +81,8 @@ + + diff --git a/GitVersionCore/OutputVariables/VariableProvider.cs b/GitVersionCore/OutputVariables/VariableProvider.cs index 8e9bc04c5a..0f9938e6cc 100644 --- a/GitVersionCore/OutputVariables/VariableProvider.cs +++ b/GitVersionCore/OutputVariables/VariableProvider.cs @@ -38,7 +38,8 @@ public static VersionVariables GetVariablesFor( fullSemVer: semanticVersion.ToString("f"), informationalVersion: semanticVersion.ToString("i"), branchName: bmd.Branch, - sha: bmd.Sha); + sha: bmd.Sha, + commitDate: bmd.CommitDate.UtcDateTime.ToString("yyyy-MM-dd")); return variables; } diff --git a/GitVersionCore/OutputVariables/VersionVariables.cs b/GitVersionCore/OutputVariables/VersionVariables.cs index d1f4254f7e..edc474d262 100644 --- a/GitVersionCore/OutputVariables/VersionVariables.cs +++ b/GitVersionCore/OutputVariables/VersionVariables.cs @@ -6,7 +6,8 @@ public class VersionVariables : IEnumerable> { - public VersionVariables(string major, string minor, string patch, string buildMetaData, string fullBuildMetaData, string branchName, string sha, string majorMinorPatch, string semVer, string legacySemVer, string legacySemVerPadded, string fullSemVer, string assemblySemVer, string preReleaseTag, string preReleaseTagWithDash, string informationalVersion) + public VersionVariables(string major, string minor, string patch, string buildMetaData, string fullBuildMetaData, string branchName, string sha, string majorMinorPatch, string semVer, string legacySemVer, string legacySemVerPadded, string fullSemVer, string assemblySemVer, string preReleaseTag, string preReleaseTagWithDash, string informationalVersion, + string commitDate) { Major = major; Minor = minor; @@ -24,6 +25,7 @@ public VersionVariables(string major, string minor, string patch, string buildMe PreReleaseTag = preReleaseTag; PreReleaseTagWithDash = preReleaseTagWithDash; InformationalVersion = informationalVersion; + CommitDate = commitDate; } public string Major { get; private set; } @@ -53,6 +55,8 @@ public IEnumerable AvailableVariables get { return typeof(VersionVariables).GetProperties().Select(p => p.Name).OrderBy(a => a); } } + public string CommitDate { get; set; } + public IEnumerator> GetEnumerator() { var type = typeof(string); diff --git a/GitVersionExe.Tests/ArgumentBuilder.cs b/GitVersionExe.Tests/ArgumentBuilder.cs index c25c21dd69..7d7412885f 100644 --- a/GitVersionExe.Tests/ArgumentBuilder.cs +++ b/GitVersionExe.Tests/ArgumentBuilder.cs @@ -19,11 +19,12 @@ public ArgumentBuilder(string workingDirectory, string exec, string execArgs, st this.isTeamCity = isTeamCity; } - public ArgumentBuilder(string workingDirectory, string additionalArguments, bool isTeamCity) + public ArgumentBuilder(string workingDirectory, string additionalArguments, bool isTeamCity, string logFile) { this.workingDirectory = workingDirectory; this.isTeamCity = isTeamCity; this.additionalArguments = additionalArguments; + this.logFile = logFile; } diff --git a/GitVersionExe.Tests/GitPreparerTests.cs b/GitVersionExe.Tests/GitPreparerTests.cs index bc77b5217b..6c0d1acec4 100644 --- a/GitVersionExe.Tests/GitPreparerTests.cs +++ b/GitVersionExe.Tests/GitPreparerTests.cs @@ -55,8 +55,8 @@ public void WorksCorrectlyWithRemoteRepository(string branchName, string expecte arguments.TargetBranch = branchName; } - var gitPreparer = new GitPreparer(arguments); - gitPreparer.InitialiseDynamicRepositoryIfNeeded(); + var gitPreparer = new GitPreparer(arguments.TargetUrl, arguments.DynamicRepositoryLocation, arguments.Authentication, arguments.TargetBranch, arguments.NoFetch, arguments.TargetPath); + gitPreparer.Initialise(false); dynamicRepositoryPath = gitPreparer.GetDotGitDirectory(); gitPreparer.IsDynamicGitRepository.ShouldBe(true); @@ -100,12 +100,12 @@ public void UpdatesExistingDynamicRepository() TargetBranch = "master" }; - var gitPreparer = new GitPreparer(arguments); - gitPreparer.InitialiseDynamicRepositoryIfNeeded(); + var gitPreparer = new GitPreparer(arguments.TargetUrl, arguments.DynamicRepositoryLocation, arguments.Authentication, arguments.TargetBranch, arguments.NoFetch, arguments.TargetPath); + gitPreparer.Initialise(false); dynamicRepositoryPath = gitPreparer.GetDotGitDirectory(); var newCommit = mainRepositoryFixture.Repository.MakeACommit(); - gitPreparer.InitialiseDynamicRepositoryIfNeeded(); + gitPreparer.Initialise(false); using (var repository = new Repository(dynamicRepositoryPath)) { @@ -147,8 +147,8 @@ public void PicksAnotherDirectoryNameWhenDynamicRepoFolderTaken() TargetUrl = fixture.RepositoryPath }; - var gitPreparer = new GitPreparer(arguments); - gitPreparer.InitialiseDynamicRepositoryIfNeeded(); + var gitPreparer = new GitPreparer(arguments.TargetUrl, arguments.DynamicRepositoryLocation, arguments.Authentication, arguments.TargetBranch, arguments.NoFetch, arguments.TargetPath); + gitPreparer.Initialise(false); gitPreparer.IsDynamicGitRepository.ShouldBe(true); gitPreparer.DynamicGitRepositoryPath.ShouldBe(expectedDynamicRepoLocation + "_1\\.git"); @@ -174,10 +174,39 @@ public void WorksCorrectlyWithLocalRepository() TargetPath = tempDir }; - var gitPreparer = new GitPreparer(arguments); + var gitPreparer = new GitPreparer(arguments.TargetUrl, arguments.DynamicRepositoryLocation, arguments.Authentication, arguments.TargetBranch, arguments.NoFetch, arguments.TargetPath); var dynamicRepositoryPath = gitPreparer.GetDotGitDirectory(); dynamicRepositoryPath.ShouldBe(null); gitPreparer.IsDynamicGitRepository.ShouldBe(false); } + + [Test] + public void UsesGitVersionConfigWhenCreatingDynamicRepository() + { + var localRepoPath = PathHelper.GetTempPath(); + var repoBasePath = Path.GetDirectoryName(PathHelper.GetTempPath()); + Directory.CreateDirectory(localRepoPath); + + try + { + using (var remote = new EmptyRepositoryFixture(new Config())) + { + remote.Repository.MakeACommit(); + var configFile = Path.Combine(localRepoPath, "GitVersionConfig.yaml"); + File.WriteAllText(configFile, "next-version: 1.0.0"); + + var arguments = string.Format(" /url {0} /dynamicRepoLocation {1}", remote.RepositoryPath, repoBasePath); + var results = GitVersionHelper.ExecuteIn(localRepoPath, arguments, false); + results.OutputVariables.SemVer.ShouldBe("1.0.0"); + } + } + finally + { + DeleteHelper.DeleteGitRepository(localRepoPath); + DeleteHelper.DeleteGitRepository(repoBasePath); + } + } + + // TODO test around normalisation } \ No newline at end of file diff --git a/GitVersionExe.Tests/GitVersionHelper.cs b/GitVersionExe.Tests/GitVersionHelper.cs index 70a5e2d0da..8e63934bfd 100644 --- a/GitVersionExe.Tests/GitVersionHelper.cs +++ b/GitVersionExe.Tests/GitVersionHelper.cs @@ -17,7 +17,8 @@ public static ExecutionResults ExecuteIn(string workingDirectory, public static ExecutionResults ExecuteIn(string workingDirectory, string arguments, bool isTeamCity = false) { - var args = new ArgumentBuilder(workingDirectory, arguments, isTeamCity); + var logFile = Path.Combine(workingDirectory, "log.txt"); + var args = new ArgumentBuilder(workingDirectory, arguments, isTeamCity, logFile); return ExecuteIn(args); } @@ -46,7 +47,7 @@ static ExecutionResults ExecuteIn(ArgumentBuilder arguments) Console.WriteLine(); Console.WriteLine("-------------------------------------------------------"); - if (string.IsNullOrWhiteSpace(arguments.LogFile)) + if (string.IsNullOrWhiteSpace(arguments.LogFile) || !File.Exists(arguments.LogFile)) { return new ExecutionResults(exitCode, output.ToString(), null); } diff --git a/GitVersionExe/GitVersionExe.csproj b/GitVersionExe/GitVersionExe.csproj index 6b324afe88..3892ebf84f 100644 --- a/GitVersionExe/GitVersionExe.csproj +++ b/GitVersionExe/GitVersionExe.csproj @@ -56,7 +56,6 @@ - diff --git a/GitVersionExe/SpecifiedArgumentRunner.cs b/GitVersionExe/SpecifiedArgumentRunner.cs index c1047fcca1..30324e4aae 100644 --- a/GitVersionExe/SpecifiedArgumentRunner.cs +++ b/GitVersionExe/SpecifiedArgumentRunner.cs @@ -11,34 +11,19 @@ class SpecifiedArgumentRunner public static void Run(Arguments arguments, IFileSystem fileSystem) { - var gitPreparer = new GitPreparer(arguments); - gitPreparer.InitialiseDynamicRepositoryIfNeeded(); - var dotGitDirectory = gitPreparer.GetDotGitDirectory(); - if (string.IsNullOrEmpty(dotGitDirectory)) - { - throw new Exception(string.Format("Failed to prepare or find the .git directory in path '{0}'", arguments.TargetPath)); - } - var applicableBuildServers = GetApplicableBuildServers(arguments.Authentication).ToList(); - - foreach (var buildServer in applicableBuildServers) - { - buildServer.PerformPreProcessingSteps(dotGitDirectory, arguments.NoFetch); - } - VersionVariables variables; - var versionFinder = new GitVersionFinder(); - var configuration = ConfigurationProvider.Provide(dotGitDirectory, fileSystem); + var noFetch = arguments.NoFetch; + var authentication = arguments.Authentication; + var targetPath = arguments.TargetPath; + var targetUrl = arguments.TargetUrl; + var dynamicRepositoryLocation = arguments.DynamicRepositoryLocation; + var targetBranch = arguments.TargetBranch; + var commitId = arguments.CommitId; - using (var repo = RepositoryLoader.GetRepo(dotGitDirectory)) - { - var gitVersionContext = new GitVersionContext(repo, configuration, commitId: arguments.CommitId); - var semanticVersion = versionFinder.FindVersion(gitVersionContext); - var config = gitVersionContext.Configuration; - variables = VariableProvider.GetVariablesFor(semanticVersion, config.AssemblyVersioningScheme, config.VersioningMode, config.ContinuousDeploymentFallbackTag, gitVersionContext.IsCurrentCommitTagged); - } + var variables = ExecuteCore.ExecuteGitVersion(fileSystem, targetUrl, dynamicRepositoryLocation, authentication, targetBranch, noFetch, targetPath, commitId); if (arguments.Output == OutputType.BuildServer) { - foreach (var buildServer in applicableBuildServers) + foreach (var buildServer in BuildServerList.GetApplicableBuildServers()) { buildServer.WriteIntegration(Console.WriteLine, variables); } @@ -63,10 +48,10 @@ public static void Run(Arguments arguments, IFileSystem fileSystem) } } - using (var assemblyInfoUpdate = new AssemblyInfoFileUpdate(arguments, arguments.TargetPath, variables, fileSystem)) + using (var assemblyInfoUpdate = new AssemblyInfoFileUpdate(arguments, targetPath, variables, fileSystem)) { - var execRun = RunExecCommandIfNeeded(arguments, arguments.TargetPath, variables); - var msbuildRun = RunMsBuildIfNeeded(arguments, arguments.TargetPath, variables); + var execRun = RunExecCommandIfNeeded(arguments, targetPath, variables); + var msbuildRun = RunMsBuildIfNeeded(arguments, targetPath, variables); if (!execRun && !msbuildRun) { assemblyInfoUpdate.DoNotRestoreAssemblyInfo(); @@ -81,11 +66,6 @@ public static void Run(Arguments arguments, IFileSystem fileSystem) } } - static IEnumerable GetApplicableBuildServers(Authentication authentication) - { - return BuildServerList.GetApplicableBuildServers(authentication); - } - static bool RunMsBuildIfNeeded(Arguments args, string workingDirectory, VersionVariables variables) { if (string.IsNullOrEmpty(args.Proj)) return false; diff --git a/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_Major.approved.txt b/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_Major.approved.txt index a3f4922c47..afbbb739d8 100644 --- a/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_Major.approved.txt +++ b/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_Major.approved.txt @@ -39,6 +39,7 @@ static class GitVersionInformation public static string Sha = "commitSha"; public static string NuGetVersionV2 = "2.3.4-beta0005"; public static string NuGetVersion = "2.3.4-beta0005"; + public static string CommitDate = "2014-03-06"; } diff --git a/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinor.approved.txt b/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinor.approved.txt index e7d234613d..832c7b23ad 100644 --- a/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinor.approved.txt +++ b/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinor.approved.txt @@ -39,6 +39,7 @@ static class GitVersionInformation public static string Sha = "commitSha"; public static string NuGetVersionV2 = "2.3.4-beta0005"; public static string NuGetVersion = "2.3.4-beta0005"; + public static string CommitDate = "2014-03-06"; } diff --git a/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatch.approved.txt b/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatch.approved.txt index fff2fa6bd4..5607576322 100644 --- a/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatch.approved.txt +++ b/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatch.approved.txt @@ -39,6 +39,7 @@ static class GitVersionInformation public static string Sha = "commitSha"; public static string NuGetVersionV2 = "2.3.4-beta0005"; public static string NuGetVersion = "2.3.4-beta0005"; + public static string CommitDate = "2014-03-06"; } diff --git a/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatchTag.approved.txt b/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatchTag.approved.txt index e6c7aa3172..24aebf881f 100644 --- a/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatchTag.approved.txt +++ b/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatchTag.approved.txt @@ -39,6 +39,7 @@ static class GitVersionInformation public static string Sha = "commitSha"; public static string NuGetVersionV2 = "2.3.4-beta0005"; public static string NuGetVersion = "2.3.4-beta0005"; + public static string CommitDate = "2014-03-06"; } diff --git a/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyCreatedCode.approved.txt b/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyCreatedCode.approved.txt index 836e58cd54..1ef7c2d027 100644 --- a/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyCreatedCode.approved.txt +++ b/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyCreatedCode.approved.txt @@ -39,6 +39,7 @@ static class GitVersionInformation public static string Sha = "commitSha"; public static string NuGetVersionV2 = "1.2.3-unstable0004"; public static string NuGetVersion = "1.2.3-unstable0004"; + public static string CommitDate = "2014-03-06"; } diff --git a/GitVersionTask.Tests/AssemblyInfoBuilderTests.cs b/GitVersionTask.Tests/AssemblyInfoBuilderTests.cs index b961b9e8c8..a29ce5d08f 100644 --- a/GitVersionTask.Tests/AssemblyInfoBuilderTests.cs +++ b/GitVersionTask.Tests/AssemblyInfoBuilderTests.cs @@ -4,7 +4,6 @@ using System.Runtime.CompilerServices; using ApprovalTests; using GitVersion; -using GitVersionCore.Tests; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using NUnit.Framework; @@ -25,14 +24,9 @@ public void VerifyCreatedCode() BuildMetaData = new SemanticVersionBuildMetaData(5, "feature1", "commitSha", DateTimeOffset.Parse("2014-03-06 23:59:59Z")) }; - var assemblyInfoBuilder = new AssemblyInfoBuilder - { - CachedVersion = new CachedVersion - { - SemanticVersion = semanticVersion - } - }; - var assemblyInfoText = assemblyInfoBuilder.GetAssemblyInfoText(new TestEffectiveConfiguration()); + var assemblyInfoBuilder = new AssemblyInfoBuilder(); + var versionVariables = VariableProvider.GetVariablesFor(semanticVersion, AssemblyVersioningScheme.MajorMinorPatch, VersioningMode.ContinuousDelivery, "ci", false); + var assemblyInfoText = assemblyInfoBuilder.GetAssemblyInfoText(versionVariables); Approvals.Verify(assemblyInfoText); var compilation = CSharpCompilation.Create("Fake.dll") @@ -84,15 +78,9 @@ static void VerifyAssemblyVersion(AssemblyVersioningScheme avs) BuildMetaData = new SemanticVersionBuildMetaData(6, "master", "commitSha", DateTimeOffset.Parse("2014-03-06 23:59:59Z")), }; - var assemblyInfoBuilder = new AssemblyInfoBuilder - { - CachedVersion = new CachedVersion - { - SemanticVersion = semanticVersion - }, - }; - - var assemblyInfoText = assemblyInfoBuilder.GetAssemblyInfoText(new TestEffectiveConfiguration(assemblyVersioningScheme: avs)); + var assemblyInfoBuilder = new AssemblyInfoBuilder(); + var versionVariables = VariableProvider.GetVariablesFor(semanticVersion, avs, VersioningMode.ContinuousDelivery, "ci", false); + var assemblyInfoText = assemblyInfoBuilder.GetAssemblyInfoText(versionVariables); Approvals.Verify(assemblyInfoText); var compilation = CSharpCompilation.Create("Fake.dll") diff --git a/GitVersionTask.Tests/GitHelperTests.cs b/GitVersionTask.Tests/GitHelperTests.cs deleted file mode 100644 index c3553cdcda..0000000000 --- a/GitVersionTask.Tests/GitHelperTests.cs +++ /dev/null @@ -1,143 +0,0 @@ -using System.Diagnostics; -using System.Linq; -using GitVersion; -using LibGit2Sharp; -using NUnit.Framework; - -[TestFixture] -public class GitHelperTests : Lg2sHelperBase -{ - [Test] - public void CanDetermineTheVersionFromAFetchedMaster() - { - var gitDirectory = FakeTeamCityFetchAndCheckout(ASBMTestRepoWorkingDirPath, "refs/heads/master"); - - var authentication = new Authentication(); - GitHelper.NormalizeGitDirectory(gitDirectory, authentication, false); - - using (var repository = new Repository(gitDirectory)) - { - var semanticVersion = new GitVersionFinder().FindVersion(new GitVersionContext(repository, new Config())); - Assert.IsNotNull(semanticVersion); - } - } - - [Test] - public void CanDetermineTheVersionFromAPullRequest() - { - var repoPath = Clone(ASBMTestRepoWorkingDirPath); - CreateFakePullRequest(repoPath, "1735"); - - var gitDirectory = FakeTeamCityFetchAndCheckout(repoPath, "refs/pull/1735/merge"); - - var authentication = new Authentication(); - GitHelper.NormalizeGitDirectory(gitDirectory, authentication, false); - - using (var repository = new Repository(gitDirectory)) - { - var semanticVersion = new GitVersionFinder().FindVersion(new GitVersionContext(repository, new Config())); - Assert.IsNotNull(semanticVersion); - } - } - - [Test] - public void CanDetermineTheVersionFromAFetchedDevelop() - { - var gitDirectory = FakeTeamCityFetchAndCheckout(ASBMTestRepoWorkingDirPath, "refs/heads/develop"); - - var authentication = new Authentication(); - GitHelper.NormalizeGitDirectory(gitDirectory, authentication, false); - - using (var repository = new Repository(gitDirectory)) - { - var semanticVersion = new GitVersionFinder().FindVersion(new GitVersionContext(repository, new Config())); - Assert.IsNotNull(semanticVersion); - } - } - - [Test] - public void CanDetermineTheVersionFromAFetchedFeature() - { - var gitDirectory = FakeTeamCityFetchAndCheckout(ASBMTestRepoWorkingDirPath, "refs/heads/feature/one"); - - var authentication = new Authentication(); - GitHelper.NormalizeGitDirectory(gitDirectory, authentication, false); - - using (var repository = new Repository(gitDirectory)) - { - repository.DumpGraph(); - var semanticVersion = new GitVersionFinder().FindVersion(new GitVersionContext(repository, new Config())); - Assert.IsNotNull(semanticVersion); - } - } - - static void CreateFakePullRequest(string repoPath, string issueNumber) - { - // Fake an upstream repository as it would appear on GitHub - // will pull requests stored under the refs/pull/ namespace - using (var repo = new Repository(repoPath)) - { - var branch = repo.CreateBranch("temp", repo.Branches["develop"].Tip); - branch.Checkout(); - - AddOneCommitToHead(repo, "code"); - AddOneCommitToHead(repo, "code"); - - var c = repo.Head.Tip; - repo.Refs.Add(string.Format("refs/pull/{0}/head", issueNumber), c.Id); - - var sign = SignatureBuilder.SignatureNow(); - var m = repo.ObjectDatabase.CreateCommit( - sign, sign, - string.Format("Merge pull request #{0} from nulltoken/ntk/fix/{0}", issueNumber) - , c.Tree, new[] { repo.Branches["develop"].Tip, c }, true); - - repo.Refs.Add(string.Format("refs/pull/{0}/merge", issueNumber), m.Id); - - repo.Checkout("develop"); - repo.Branches.Remove("temp"); - } - } - - string FakeTeamCityFetchAndCheckout(string upstreamRepository, string monitoredReference) - { - var repoPath = InitNewRepository(); - - using (var repo = new Repository(repoPath)) - { - var remote = repo.Network.Remotes.Add("origin", upstreamRepository); - Debug.Assert(remote.FetchRefSpecs.Single().Specification == "+refs/heads/*:refs/remotes/origin/*"); - repo.Network.Fetch(remote); - - if (monitoredReference.StartsWith("refs/pull/")) - { - repo.Network.Fetch(remote, new[] { string.Format("+{0}:{0}", monitoredReference) }); - } - - var src = monitoredReference; - var dst = monitoredReference.Replace("refs/heads/", "refs/remotes/origin/"); - - var fetched = (DirectReference)repo.Refs[dst]; - if (fetched.IsRemoteTrackingBranch()) - { - Assert.IsNull(repo.Refs[src]); - repo.Refs.Add(src, fetched.Target.Id); - - var branch = repo.Branches[src]; - - repo.Branches.Update(branch, - b => b.Remote = remote.Name, - b => b.UpstreamBranch = src); - } - - repo.Checkout(src); - - if (monitoredReference.StartsWith("refs/pull/")) - { - repo.Refs.Remove(monitoredReference); - } - } - - return repoPath; - } -} \ No newline at end of file diff --git a/GitVersionTask.Tests/GitVersionTask.Tests.csproj b/GitVersionTask.Tests/GitVersionTask.Tests.csproj index 92dca843e8..4862d50eb6 100644 --- a/GitVersionTask.Tests/GitVersionTask.Tests.csproj +++ b/GitVersionTask.Tests/GitVersionTask.Tests.csproj @@ -102,17 +102,12 @@ - - - - - diff --git a/GitVersionTask.Tests/Helpers/Lg2sHelperBase.cs b/GitVersionTask.Tests/Helpers/Lg2sHelperBase.cs deleted file mode 100644 index 64d7bdcdff..0000000000 --- a/GitVersionTask.Tests/Helpers/Lg2sHelperBase.cs +++ /dev/null @@ -1,123 +0,0 @@ -// From https://github.com/libgit2/libgit2sharp/blob/f43d558/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs - -using System; -using System.Collections.Generic; -using System.IO; -using LibGit2Sharp; -using NUnit.Framework; - -public abstract class Lg2sHelperBase : IPostTestDirectoryRemover -{ - public const string TemporaryReposPath = "TestRepos"; - List directories; - - [TestFixtureSetUp] - public void Setup() - { - directories = new List(); - } - - [TestFixtureTearDown] - public virtual void TearDown() - { - foreach (var directory in directories) - { - DirectoryHelper.DeleteDirectory(directory); - } - } - - static Lg2sHelperBase() - { - // Do the set up in the static ctor so it only happens once - SetUpTestEnvironment(); - - if (Directory.Exists(TemporaryReposPath)) - { - DirectoryHelper.DeleteSubDirectories(TemporaryReposPath); - } - } - - protected static string ASBMTestRepoWorkingDirPath { private set; get; } - static DirectoryInfo ResourcesDirectory; - - static void SetUpTestEnvironment() - { - var source = new DirectoryInfo(@"../../Resources"); - ResourcesDirectory = new DirectoryInfo(string.Format(@"Resources/{0}", Guid.NewGuid())); - var parent = new DirectoryInfo(@"Resources"); - - if (parent.Exists) - { - DirectoryHelper.DeleteSubDirectories(parent.FullName); - } - - DirectoryHelper.CopyFilesRecursively(source, ResourcesDirectory); - - // Setup standard paths to our test repositories - ASBMTestRepoWorkingDirPath = Path.Combine(ResourcesDirectory.FullName, "asbm_wd"); - } - - protected SelfCleaningDirectory BuildSelfCleaningDirectory() - { - return new SelfCleaningDirectory(this, BuildTempPath()); - } - - protected SelfCleaningDirectory BuildSelfCleaningDirectory(string path) - { - return new SelfCleaningDirectory(this, path); - } - - protected static string BuildTempPath() - { - return Path.Combine(TemporaryReposPath, Guid.NewGuid().ToString().Substring(0, 8)); - } - - protected string Clone(string sourceDirectoryPath, params string[] additionalSourcePaths) - { - var scd = BuildSelfCleaningDirectory(); - var source = new DirectoryInfo(sourceDirectoryPath); - - var clonePath = Path.Combine(scd.DirectoryPath, source.Name); - DirectoryHelper.CopyFilesRecursively(source, new DirectoryInfo(clonePath)); - - foreach (var additionalPath in additionalSourcePaths) - { - var additional = new DirectoryInfo(additionalPath); - var targetForAdditional = Path.Combine(scd.DirectoryPath, additional.Name); - - DirectoryHelper.CopyFilesRecursively(additional, new DirectoryInfo(targetForAdditional)); - } - - return clonePath; - } - - protected string InitNewRepository(bool isBare = false) - { - var scd = BuildSelfCleaningDirectory(); - - return Repository.Init(scd.DirectoryPath, isBare); - } - - public void Register(string directoryPath) - { - directories.Add(directoryPath); - } - - protected static Commit AddOneCommitToHead(Repository repo, string type) - { - var randomFile = Path.Combine(repo.Info.WorkingDirectory, Guid.NewGuid().ToString()); - File.WriteAllText(randomFile, string.Empty); - repo.Stage(randomFile); - var sign = SignatureBuilder.SignatureNow(); - return repo.Commit(type + " commit", sign, sign); - } - - protected static void AddTag(Repository repo, string tagName) - { - var randomFile = Path.Combine(repo.Info.WorkingDirectory, Guid.NewGuid().ToString()); - File.WriteAllText(randomFile, string.Empty); - repo.Stage(randomFile); - var sign = SignatureBuilder.SignatureNow(); - repo.ApplyTag(tagName, repo.Head.Tip.Id.Sha, sign, "foo"); - } -} \ No newline at end of file diff --git a/GitVersionTask.Tests/UpdateAssemblyInfoTests.cs b/GitVersionTask.Tests/UpdateAssemblyInfoTests.cs deleted file mode 100644 index e80fb7634f..0000000000 --- a/GitVersionTask.Tests/UpdateAssemblyInfoTests.cs +++ /dev/null @@ -1,126 +0,0 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using GitVersion; -using GitVersionTask; -using LibGit2Sharp; -using NUnit.Framework; - -[TestFixture] -public class UpdateAssemblyInfoTests : Lg2sHelperBase -{ - [Test] - public void StandardExecutionMode_LackOfAValidGitDirectoryDoesNotPreventExecution() - { - var task = new UpdateAssemblyInfo - { - BuildEngine = new MockBuildEngine(), - SolutionDirectory = Path.GetTempPath(), - }; - - task.InnerExecute(); - } - - [Test] - public void StandardExecutionMode_DoesNotRequireARemoteToOperate() - { - using (var repo = new Repository(ASBMTestRepoWorkingDirPath)) - { - Assert.AreEqual(0, repo.Network.Remotes.Count()); - } - - var task = new UpdateAssemblyInfo - { - BuildEngine = new MockBuildEngine(), - SolutionDirectory = ASBMTestRepoWorkingDirPath, - }; - - task.InnerExecute(); - } - - [Test] - public void StandardExecutionMode_CanDetermineTheVersionFromALocalMaster() - { - var repoPath = CheckoutLocal(ASBMTestRepoWorkingDirPath, "refs/heads/master"); - - var task = new UpdateAssemblyInfo - { - BuildEngine = new MockBuildEngine(), - SolutionDirectory = repoPath, - }; - - task.InnerExecute(); - } - - [Test] - public void StandardExecutionMode_CanDetermineTheVersionFromALocalDevelop() - { - var repoPath = CheckoutLocal(ASBMTestRepoWorkingDirPath, "refs/heads/develop"); - - var task = new UpdateAssemblyInfo - { - BuildEngine = new MockBuildEngine(), - SolutionDirectory = repoPath, - }; - - task.InnerExecute(); - } - - [Test] - public void StandardExecutionMode_CanDetermineTheVersionFromALocalFeature() - { - var repoPath = CheckoutLocal(ASBMTestRepoWorkingDirPath, "refs/heads/feature/one"); - var task = new UpdateAssemblyInfo - { - BuildEngine = new MockBuildEngine(), - SolutionDirectory = repoPath, - }; - - task.InnerExecute(); - } - - [TestCase("Major")] - [TestCase("MajorMinor")] - [TestCase("MajorMinorPatch")] - [TestCase("mAjOr")] - [TestCase("mAjOrMiNor")] - [TestCase("mAjOrMiNorpatch")] - public void StandardExecutionMode_CanAcceptAssemblyVersioningSchemes(string assemblyVersioningScheme) - { - var repoPath = CheckoutLocal(ASBMTestRepoWorkingDirPath, "refs/heads/master"); - - // TODO Tasks need a way to overrride configuration in tests - var task = new UpdateAssemblyInfo - { - BuildEngine = new MockBuildEngine(), - SolutionDirectory = repoPath, - // TODO AssemblyVersioningScheme = assemblyVersioningScheme - }; - - task.InnerExecute(); - } - - [SetUp] - public void SetUp() - { - //avoid buildserver detection to make the tests pass on the buildserver - BuildServerList.Selector = arguments => new List(); - } - - [TearDown] - public new void TearDown() - { - BuildServerList.ResetSelector(); - } - - string CheckoutLocal(string repositoryPath, string monitoredReference) - { - var repoPath = Clone(repositoryPath); - - using (var repo = new Repository(repoPath)) - { - repo.Branches[monitoredReference].ForceCheckout(); - } - return repoPath; - } -} \ No newline at end of file diff --git a/GitVersionTask.Tests/VersionAndBranchFinderTests.cs b/GitVersionTask.Tests/VersionAndBranchFinderTests.cs deleted file mode 100644 index 154d31abbe..0000000000 --- a/GitVersionTask.Tests/VersionAndBranchFinderTests.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using GitVersion; -using LibGit2Sharp; -using NUnit.Framework; - -[TestFixture] -public class VersionAndBranchFinderTests: Lg2sHelperBase -{ - [Test] - public void ShouldBeAbleGetVersionFromGitDir() - { - var repoPath = Clone(ASBMTestRepoWorkingDirPath); - using (var repo = new Repository(repoPath)) - { - // Create a pull request branch from the parent of current develop tip - repo.Branches.Add("pull/1735/merge", "develop~").ForceCheckout(); - - AddOneCommitToHead(repo, "code"); - - } - - Tuple versionAndBranch; - VersionAndBranchFinder.TryGetVersion(ASBMTestRepoWorkingDirPath, out versionAndBranch, new Config(), false); - Assert.IsNotNull(versionAndBranch); - } -} diff --git a/GitVersionTask.Tests/VersionOnMasterFinderTests.Should_find_previous_commit_that_was_at_least_a_minor_bump.approved.txt b/GitVersionTask.Tests/VersionOnMasterFinderTests.Should_find_previous_commit_that_was_at_least_a_minor_bump.approved.txt deleted file mode 100644 index ea03e7252a..0000000000 --- a/GitVersionTask.Tests/VersionOnMasterFinderTests.Should_find_previous_commit_that_was_at_least_a_minor_bump.approved.txt +++ /dev/null @@ -1,4 +0,0 @@ -{ - "Major": 0, - "Minor": 3 -} \ No newline at end of file diff --git a/GitVersionTask.Tests/WriteVersionInfoToBuildLogTests.cs b/GitVersionTask.Tests/WriteVersionInfoToBuildLogTests.cs deleted file mode 100644 index 95ef72809e..0000000000 --- a/GitVersionTask.Tests/WriteVersionInfoToBuildLogTests.cs +++ /dev/null @@ -1,22 +0,0 @@ - -namespace GitVersionTask.Tests -{ - using System.IO; - using NUnit.Framework; - - [TestFixture] - public class WriteVersionInfoToBuildLogTests - { - [Test] - public void UsingInvalidGitDirectory_ThrowsDirectoryNotFoundException() - { - var task = new WriteVersionInfoToBuildLog - { - BuildEngine = new MockBuildEngine(), - SolutionDirectory = Path.GetTempPath() - }; - - Assert.That(task.InnerExecute, Throws.InstanceOf()); - } - } -} diff --git a/GitVersionTask/AssemblyInfoBuilder/AssemblyInfoBuilder.cs b/GitVersionTask/AssemblyInfoBuilder/AssemblyInfoBuilder.cs index bcfc1d6647..241768ded0 100644 --- a/GitVersionTask/AssemblyInfoBuilder/AssemblyInfoBuilder.cs +++ b/GitVersionTask/AssemblyInfoBuilder/AssemblyInfoBuilder.cs @@ -4,12 +4,8 @@ public class AssemblyInfoBuilder { - public CachedVersion CachedVersion; - - public string GetAssemblyInfoText(EffectiveConfiguration configuration) + public string GetAssemblyInfoText(VersionVariables vars) { - var semanticVersion = CachedVersion.SemanticVersion; - var vars = VariableProvider.GetVariablesFor(semanticVersion, configuration.AssemblyVersioningScheme, configuration.VersioningMode, "ci", false); var assemblyInfo = string.Format(@" using System; using System.Reflection; @@ -40,8 +36,8 @@ static class GitVersionInformation ", vars.AssemblySemVer, vars.MajorMinorPatch + ".0", - semanticVersion.ToString("i"), - semanticVersion.BuildMetaData.CommitDate.UtcDateTime.ToString("yyyy-MM-dd"), + vars.InformationalVersion, + vars.CommitDate, GenerateVariableMembers(vars)); return assemblyInfo; diff --git a/GitVersionTask/AssemblyInfoBuilder/UpdateAssemblyInfo.cs b/GitVersionTask/AssemblyInfoBuilder/UpdateAssemblyInfo.cs index ceb3a1971e..8b32d63ca8 100644 --- a/GitVersionTask/AssemblyInfoBuilder/UpdateAssemblyInfo.cs +++ b/GitVersionTask/AssemblyInfoBuilder/UpdateAssemblyInfo.cs @@ -67,22 +67,16 @@ 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 semanticVersion; - if (!VersionAndBranchFinder.TryGetVersion(SolutionDirectory, out semanticVersion, configuration, NoFetch)) + + VersionVariables versionVariables; + if (!VersionAndBranchFinder.TryGetVersion(SolutionDirectory, out versionVariables, NoFetch, new Authentication(), fileSystem)) { return; } - CreateTempAssemblyInfo(semanticVersion.Item1, semanticVersion.Item2.Configuration); + CreateTempAssemblyInfo(versionVariables); } - void CreateTempAssemblyInfo(CachedVersion semanticVersion, EffectiveConfiguration configuration) + void CreateTempAssemblyInfo(VersionVariables versionVariables) { if (IntermediateOutputPath == null) @@ -95,11 +89,8 @@ void CreateTempAssemblyInfo(CachedVersion semanticVersion, EffectiveConfiguratio AssemblyInfoTempFilePath = Path.Combine(IntermediateOutputPath, "GitVersionTaskAssemblyInfo.g.cs"); } - var assemblyInfoBuilder = new AssemblyInfoBuilder - { - CachedVersion = semanticVersion - }; - var assemblyInfo = assemblyInfoBuilder.GetAssemblyInfoText(configuration); + var assemblyInfoBuilder = new AssemblyInfoBuilder(); + var assemblyInfo = assemblyInfoBuilder.GetAssemblyInfoText(versionVariables); File.WriteAllText(AssemblyInfoTempFilePath, assemblyInfo); } } diff --git a/GitVersionTask/CachedVersion.cs b/GitVersionTask/CachedVersion.cs index c20c0d2ed7..75a35d22c8 100644 --- a/GitVersionTask/CachedVersion.cs +++ b/GitVersionTask/CachedVersion.cs @@ -2,6 +2,6 @@ public class CachedVersion { - public SemanticVersion SemanticVersion; + public VersionVariables VersionVariables; public long Timestamp; } \ No newline at end of file diff --git a/GitVersionTask/GetVersion.cs b/GitVersionTask/GetVersion.cs index 86eaa53378..c57ed4b1b6 100644 --- a/GitVersionTask/GetVersion.cs +++ b/GitVersionTask/GetVersion.cs @@ -68,6 +68,9 @@ public class GetVersion : Task [Output] public string NuGetVersion { get; set; } + [Output] + public string CommitDate { get; set; } + TaskLogger logger; IFileSystem fileSystem; @@ -83,20 +86,11 @@ public override bool Execute() { try { - Tuple versionAndBranch; - var gitDirectory = GitDirFinder.TreeWalkForDotGitDir(SolutionDirectory); - var configuration = ConfigurationProvider.Provide(gitDirectory, fileSystem); + VersionVariables variables; - if (VersionAndBranchFinder.TryGetVersion(SolutionDirectory, out versionAndBranch, configuration, NoFetch)) + if (VersionAndBranchFinder.TryGetVersion(SolutionDirectory, out variables, NoFetch, new Authentication(), fileSystem)) { 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); diff --git a/GitVersionTask/GitVersionTask.csproj b/GitVersionTask/GitVersionTask.csproj index 55ef3e2978..cd335264bc 100644 --- a/GitVersionTask/GitVersionTask.csproj +++ b/GitVersionTask/GitVersionTask.csproj @@ -59,7 +59,6 @@ - diff --git a/GitVersionTask/VersionAndBranchFinder.cs b/GitVersionTask/VersionAndBranchFinder.cs index dadf5e9af0..08f4041d74 100644 --- a/GitVersionTask/VersionAndBranchFinder.cs +++ b/GitVersionTask/VersionAndBranchFinder.cs @@ -1,37 +1,51 @@ using System; using System.Collections.Generic; using GitVersion; +using GitVersion.Helpers; public static class VersionAndBranchFinder { - static List processedDirectories = new List(); - public static bool TryGetVersion(string directory, out Tuple versionAndBranch, Config configuration, bool noFetch) - { - var gitDirectory = GitDirFinder.TreeWalkForDotGitDir(directory); + static Dictionary versionCacheVersions = new Dictionary(); - if (string.IsNullOrEmpty(gitDirectory)) + public static bool TryGetVersion(string directory, out VersionVariables versionVariables, bool noFetch, Authentication authentication, IFileSystem fileSystem) + { + try { - 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; + versionVariables = GetVersion(directory, authentication, noFetch, fileSystem); + return true; + } + catch (Exception ex) + { + Logger.WriteWarning("Could not determine assembly version: " + ex.Message); + versionVariables = null; return false; } + } - if (!processedDirectories.Contains(directory)) + public static VersionVariables GetVersion(string directory, Authentication authentication, bool noFetch, IFileSystem fileSystem) + { + using (var repo = RepositoryLoader.GetRepo(directory)) { - processedDirectories.Add(directory); - var authentication = new Authentication(); - foreach (var buildServer in BuildServerList.GetApplicableBuildServers(authentication)) + 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)) { - Logger.WriteInfo(string.Format("Executing PerformPreProcessingSteps for '{0}'.", buildServer.GetType().Name)); - buildServer.PerformPreProcessingSteps(gitDirectory, noFetch); + 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; } - versionAndBranch = VersionCache.GetVersion(gitDirectory, configuration); - return true; } } diff --git a/GitVersionTask/VersionCache.cs b/GitVersionTask/VersionCache.cs deleted file mode 100644 index 2ed7654d8c..0000000000 --- a/GitVersionTask/VersionCache.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using System.Collections.Generic; -using GitVersion; - -public static class VersionCache -{ - static Dictionary> versionCacheVersions = new Dictionary>(); - - public static Tuple GetVersion(string gitDirectory, Config configuration) - { - using (var repo = RepositoryLoader.GetRepo(gitDirectory)) - { - var versionFinder = new GitVersionFinder(); - var context = new GitVersionContext(repo, configuration); - var ticks = DirectoryDateFinder.GetLastDirectoryWrite(gitDirectory); - var key = string.Format("{0}:{1}:{2}", repo.Head.CanonicalName, repo.Head.Tip.Sha, ticks); - - Tuple result; - if (versionCacheVersions.TryGetValue(key, out result)) - { - if (result.Item1.Timestamp != ticks) - { - Logger.WriteInfo("Change detected. flushing cache."); - result.Item1.SemanticVersion = versionFinder.FindVersion(context); - } - return result; - } - Logger.WriteInfo("Version not in cache. Calculating version."); - - return versionCacheVersions[key] = Tuple.Create(new CachedVersion - { - SemanticVersion = versionFinder.FindVersion(context), - Timestamp = ticks - }, context); - } - } - -} \ No newline at end of file diff --git a/GitVersionTask/WriteVersionInfoToBuildLog.cs b/GitVersionTask/WriteVersionInfoToBuildLog.cs index 4e58a85a4a..3eef8be776 100644 --- a/GitVersionTask/WriteVersionInfoToBuildLog.cs +++ b/GitVersionTask/WriteVersionInfoToBuildLog.cs @@ -6,7 +6,6 @@ using Microsoft.Build.Utilities; using System; using System.Collections.Generic; - using System.IO; using Logger = GitVersion.Logger; public class WriteVersionInfoToBuildLog : Task @@ -52,39 +51,21 @@ public override bool Execute() public void InnerExecute() { - Tuple 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)) + VersionVariables result; + if (!VersionAndBranchFinder.TryGetVersion(SolutionDirectory, out result, NoFetch, new Authentication(), fileSystem)) { 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); + + WriteIntegrationParameters(BuildServerList.GetApplicableBuildServers(), result); } - public void WriteIntegrationParameters(CachedVersion cachedVersion, IEnumerable applicableBuildServers, VersionVariables variables) + public void WriteIntegrationParameters(IEnumerable applicableBuildServers, VersionVariables variables) { foreach (var buildServer in applicableBuildServers) { logger.LogInfo(string.Format("Executing GenerateSetVersionMessage for '{0}'.", buildServer.GetType().Name)); - logger.LogInfo(buildServer.GenerateSetVersionMessage(cachedVersion.SemanticVersion.ToString())); + logger.LogInfo(buildServer.GenerateSetVersionMessage(variables.FullSemVer)); logger.LogInfo(string.Format("Executing GenerateBuildLogOutput for '{0}'.", buildServer.GetType().Name)); foreach (var buildParameter in BuildOutputFormatter.GenerateBuildLogOutput(buildServer, variables)) {