diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5d0258c10e..3428922813 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -3,7 +3,7 @@ We love contributions to get started contributing you might need: - [Get started with git](http://rogerdudler.github.io/git-guide) - [How to create a pull request](https://help.github.com/articles/using-pull-requests) - - [An issue to work on](https://github.com/ParticularLabs/GitVersion/labels/up-for-grabs) - We are on [Up for grabs](http://up-for-grabs.net/), our up for grabs issues are tagged `up-for-grabs` + - [An issue to work on](https://github.com/GitTools/GitVersion/labels/up-for-grabs) - We are on [Up for grabs](http://up-for-grabs.net/), our up for grabs issues are tagged `up-for-grabs` - An understanding of our [architecture](#architecture) and how [we write tests](#writing-tests) Once you know how to create a pull request and have an issue to work on, just post a comment saying you will work on it. diff --git a/src/GitVersionCore.Tests/ConfigProviderTests.CanWriteOutEffectiveConfiguration.approved.txt b/src/GitVersionCore.Tests/ConfigProviderTests.CanWriteOutEffectiveConfiguration.approved.txt index a0fbe908c9..2460062693 100644 --- a/src/GitVersionCore.Tests/ConfigProviderTests.CanWriteOutEffectiveConfiguration.approved.txt +++ b/src/GitVersionCore.Tests/ConfigProviderTests.CanWriteOutEffectiveConfiguration.approved.txt @@ -1,29 +1,48 @@ -assembly-versioning-scheme: MajorMinorPatch -mode: ContinuousDelivery -tag-prefix: '[vV]' -continuous-delivery-fallback-tag: ci -branches: - master: - tag: - increment: Patch - prevent-increment-of-merged-branch-version: true - release[/-]: - tag: beta - feature[/-]: - tag: useBranchName - increment: Inherit - hotfix[/-]: - tag: beta - support[/-]: - tag: - increment: Patch - prevent-increment-of-merged-branch-version: true - develop: - mode: ContinuousDeployment - tag: unstable - increment: Minor - track-merge-target: true - (pull|pull\-requests|pr)[/-]: - tag: PullRequest - increment: Inherit - tag-number-pattern: '[/-](?\d+)[-/]' +assembly-versioning-scheme: MajorMinorPatch +mode: ContinuousDelivery +tag-prefix: '[vV]' +continuous-delivery-fallback-tag: ci +branches: + master: + mode: ContinuousDelivery + tag: + increment: Patch + prevent-increment-of-merged-branch-version: true + track-merge-target: false + release[/-]: + mode: ContinuousDelivery + tag: beta + increment: Patch + prevent-increment-of-merged-branch-version: true + track-merge-target: false + feature[/-]: + mode: ContinuousDelivery + tag: useBranchName + increment: Inherit + prevent-increment-of-merged-branch-version: false + track-merge-target: false + (pull|pull\-requests|pr)[/-]: + mode: ContinuousDelivery + tag: PullRequest + increment: Inherit + prevent-increment-of-merged-branch-version: false + tag-number-pattern: '[/-](?\d+)[-/]' + track-merge-target: false + hotfix[/-]: + mode: ContinuousDelivery + tag: beta + increment: Patch + prevent-increment-of-merged-branch-version: false + track-merge-target: false + support[/-]: + mode: ContinuousDelivery + tag: + increment: Patch + prevent-increment-of-merged-branch-version: true + track-merge-target: false + develop: + mode: ContinuousDeployment + tag: unstable + increment: Minor + prevent-increment-of-merged-branch-version: false + track-merge-target: true diff --git a/src/GitVersionCore.Tests/ConfigProviderTests.cs b/src/GitVersionCore.Tests/ConfigProviderTests.cs index 15bcf20a2c..5a3236106e 100644 --- a/src/GitVersionCore.Tests/ConfigProviderTests.cs +++ b/src/GitVersionCore.Tests/ConfigProviderTests.cs @@ -64,13 +64,14 @@ public void CanReadOldDocument() 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 -release-branch-tag has been replaced by branch specific configuration.See https://github.com/ParticularLabs/GitVersion/wiki/Branch-Specific-Configuration"); +develop-branch-tag has been replaced by branch specific configuration.See http://gitversion.readthedocs.org/en/latest/configuration/#branch-configuration +release-branch-tag has been replaced by branch specific configuration.See http://gitversion.readthedocs.org/en/latest/configuration/#branch-configuration"); } [Test] public void OverwritesDefaultsWithProvidedConfig() { + var defaultConfig = ConfigurationProvider.Provide(repoPath, fileSystem); const string text = @" next-version: 2.0.0 branches: @@ -78,11 +79,9 @@ public void OverwritesDefaultsWithProvidedConfig() mode: ContinuousDeployment tag: dev"; SetupConfigFileContent(text); - var defaultConfig = new Config(); var config = ConfigurationProvider.Provide(repoPath, fileSystem); config.NextVersion.ShouldBe("2.0.0"); - config.AssemblyVersioningScheme.ShouldBe(defaultConfig.AssemblyVersioningScheme); config.Branches["develop"].Increment.ShouldBe(defaultConfig.Branches["develop"].Increment); config.Branches["develop"].VersioningMode.ShouldBe(defaultConfig.Branches["develop"].VersioningMode); config.Branches["develop"].Tag.ShouldBe("dev"); @@ -120,7 +119,7 @@ public void CanReadDefaultDocument() config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinorPatch); config.Branches["develop"].Tag.ShouldBe("unstable"); config.Branches["release[/-]"].Tag.ShouldBe("beta"); - config.TagPrefix.ShouldBe(Config.DefaultTagPrefix); + config.TagPrefix.ShouldBe(ConfigurationProvider.DefaultTagPrefix); config.NextVersion.ShouldBe(null); } diff --git a/src/GitVersionCore.Tests/Fixtures/RepositoryFixtureBase.cs b/src/GitVersionCore.Tests/Fixtures/RepositoryFixtureBase.cs index ec7cf49574..5764df9783 100644 --- a/src/GitVersionCore.Tests/Fixtures/RepositoryFixtureBase.cs +++ b/src/GitVersionCore.Tests/Fixtures/RepositoryFixtureBase.cs @@ -16,6 +16,7 @@ public abstract class RepositoryFixtureBase : IDisposable protected RepositoryFixtureBase(Func repoBuilder, Config configuration) { + ConfigurationProvider.ApplyDefaultsTo(configuration); diagramBuilder = new StringBuilder(); diagramBuilder.AppendLine("@startuml"); this.configuration = configuration; diff --git a/src/GitVersionCore.Tests/GitVersionContextBuilder.cs b/src/GitVersionCore.Tests/GitVersionContextBuilder.cs index 6ff6455a18..0082cc133b 100644 --- a/src/GitVersionCore.Tests/GitVersionContextBuilder.cs +++ b/src/GitVersionCore.Tests/GitVersionContextBuilder.cs @@ -58,7 +58,9 @@ public GitVersionContextBuilder AddBranch(string branchName) public GitVersionContext Build() { - return new GitVersionContext(repository ?? CreateRepository(), config ?? new Config()); + var configuration = config ?? new Config(); + ConfigurationProvider.ApplyDefaultsTo(configuration); + return new GitVersionContext(repository ?? CreateRepository(), configuration); } IRepository CreateRepository() diff --git a/src/GitVersionCore.Tests/GitVersionContextTests.cs b/src/GitVersionCore.Tests/GitVersionContextTests.cs index 3247cf506c..91079bf624 100644 --- a/src/GitVersionCore.Tests/GitVersionContextTests.cs +++ b/src/GitVersionCore.Tests/GitVersionContextTests.cs @@ -15,6 +15,7 @@ public void CanInheritVersioningMode(VersioningMode mode) { VersioningMode = mode }; + ConfigurationProvider.ApplyDefaultsTo(config); var mockBranch = new MockBranch("master") { new MockCommit { CommitterEx = SignatureBuilder.SignatureNow() } }; var mockRepository = new MockRepository @@ -34,10 +35,19 @@ public void UsesBranchSpecificConfigOverTopLevelDefaults() { var config = new Config { - VersioningMode = VersioningMode.ContinuousDelivery + VersioningMode = VersioningMode.ContinuousDelivery, + Branches = + { + { + "develop", new BranchConfig + { + VersioningMode = VersioningMode.ContinuousDeployment, + Tag = "alpha" + } + } + } }; - config.Branches["develop"].VersioningMode = VersioningMode.ContinuousDeployment; - config.Branches["develop"].Tag = "alpha"; + ConfigurationProvider.ApplyDefaultsTo(config); var develop = new MockBranch("develop") { new MockCommit { CommitterEx = SignatureBuilder.SignatureNow() } }; var mockRepository = new MockRepository { @@ -54,9 +64,14 @@ public void UsesBranchSpecificConfigOverTopLevelDefaults() [Test] public void CanFindParentBranchForInheritingIncrementStrategy() { - var config = new Config(); - config.Branches["develop"].Increment = IncrementStrategy.Major; - config.Branches["feature[/-]"].Increment = IncrementStrategy.Inherit; + var config = new Config + { + Branches = + { + { "develop", new BranchConfig { Increment = IncrementStrategy.Major} }, + { "feature[/-]", new BranchConfig { Increment = IncrementStrategy.Inherit} } + } + }; using (var repo = new EmptyRepositoryFixture(config)) { diff --git a/src/GitVersionCore.Tests/GitVersionCore.Tests.csproj b/src/GitVersionCore.Tests/GitVersionCore.Tests.csproj index 1bd506bb2e..dfd7b7dc26 100644 --- a/src/GitVersionCore.Tests/GitVersionCore.Tests.csproj +++ b/src/GitVersionCore.Tests/GitVersionCore.Tests.csproj @@ -53,6 +53,22 @@ False ..\packages\LibGit2Sharp.0.20.1.0\lib\net40\LibGit2Sharp.dll + + ..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.dll + True + + + ..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Mdb.dll + True + + + ..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Pdb.dll + True + + + ..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Rocks.dll + True + False ..\packages\NUnit.2.6.4\lib\nunit.framework.dll @@ -68,6 +84,10 @@ + + ..\packages\TestStack.ConventionTests.2.2.1\lib\net40\TestStack.ConventionTests.dll + True + False ..\packages\YamlDotNet.3.5.1\lib\net35\YamlDotNet.dll @@ -85,6 +105,9 @@ + + + @@ -124,6 +147,7 @@ + diff --git a/src/GitVersionCore.Tests/Init/InitScenarios.CanSetNextVersion.approved.txt b/src/GitVersionCore.Tests/Init/InitScenarios.CanSetNextVersion.approved.txt new file mode 100644 index 0000000000..bc5d6b1c34 --- /dev/null +++ b/src/GitVersionCore.Tests/Init/InitScenarios.CanSetNextVersion.approved.txt @@ -0,0 +1,2 @@ +next-version: 2.0.0 +branches: {} diff --git a/src/GitVersionCore.Tests/Init/InitScenarios.cs b/src/GitVersionCore.Tests/Init/InitScenarios.cs new file mode 100644 index 0000000000..0b7703a94f --- /dev/null +++ b/src/GitVersionCore.Tests/Init/InitScenarios.cs @@ -0,0 +1,31 @@ +namespace GitVersionCore.Tests.Init +{ + using ApprovalTests; + using GitVersion; + using GitVersion.Configuration.Init; + using GitVersion.Configuration.Init.Wizard; + using NUnit.Framework; + using TestStack.ConventionTests; + using TestStack.ConventionTests.ConventionData; + + [TestFixture] + public class InitScenarios + { + [Test] + public void CanSetNextVersion() + { + var testFileSystem = new TestFileSystem(); + var testConsole = new TestConsole("3", "2.0.0", "0"); + ConfigurationProvider.Init("c:\\proj", testFileSystem, testConsole); + + Approvals.Verify(testFileSystem.ReadAllText("c:\\proj\\GitVersionConfig.yaml")); + } + + [Test] + public void DefaultResponsesDoNotThrow() + { + var steps = Types.InAssemblyOf(t => t.IsSubclassOf(typeof(ConfigInitWizardStep)) && t.IsConcreteClass()); + Convention.Is(new InitStepsDefaultResponsesDoNotThrow(), steps); + } + } +} \ No newline at end of file diff --git a/src/GitVersionCore.Tests/Init/InitStepsDefaultResponsesDoNotThrow.cs b/src/GitVersionCore.Tests/Init/InitStepsDefaultResponsesDoNotThrow.cs new file mode 100644 index 0000000000..4688284447 --- /dev/null +++ b/src/GitVersionCore.Tests/Init/InitStepsDefaultResponsesDoNotThrow.cs @@ -0,0 +1,36 @@ +namespace GitVersionCore.Tests.Init +{ + using System; + using System.Linq; + using System.Reflection; + using GitVersion.Configuration.Init.Wizard; + using TestStack.ConventionTests; + using TestStack.ConventionTests.ConventionData; + + public class InitStepsDefaultResponsesDoNotThrow : IConvention + { + public void Execute(Types data, IConventionResultContext result) + { + var resultProperty = typeof(ConfigInitWizardStep).GetProperty("DefaultResult", BindingFlags.NonPublic | BindingFlags.Instance); + result + .Is("Init steps default response should not throw", + data.TypesToVerify.Where(t => + { + var constructorInfo = t.GetConstructors().Single(); + var ctorArguments = constructorInfo.GetParameters().Select(p => p.ParameterType.IsValueType ? Activator.CreateInstance(p.ParameterType) : null).ToArray(); + var instance = Activator.CreateInstance(t, ctorArguments); + try + { + resultProperty.GetValue(instance); + } + catch (Exception) + { + return true; + } + return false; + })); + } + + public string ConventionReason { get { return "So things do not blow up"; } } + } +} \ No newline at end of file diff --git a/src/GitVersionCore.Tests/Init/TestConsole.cs b/src/GitVersionCore.Tests/Init/TestConsole.cs new file mode 100644 index 0000000000..a1239a8e69 --- /dev/null +++ b/src/GitVersionCore.Tests/Init/TestConsole.cs @@ -0,0 +1,46 @@ +namespace GitVersionCore.Tests.Init +{ + using System; + using System.Collections.Generic; + using GitVersion; + + public class TestConsole : IConsole + { + readonly Queue responses; + + public TestConsole(params string[] responses) + { + this.responses = new Queue(responses); + } + + public void WriteLine(string msg) + { + Logger.WriteInfo(msg + Environment.NewLine); + } + + public void WriteLine() + { + Logger.WriteInfo(Environment.NewLine); + } + + public void Write(string msg) + { + Logger.WriteInfo(msg); + } + + public string ReadLine() + { + return responses.Dequeue(); + } + + public IDisposable UseColor(ConsoleColor consoleColor) + { + return new NoOpDisposable(); + } + + class NoOpDisposable : IDisposable + { + public void Dispose() { } + } + } +} \ No newline at end of file diff --git a/src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs b/src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs index ccb4b888c0..063d422de9 100644 --- a/src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs +++ b/src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs @@ -55,8 +55,13 @@ public void WhenDevelopBranchedFromTaggedCommitOnMasterVersionDoesNotChange() [Test] public void CanChangeDevelopTagViaConfig() { - var config = new Config(); - config.Branches["develop"].Tag = "alpha"; + var config = new Config + { + Branches = + { + { "develop", new BranchConfig { Tag = "alpha" } } + } + }; using (var fixture = new EmptyRepositoryFixture(config)) { fixture.Repository.MakeATaggedCommit("1.0.0"); @@ -100,8 +105,13 @@ public void MergingReleaseBranchBackIntoDevelopWithMergingToMaster_DoesBumpDevel [Test] public void CanHandleContinuousDelivery() { - var config = new Config(); - config.Branches["develop"].VersioningMode = VersioningMode.ContinuousDelivery; + var config = new Config + { + Branches = + { + { "develop", new BranchConfig { VersioningMode = VersioningMode.ContinuousDelivery} } + } + }; using (var fixture = new EmptyRepositoryFixture(config)) { fixture.Repository.MakeATaggedCommit("1.0.0"); diff --git a/src/GitVersionCore.Tests/IntegrationTests/FeatureBranchScenarios.cs b/src/GitVersionCore.Tests/IntegrationTests/FeatureBranchScenarios.cs index 03aab78fd9..106599feaa 100644 --- a/src/GitVersionCore.Tests/IntegrationTests/FeatureBranchScenarios.cs +++ b/src/GitVersionCore.Tests/IntegrationTests/FeatureBranchScenarios.cs @@ -35,8 +35,13 @@ public void ShouldInheritIncrementCorrectlyWithMultiplePossibleParentsAndWeirdly [Test] public void BranchCreatedAfterFastForwardMergeShouldInheritCorrectly() { - var config = new Config(); - config.Branches.Add("unstable", config.Branches["develop"]); + var config = new Config + { + Branches = + { + { "unstable", new BranchConfig { Increment = IncrementStrategy.Minor } } + } + }; using (var fixture = new EmptyRepositoryFixture(config)) { diff --git a/src/GitVersionCore.Tests/IntegrationTests/ReleaseBranchScenarios.cs b/src/GitVersionCore.Tests/IntegrationTests/ReleaseBranchScenarios.cs index 715a2c9f0e..56852dcd2d 100644 --- a/src/GitVersionCore.Tests/IntegrationTests/ReleaseBranchScenarios.cs +++ b/src/GitVersionCore.Tests/IntegrationTests/ReleaseBranchScenarios.cs @@ -89,8 +89,13 @@ public void ReleaseBranchWithNextVersionSetInConfig() [Test] public void CanTakeVersionFromReleaseBranchWithTagOverridden() { - var config = new Config(); - config.Branches["release[/-]"].Tag = "rc"; + var config = new Config + { + Branches = + { + { "release[/-]", new BranchConfig { Tag = "rc" } } + } + }; using (var fixture = new EmptyRepositoryFixture(config)) { fixture.Repository.MakeATaggedCommit("1.0.3"); diff --git a/src/GitVersionCore.Tests/IntegrationTests/VersionBumpingScenarios.cs b/src/GitVersionCore.Tests/IntegrationTests/VersionBumpingScenarios.cs index 352e7afc8a..1eeb014840 100644 --- a/src/GitVersionCore.Tests/IntegrationTests/VersionBumpingScenarios.cs +++ b/src/GitVersionCore.Tests/IntegrationTests/VersionBumpingScenarios.cs @@ -7,8 +7,13 @@ public class VersionBumpingScenarios [Test] public void AppliedPrereleaseTagCausesBump() { - var configuration = new Config(); - configuration.Branches["master"].Tag = "pre"; + var configuration = new Config + { + Branches = + { + { "master", new BranchConfig { Tag = "pre" } } + } + }; using (var fixture = new EmptyRepositoryFixture(configuration)) { fixture.Repository.MakeACommit(); diff --git a/src/GitVersionCore.Tests/SemanticVersionTests.cs b/src/GitVersionCore.Tests/SemanticVersionTests.cs index fc036d9225..498d91c998 100644 --- a/src/GitVersionCore.Tests/SemanticVersionTests.cs +++ b/src/GitVersionCore.Tests/SemanticVersionTests.cs @@ -26,9 +26,9 @@ public class SemanticVersionTests [TestCase("1.2.3+4.Branch.Foo", 1, 2, 3, null, null, 4, "Foo", null, null, null, null)] [TestCase("1.2.3+randomMetaData", 1, 2, 3, null, null, null, null, null, "randomMetaData", null, null)] [TestCase("1.2.3-beta.1+4.Sha.12234.Othershiz", 1, 2, 3, "beta", 1, 4, null, "12234", "Othershiz", null, null)] - [TestCase("1.2.3", 1, 2, 3, null, null, null, null, null, null, null, Config.DefaultTagPrefix)] - [TestCase("v1.2.3", 1, 2, 3, null, null, null, null, null, null, "1.2.3", Config.DefaultTagPrefix)] - [TestCase("V1.2.3", 1, 2, 3, null, null, null, null, null, null, "1.2.3", Config.DefaultTagPrefix)] + [TestCase("1.2.3", 1, 2, 3, null, null, null, null, null, null, null, ConfigurationProvider.DefaultTagPrefix)] + [TestCase("v1.2.3", 1, 2, 3, null, null, null, null, null, null, "1.2.3", ConfigurationProvider.DefaultTagPrefix)] + [TestCase("V1.2.3", 1, 2, 3, null, null, null, null, null, null, "1.2.3", ConfigurationProvider.DefaultTagPrefix)] [TestCase("version-1.2.3", 1, 2, 3, null, null, null, null, null, null, "1.2.3", "version-")] public void ValidateVersionParsing( string versionString, int major, int minor, int patch, string tag, int? tagNumber, int? numberOfBuilds, diff --git a/src/GitVersionCore.Tests/TestFileSystem.cs b/src/GitVersionCore.Tests/TestFileSystem.cs index 032300bc1a..dba500611c 100644 --- a/src/GitVersionCore.Tests/TestFileSystem.cs +++ b/src/GitVersionCore.Tests/TestFileSystem.cs @@ -1,6 +1,7 @@ - using System.Collections.Generic; - using System.IO; - using GitVersion.Helpers; +using System; +using System.Collections.Generic; +using System.IO; +using GitVersion.Helpers; public class TestFileSystem : IFileSystem { @@ -8,12 +9,12 @@ public class TestFileSystem : IFileSystem public void Copy(string @from, string to, bool overwrite) { - throw new System.NotImplementedException(); + throw new NotImplementedException(); } public void Move(string @from, string to) { - throw new System.NotImplementedException(); + throw new NotImplementedException(); } public bool Exists(string file) @@ -23,7 +24,7 @@ public bool Exists(string file) public void Delete(string path) { - throw new System.NotImplementedException(); + throw new NotImplementedException(); } public string ReadAllText(string path) @@ -41,11 +42,11 @@ public void WriteAllText(string file, string fileContents) public IEnumerable DirectoryGetFiles(string directory, string searchPattern, SearchOption searchOption) { - throw new System.NotImplementedException(); + throw new NotImplementedException(); } public Stream OpenWrite(string path) { - throw new System.NotImplementedException(); + return new TestStream(path, this); } } \ No newline at end of file diff --git a/src/GitVersionCore.Tests/TestStream.cs b/src/GitVersionCore.Tests/TestStream.cs new file mode 100644 index 0000000000..ce23cfa7ec --- /dev/null +++ b/src/GitVersionCore.Tests/TestStream.cs @@ -0,0 +1,76 @@ +using System; +using System.IO; +using System.Threading; +using System.Threading.Tasks; + +public class TestStream : Stream +{ + readonly string path; + readonly TestFileSystem testFileSystem; + MemoryStream underlying = new MemoryStream(); + + public TestStream(string path, TestFileSystem testFileSystem) + { + this.path = path; + this.testFileSystem = testFileSystem; + } + + protected override void Dispose(bool disposing) + { + Flush(); + base.Dispose(disposing); + } + + public override void Flush() + { + underlying.Position = 0; + var readToEnd = new StreamReader(underlying).ReadToEnd(); + testFileSystem.WriteAllText(path, readToEnd); + } + + public override long Seek(long offset, SeekOrigin origin) + { + return underlying.Seek(offset, origin); + } + + public override void SetLength(long value) + { + underlying.SetLength(value); + } + + public override int Read(byte[] buffer, int offset, int count) + { + return underlying.Read(buffer, offset, count); + } + + public override void Write(byte[] buffer, int offset, int count) + { + underlying.Write(buffer, offset, count); + } + + public override void WriteByte(byte value) + { + base.WriteByte(value); + } + + public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) + { + return base.BeginWrite(buffer, offset, count, callback, state); + } + + public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) + { + return base.WriteAsync(buffer, offset, count, cancellationToken); + } + + public override bool CanRead { get { return underlying.CanRead; } } + public override bool CanSeek { get { return underlying.CanSeek; } } + public override bool CanWrite { get { return underlying.CanWrite; } } + public override long Length { get { return underlying.Length; } } + + public override long Position + { + get { return underlying.Position; } + set { underlying.Position = value; } + } +} \ No newline at end of file diff --git a/src/GitVersionCore.Tests/packages.config b/src/GitVersionCore.Tests/packages.config index e0a13f8d56..be83d1b714 100644 --- a/src/GitVersionCore.Tests/packages.config +++ b/src/GitVersionCore.Tests/packages.config @@ -5,7 +5,9 @@ + + \ No newline at end of file diff --git a/src/GitVersionCore/BranchConfigurationCalculator.cs b/src/GitVersionCore/BranchConfigurationCalculator.cs index c8b8be6058..832b70e52b 100644 --- a/src/GitVersionCore/BranchConfigurationCalculator.cs +++ b/src/GitVersionCore/BranchConfigurationCalculator.cs @@ -14,7 +14,9 @@ public static KeyValuePair GetBranchConfiguration(Commit c if (matchingBranches.Length == 0) { - return new KeyValuePair(string.Empty, new BranchConfig()); + var branchConfig = new BranchConfig(); + ConfigurationProvider.ApplyBranchDefaults(config, branchConfig); + return new KeyValuePair(string.Empty, branchConfig); } if (matchingBranches.Length == 1) { diff --git a/src/GitVersionCore/Configuration/BranchConfig.cs b/src/GitVersionCore/Configuration/BranchConfig.cs index 29c0485c59..f20836adaa 100644 --- a/src/GitVersionCore/Configuration/BranchConfig.cs +++ b/src/GitVersionCore/Configuration/BranchConfig.cs @@ -37,6 +37,6 @@ public BranchConfig(BranchConfig branchConfiguration) public string TagNumberPattern { get; set; } [YamlMember(Alias = "track-merge-target")] - public bool TrackMergeTarget { get; set; } + public bool? TrackMergeTarget { get; set; } } } diff --git a/src/GitVersionCore/Configuration/Config.cs b/src/GitVersionCore/Configuration/Config.cs index 7de22999ab..1b8865e2ae 100644 --- a/src/GitVersionCore/Configuration/Config.cs +++ b/src/GitVersionCore/Configuration/Config.cs @@ -6,53 +6,10 @@ public class Config { - internal const string DefaultTagPrefix = "[vV]"; - Dictionary branches = new Dictionary(); - public Config() - { - AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatch; - TagPrefix = DefaultTagPrefix; - VersioningMode = GitVersion.VersioningMode.ContinuousDelivery; - ContinuousDeploymentFallbackTag = "ci"; - - Branches["master"] = new BranchConfig - { - Tag = string.Empty, - Increment = IncrementStrategy.Patch, - PreventIncrementOfMergedBranchVersion = true - }; - Branches["release[/-]"] = new BranchConfig { Tag = "beta" }; - Branches["feature[/-]"] = new BranchConfig - { - Increment = IncrementStrategy.Inherit, - Tag = "useBranchName" - }; - Branches["hotfix[/-]"] = new BranchConfig { Tag = "beta" }; - Branches["support[/-]"] = new BranchConfig - { - Tag = string.Empty, - Increment = IncrementStrategy.Patch, - PreventIncrementOfMergedBranchVersion = true - }; - Branches["develop"] = new BranchConfig - { - Tag = "unstable", - Increment = IncrementStrategy.Minor, - VersioningMode = GitVersion.VersioningMode.ContinuousDeployment, - TrackMergeTarget = true - }; - Branches[@"(pull|pull\-requests|pr)[/-]"] = new BranchConfig - { - Tag = "PullRequest", - TagNumberPattern = @"[/-](?\d+)[-/]", - Increment = IncrementStrategy.Inherit - }; - } - [YamlMember(Alias = "assembly-versioning-scheme")] - public AssemblyVersioningScheme AssemblyVersioningScheme { get; set; } + public AssemblyVersioningScheme? AssemblyVersioningScheme { get; set; } [YamlMember(Alias = "mode")] public VersioningMode? VersioningMode { get; set; } diff --git a/src/GitVersionCore/Configuration/ConfigurationProvider.cs b/src/GitVersionCore/Configuration/ConfigurationProvider.cs index ee321ca371..914f32875b 100644 --- a/src/GitVersionCore/Configuration/ConfigurationProvider.cs +++ b/src/GitVersionCore/Configuration/ConfigurationProvider.cs @@ -1,13 +1,84 @@ namespace GitVersion { using System.IO; + using System.Linq; using System.Text; using GitVersion.Configuration.Init.Wizard; using GitVersion.Helpers; public class ConfigurationProvider { - public static Config Provide(string workingDirectory, IFileSystem fileSystem) + internal const string DefaultTagPrefix = "[vV]"; + + public static Config Provide(string workingDirectory, IFileSystem fileSystem, bool applyDefaults = true) + { + var readConfig = ReadConfig(workingDirectory, fileSystem); + if (applyDefaults) + ApplyDefaultsTo(readConfig); + return readConfig; + } + + public static void ApplyDefaultsTo(Config config) + { + config.AssemblyVersioningScheme = config.AssemblyVersioningScheme ?? AssemblyVersioningScheme.MajorMinorPatch; + config.TagPrefix = config.TagPrefix ?? DefaultTagPrefix; + config.VersioningMode = config.VersioningMode ?? VersioningMode.ContinuousDelivery; + config.ContinuousDeploymentFallbackTag = config.ContinuousDeploymentFallbackTag ?? "ci"; + var configBranches = config.Branches.ToList(); + + ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, "master"), defaultTag: string.Empty, defaultPreventIncrement: true); + ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, "release[/-]"), defaultTag: "beta", defaultPreventIncrement: true); + ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, "feature[/-]"), defaultIncrementStrategy: IncrementStrategy.Inherit); + ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, @"(pull|pull\-requests|pr)[/-]"), + defaultTag: "PullRequest", + defaultTagNumberPattern: @"[/-](?\d+)[-/]", + defaultIncrementStrategy: IncrementStrategy.Inherit); + ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, "hotfix[/-]"), defaultTag: "beta"); + ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, "support[/-]"), defaultTag: string.Empty, defaultPreventIncrement: true); + ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, "develop"), + defaultTag: "unstable", + defaultIncrementStrategy: IncrementStrategy.Minor, + defaultVersioningMode: VersioningMode.ContinuousDeployment, + defaultTrackMergeTarget: true); + + // Any user defined branches should have other values defaulted after known branches filled in + // This allows users to override one value of + foreach (var branchConfig in configBranches) + { + ApplyBranchDefaults(config, branchConfig.Value); + } + } + + static BranchConfig GetOrCreateBranchDefaults(Config config, string branch) + { + if (!config.Branches.ContainsKey(branch)) + { + var branchConfig = new BranchConfig(); + config.Branches.Add(branch, branchConfig); + return branchConfig; + } + + return config.Branches[branch]; + } + + public static void ApplyBranchDefaults(Config config, + BranchConfig branchConfig, + string defaultTag = "useBranchName", + IncrementStrategy defaultIncrementStrategy = IncrementStrategy.Patch, + bool defaultPreventIncrement = false, + VersioningMode? defaultVersioningMode = null, // Looked up from main config + bool defaultTrackMergeTarget = false, + string defaultTagNumberPattern = null) + { + branchConfig.Tag = branchConfig.Tag ?? defaultTag; + branchConfig.TagNumberPattern = branchConfig.TagNumberPattern ?? defaultTagNumberPattern; + branchConfig.Increment = branchConfig.Increment ?? defaultIncrementStrategy; + branchConfig.PreventIncrementOfMergedBranchVersion = branchConfig.PreventIncrementOfMergedBranchVersion ?? defaultPreventIncrement; + branchConfig.TrackMergeTarget = branchConfig.TrackMergeTarget ?? defaultTrackMergeTarget; + branchConfig.VersioningMode = branchConfig.VersioningMode ?? defaultVersioningMode ?? config.VersioningMode; + } + + static Config ReadConfig(string workingDirectory, IFileSystem fileSystem) { var configFilePath = GetConfigFilePath(workingDirectory); @@ -39,10 +110,11 @@ static string GetConfigFilePath(string workingDirectory) return Path.Combine(workingDirectory, "GitVersionConfig.yaml"); } - public static void Init(string workingDirectory, IFileSystem fileSystem) + public static void Init(string workingDirectory, IFileSystem fileSystem, IConsole console) { var configFilePath = GetConfigFilePath(workingDirectory); - var config = new ConfigInitWizard().Run(Provide(workingDirectory, fileSystem), workingDirectory, fileSystem); + var currentConfiguration = Provide(workingDirectory, fileSystem, applyDefaults: false); + var config = new ConfigInitWizard(console, fileSystem).Run(currentConfiguration, workingDirectory); if (config == null) return; using (var stream = fileSystem.OpenWrite(configFilePath)) diff --git a/src/GitVersionCore/Configuration/ConsoleAdapter.cs b/src/GitVersionCore/Configuration/ConsoleAdapter.cs new file mode 100644 index 0000000000..4270a56ace --- /dev/null +++ b/src/GitVersionCore/Configuration/ConsoleAdapter.cs @@ -0,0 +1,50 @@ +namespace GitVersion +{ + using System; + + class ConsoleAdapter : IConsole + { + public void WriteLine(string msg) + { + throw new NotImplementedException(); + } + + public void WriteLine() + { + throw new NotImplementedException(); + } + + public void Write(string msg) + { + throw new NotImplementedException(); + } + + public string ReadLine() + { + throw new NotImplementedException(); + } + + public IDisposable UseColor(ConsoleColor consoleColor) + { + var old = Console.ForegroundColor; + Console.ForegroundColor = consoleColor; + + return new DelegateDisposable(() => Console.ForegroundColor = old); + } + + class DelegateDisposable : IDisposable + { + readonly Action dispose; + + public DelegateDisposable(Action dispose) + { + this.dispose = dispose; + } + + public void Dispose() + { + dispose(); + } + } + } +} \ No newline at end of file diff --git a/src/GitVersionCore/Configuration/IConsole.cs b/src/GitVersionCore/Configuration/IConsole.cs new file mode 100644 index 0000000000..f42b767387 --- /dev/null +++ b/src/GitVersionCore/Configuration/IConsole.cs @@ -0,0 +1,13 @@ +namespace GitVersion +{ + using System; + + public interface IConsole + { + void WriteLine(string msg); + void WriteLine(); + void Write(string msg); + string ReadLine(); + IDisposable UseColor(ConsoleColor consoleColor); + } +} \ No newline at end of file diff --git a/src/GitVersionCore/Configuration/Init/BuildServer/AppVeyorSetup.cs b/src/GitVersionCore/Configuration/Init/BuildServer/AppVeyorSetup.cs index 289d664dcb..b443d4dead 100644 --- a/src/GitVersionCore/Configuration/Init/BuildServer/AppVeyorSetup.cs +++ b/src/GitVersionCore/Configuration/Init/BuildServer/AppVeyorSetup.cs @@ -9,28 +9,32 @@ namespace GitVersion.Configuration.Init.BuildServer class AppVeyorSetup : ConfigInitWizardStep { - protected override StepResult HandleResult(string result, Queue steps, Config config, string workingDirectory, IFileSystem fileSystem) + public AppVeyorSetup(IConsole console, IFileSystem fileSystem) : base(console, fileSystem) + { + } + + protected override StepResult HandleResult(string result, Queue steps, Config config, string workingDirectory) { switch (result) { case "0": - steps.Enqueue(new EditConfigStep()); + steps.Enqueue(new EditConfigStep(Console, FileSystem)); return StepResult.Ok(); case "1": - GenerateBasicConfig(workingDirectory, fileSystem); - steps.Enqueue(new EditConfigStep()); + GenerateBasicConfig(workingDirectory); + steps.Enqueue(new EditConfigStep(Console, FileSystem)); return StepResult.Ok(); case "2": - GenerateNuGetConfig(workingDirectory, fileSystem); - steps.Enqueue(new EditConfigStep()); + GenerateNuGetConfig(workingDirectory); + steps.Enqueue(new EditConfigStep(Console, FileSystem)); return StepResult.Ok(); } return StepResult.InvalidResponseSelected(); } - void GenerateBasicConfig(string workingDirectory, IFileSystem fileSystem) + void GenerateBasicConfig(string workingDirectory) { - WriteConfig(workingDirectory, fileSystem, @"install: + WriteConfig(workingDirectory, FileSystem, @"install: - choco install gitversion.portable -pre -y before_build: @@ -41,9 +45,9 @@ void GenerateBasicConfig(string workingDirectory, IFileSystem fileSystem) project: "); } - void GenerateNuGetConfig(string workingDirectory, IFileSystem fileSystem) + void GenerateNuGetConfig(string workingDirectory) { - WriteConfig(workingDirectory, fileSystem, @"install: + WriteConfig(workingDirectory, FileSystem, @"install: - choco install gitversion.portable -pre -y assembly_info: @@ -69,10 +73,10 @@ void WriteConfig(string workingDirectory, IFileSystem fileSystem, string configC Logger.WriteInfo(string.Format("AppVeyor sample config file written to {0}", outputFilename)); } - protected override string GetPrompt(Config config, string workingDirectory, IFileSystem fileSystem) + protected override string GetPrompt(Config config, string workingDirectory) { var prompt = new StringBuilder(); - if (AppVeyorConfigExists(workingDirectory, fileSystem)) + if (AppVeyorConfigExists(workingDirectory, FileSystem)) { prompt.AppendLine("GitVersion doesn't support modifying existing appveyor config files. We will generate appveyor.gitversion.yml instead"); prompt.AppendLine(); diff --git a/src/GitVersionCore/Configuration/Init/BuildServer/SetupBuildScripts.cs b/src/GitVersionCore/Configuration/Init/BuildServer/SetupBuildScripts.cs index 1847dc4df0..272a6e2af6 100644 --- a/src/GitVersionCore/Configuration/Init/BuildServer/SetupBuildScripts.cs +++ b/src/GitVersionCore/Configuration/Init/BuildServer/SetupBuildScripts.cs @@ -6,21 +6,25 @@ class SetupBuildScripts : ConfigInitWizardStep { - protected override StepResult HandleResult(string result, Queue steps, Config config, string workingDirectory, IFileSystem fileSystem) + public SetupBuildScripts(IConsole console, IFileSystem fileSystem) : base(console, fileSystem) + { + } + + protected override StepResult HandleResult(string result, Queue steps, Config config, string workingDirectory) { switch (result) { case "0": - steps.Enqueue(new EditConfigStep()); + steps.Enqueue(new EditConfigStep(Console, FileSystem)); return StepResult.Ok(); case "1": - steps.Enqueue(new AppVeyorSetup()); + steps.Enqueue(new AppVeyorSetup(Console, FileSystem)); return StepResult.Ok(); } return StepResult.Ok(); } - protected override string GetPrompt(Config config, string workingDirectory, IFileSystem fileSystem) + protected override string GetPrompt(Config config, string workingDirectory) { return @"What build server are you using? diff --git a/src/GitVersionCore/Configuration/Init/EditConfigStep.cs b/src/GitVersionCore/Configuration/Init/EditConfigStep.cs index dc7bf362eb..784fa13607 100644 --- a/src/GitVersionCore/Configuration/Init/EditConfigStep.cs +++ b/src/GitVersionCore/Configuration/Init/EditConfigStep.cs @@ -8,7 +8,11 @@ namespace GitVersion.Configuration.Init public class EditConfigStep : ConfigInitWizardStep { - protected override StepResult HandleResult(string result, Queue steps, Config config, string workingDirectory, IFileSystem fileSystem) + public EditConfigStep(IConsole console, IFileSystem fileSystem) : base(console, fileSystem) + { + } + + protected override StepResult HandleResult(string result, Queue steps, Config config, string workingDirectory) { switch (result) { @@ -18,30 +22,30 @@ protected override StepResult HandleResult(string result, Queue steps, Config config, string workingDirectory, IFileSystem fileSystem) + public AssemblyVersioningSchemeSetting(IConsole console, IFileSystem fileSystem) : base(console, fileSystem) + { + } + + protected override StepResult HandleResult(string result, Queue steps, Config config, string workingDirectory) { switch (result) { case "0": - steps.Enqueue(new EditConfigStep()); + steps.Enqueue(new EditConfigStep(Console, FileSystem)); return StepResult.Ok(); case "1": config.AssemblyVersioningScheme = AssemblyVersioningScheme.Major; - steps.Enqueue(new EditConfigStep()); + steps.Enqueue(new EditConfigStep(Console, FileSystem)); return StepResult.Ok(); case "2": config.AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinor; - steps.Enqueue(new EditConfigStep()); + steps.Enqueue(new EditConfigStep(Console, FileSystem)); return StepResult.Ok(); case "3": config.AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatch; - steps.Enqueue(new EditConfigStep()); + steps.Enqueue(new EditConfigStep(Console, FileSystem)); return StepResult.Ok(); case "4": config.AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatchTag; - steps.Enqueue(new EditConfigStep()); + steps.Enqueue(new EditConfigStep(Console, FileSystem)); return StepResult.Ok(); } return StepResult.InvalidResponseSelected(); } - protected override string GetPrompt(Config config, string workingDirectory, IFileSystem fileSystem) + protected override string GetPrompt(Config config, string workingDirectory) { return @"What assembly versioning scheme do you want to use: diff --git a/src/GitVersionCore/Configuration/Init/SetConfig/ConfigureBranch.cs b/src/GitVersionCore/Configuration/Init/SetConfig/ConfigureBranch.cs index 6148f5bfae..dd16f83eb9 100644 --- a/src/GitVersionCore/Configuration/Init/SetConfig/ConfigureBranch.cs +++ b/src/GitVersionCore/Configuration/Init/SetConfig/ConfigureBranch.cs @@ -9,31 +9,32 @@ public class ConfigureBranch : ConfigInitWizardStep string name; readonly BranchConfig branchConfig; - public ConfigureBranch(string name, BranchConfig branchConfig) + public ConfigureBranch(string name, BranchConfig branchConfig, IConsole console, IFileSystem fileSystem) + : base(console, fileSystem) { this.branchConfig = branchConfig; this.name = name; } - protected override StepResult HandleResult(string result, Queue steps, Config config, string workingDirectory, IFileSystem fileSystem) + protected override StepResult HandleResult(string result, Queue steps, Config config, string workingDirectory) { switch (result) { case "0": - steps.Enqueue(new ConfigureBranches()); + steps.Enqueue(new ConfigureBranches(Console, FileSystem)); return StepResult.Ok(); case "1": - steps.Enqueue(new SetBranchTag(name, branchConfig)); + steps.Enqueue(new SetBranchTag(name, branchConfig, Console, FileSystem)); return StepResult.Ok(); case "2": - steps.Enqueue(new SetBranchIncrementMode(name, branchConfig)); + steps.Enqueue(new SetBranchIncrementMode(name, branchConfig, Console, FileSystem)); return StepResult.Ok(); } return StepResult.InvalidResponseSelected(); } - protected override string GetPrompt(Config config, string workingDirectory, IFileSystem fileSystem) + protected override string GetPrompt(Config config, string workingDirectory) { return string.Format(@"What would you like to change for '{0}': diff --git a/src/GitVersionCore/Configuration/Init/SetConfig/ConfigureBranches.cs b/src/GitVersionCore/Configuration/Init/SetConfig/ConfigureBranches.cs index 140a9269e6..adef9ad78c 100644 --- a/src/GitVersionCore/Configuration/Init/SetConfig/ConfigureBranches.cs +++ b/src/GitVersionCore/Configuration/Init/SetConfig/ConfigureBranches.cs @@ -8,21 +8,25 @@ namespace GitVersion.Configuration.Init.SetConfig public class ConfigureBranches : ConfigInitWizardStep { - protected override StepResult HandleResult(string result, Queue steps, Config config, string workingDirectory, IFileSystem fileSystem) + public ConfigureBranches(IConsole console, IFileSystem fileSystem) : base(console, fileSystem) + { + } + + protected override StepResult HandleResult(string result, Queue steps, Config config, string workingDirectory) { int parsed; if (int.TryParse(result, out parsed)) { if (parsed == 0) { - steps.Enqueue(new EditConfigStep()); + steps.Enqueue(new EditConfigStep(Console, FileSystem)); return StepResult.Ok(); } try { var foundBranch = OrderedBranches(config).ElementAt(parsed - 1); - steps.Enqueue(new ConfigureBranch(foundBranch.Key, foundBranch.Value)); + steps.Enqueue(new ConfigureBranch(foundBranch.Key, foundBranch.Value, Console, FileSystem)); return StepResult.Ok(); } catch (ArgumentOutOfRangeException) @@ -32,7 +36,7 @@ protected override StepResult HandleResult(string result, Queue steps, Config config, string workingDirectory, IFileSystem fileSystem) + protected override StepResult HandleResult(string result, Queue steps, Config config, string workingDirectory) { switch (result) { @@ -36,7 +37,7 @@ protected override StepResult HandleResult(string result, Queue steps, Config config, string workingDirectory, IFileSystem fileSystem) + protected override StepResult HandleResult(string result, Queue steps, Config config, string workingDirectory) { switch (result) { case "0": - steps.Enqueue(new ConfigureBranch(name, branchConfig)); + steps.Enqueue(new ConfigureBranch(name, branchConfig, Console, FileSystem)); return StepResult.Ok(); case "1": branchConfig.VersioningMode = VersioningMode.ContinuousDelivery; - steps.Enqueue(new ConfigureBranch(name, branchConfig)); + steps.Enqueue(new ConfigureBranch(name, branchConfig, Console, FileSystem)); return StepResult.Ok(); case "2": branchConfig.VersioningMode = VersioningMode.ContinuousDeployment; - steps.Enqueue(new ConfigureBranch(name, branchConfig)); + steps.Enqueue(new ConfigureBranch(name, branchConfig, Console, FileSystem)); return StepResult.Ok(); } return StepResult.InvalidResponseSelected(); } - protected override string GetPrompt(Config config, string workingDirectory, IFileSystem fileSystem) + protected override string GetPrompt(Config config, string workingDirectory) { return string.Format(@"What do you want the increment mode for {0} to be? diff --git a/src/GitVersionCore/Configuration/Init/SetConfig/SetBranchTag.cs b/src/GitVersionCore/Configuration/Init/SetConfig/SetBranchTag.cs index 19cb304d7f..0d93438cd8 100644 --- a/src/GitVersionCore/Configuration/Init/SetConfig/SetBranchTag.cs +++ b/src/GitVersionCore/Configuration/Init/SetConfig/SetBranchTag.cs @@ -9,13 +9,14 @@ public class SetBranchTag : ConfigInitWizardStep string name; readonly BranchConfig branchConfig; - public SetBranchTag(string name, BranchConfig branchConfig) + public SetBranchTag(string name, BranchConfig branchConfig, IConsole console, IFileSystem fileSystem) + : base(console, fileSystem) { this.name = name; this.branchConfig = branchConfig; } - protected override StepResult HandleResult(string result, Queue steps, Config config, string workingDirectory, IFileSystem fileSystem) + protected override StepResult HandleResult(string result, Queue steps, Config config, string workingDirectory) { if (string.IsNullOrWhiteSpace(result)) { @@ -25,20 +26,20 @@ protected override StepResult HandleResult(string result, Queue steps, Config config, string workingDirectory, IFileSystem fileSystem) + public SetNextVersion(IConsole console, IFileSystem fileSystem) : base(console, fileSystem) + { + } + + protected override StepResult HandleResult(string result, Queue steps, Config config, string workingDirectory) { if (string.IsNullOrEmpty(result)) { - steps.Enqueue(new EditConfigStep()); + steps.Enqueue(new EditConfigStep(Console, FileSystem)); return StepResult.Ok(); } @@ -19,18 +23,18 @@ protected override StepResult HandleResult(string result, Queue(); - steps.Enqueue(new EditConfigStep()); + steps.Enqueue(new EditConfigStep(console, fileSystem)); while (steps.Count > 0) { var currentStep = steps.Dequeue(); - if (!currentStep.Apply(steps, config, workingDirectory, fileSystem)) + if (!currentStep.Apply(steps, config, workingDirectory)) { return null; } diff --git a/src/GitVersionCore/Configuration/Init/Wizard/ConfigInitWizardStep.cs b/src/GitVersionCore/Configuration/Init/Wizard/ConfigInitWizardStep.cs index 663a383f77..d0615eeb0f 100644 --- a/src/GitVersionCore/Configuration/Init/Wizard/ConfigInitWizardStep.cs +++ b/src/GitVersionCore/Configuration/Init/Wizard/ConfigInitWizardStep.cs @@ -6,10 +6,20 @@ namespace GitVersion.Configuration.Init.Wizard public abstract class ConfigInitWizardStep { - public bool Apply(Queue steps, Config config, string workingDirectory, IFileSystem fileSystem) + protected ConfigInitWizardStep(IConsole console, IFileSystem fileSystem) + { + Console = console; + FileSystem = fileSystem; + } + + protected IConsole Console { get; private set; } + + protected IFileSystem FileSystem { get; private set; } + + public bool Apply(Queue steps, Config config, string workingDirectory) { Console.WriteLine(); - Console.WriteLine(GetPrompt(config, workingDirectory, fileSystem)); + Console.WriteLine(GetPrompt(config, workingDirectory)); Console.WriteLine(); Console.Write("> "); var input = Console.ReadLine(); @@ -28,7 +38,7 @@ public bool Apply(Queue steps, Config config, string worki return true; } var resultWithDefaultApplied = string.IsNullOrEmpty(input) ? DefaultResult : input; - var stepResult = HandleResult(resultWithDefaultApplied, steps, config, workingDirectory, fileSystem); + var stepResult = HandleResult(resultWithDefaultApplied, steps, config, workingDirectory); if (stepResult.InvalidResponse) { InvalidResponse(steps); @@ -44,14 +54,16 @@ public bool Apply(Queue steps, Config config, string worki void InvalidResponse(Queue steps) { Console.WriteLine(); - Console.ForegroundColor = ConsoleColor.Red; + using (Console.UseColor(ConsoleColor.Red)) + { + + } Console.WriteLine("Invalid response!"); - Console.ResetColor(); steps.Enqueue(this); } - protected abstract StepResult HandleResult(string result, Queue steps, Config config, string workingDirectory, IFileSystem fileSystem); - protected abstract string GetPrompt(Config config, string workingDirectory, IFileSystem fileSystem); + protected abstract StepResult HandleResult(string result, Queue steps, Config config, string workingDirectory); + protected abstract string GetPrompt(Config config, string workingDirectory); protected abstract string DefaultResult { get; } } } \ No newline at end of file diff --git a/src/GitVersionCore/Configuration/Init/Wizard/FinishedSetupStep.cs b/src/GitVersionCore/Configuration/Init/Wizard/FinishedSetupStep.cs index cb47e26045..f5545c9328 100644 --- a/src/GitVersionCore/Configuration/Init/Wizard/FinishedSetupStep.cs +++ b/src/GitVersionCore/Configuration/Init/Wizard/FinishedSetupStep.cs @@ -4,9 +4,13 @@ namespace GitVersion.Configuration.Init.Wizard public class FinishedSetupStep : EditConfigStep { - protected override string GetPrompt(Config config, string workingDirectory, IFileSystem fileSystem) + public FinishedSetupStep(IConsole console, IFileSystem fileSystem) : base(console, fileSystem) { - return "Questions are all done, you can now edit GitVersion's configuration further\r\n" + base.GetPrompt(config, workingDirectory, fileSystem); + } + + protected override string GetPrompt(Config config, string workingDirectory) + { + return "Questions are all done, you can now edit GitVersion's configuration further\r\n" + base.GetPrompt(config, workingDirectory); } } } \ No newline at end of file diff --git a/src/GitVersionCore/Configuration/Init/Wizard/GitFlowSetupStep.cs b/src/GitVersionCore/Configuration/Init/Wizard/GitFlowSetupStep.cs index 0bc4a5043b..df3fd6c22a 100644 --- a/src/GitVersionCore/Configuration/Init/Wizard/GitFlowSetupStep.cs +++ b/src/GitVersionCore/Configuration/Init/Wizard/GitFlowSetupStep.cs @@ -5,14 +5,14 @@ namespace GitVersion.Configuration.Init.Wizard public class GitFlowSetupStep : GlobalModeSetting { - public GitFlowSetupStep() : base(new FinishedSetupStep(), true) + public GitFlowSetupStep(IConsole console, IFileSystem fileSystem) : base(new FinishedSetupStep(console, fileSystem), true, console, fileSystem) { } - protected override string GetPrompt(Config config, string workingDirectory, IFileSystem fileSystem) + protected override string GetPrompt(Config config, string workingDirectory) { return "By default GitVersion will only increment the version of the 'develop' branch every commit, all other branches will increment when tagged\r\n\r\n" + - base.GetPrompt(config, workingDirectory, fileSystem); + base.GetPrompt(config, workingDirectory); } } } \ No newline at end of file diff --git a/src/GitVersionCore/Configuration/Init/Wizard/GitHubFlowStep.cs b/src/GitVersionCore/Configuration/Init/Wizard/GitHubFlowStep.cs index ee276fbde7..89a083c9be 100644 --- a/src/GitVersionCore/Configuration/Init/Wizard/GitHubFlowStep.cs +++ b/src/GitVersionCore/Configuration/Init/Wizard/GitHubFlowStep.cs @@ -5,13 +5,13 @@ namespace GitVersion.Configuration.Init.Wizard public class GitHubFlowStep : GlobalModeSetting { - public GitHubFlowStep() : base(new FinishedSetupStep(), true) + public GitHubFlowStep(IConsole console, IFileSystem fileSystem) : base(new FinishedSetupStep(console, fileSystem), true, console, fileSystem) { } - protected override string GetPrompt(Config config, string workingDirectory, IFileSystem fileSystem) + protected override string GetPrompt(Config config, string workingDirectory) { - return "By default GitVersion will only increment the version when tagged\r\n\r\n" + base.GetPrompt(config, workingDirectory, fileSystem); + return "By default GitVersion will only increment the version when tagged\r\n\r\n" + base.GetPrompt(config, workingDirectory); } } } \ No newline at end of file diff --git a/src/GitVersionCore/Configuration/Init/Wizard/PickBranchingStrategy1Step.cs b/src/GitVersionCore/Configuration/Init/Wizard/PickBranchingStrategy1Step.cs index 22c953ff72..60ec0af31b 100644 --- a/src/GitVersionCore/Configuration/Init/Wizard/PickBranchingStrategy1Step.cs +++ b/src/GitVersionCore/Configuration/Init/Wizard/PickBranchingStrategy1Step.cs @@ -1,12 +1,15 @@ namespace GitVersion.Configuration.Init.Wizard { - using System; using System.Collections.Generic; using GitVersion.Helpers; public class PickBranchingStrategy1Step : ConfigInitWizardStep { - protected override StepResult HandleResult(string result, Queue steps, Config config, string workingDirectory, IFileSystem fileSystem) + public PickBranchingStrategy1Step(IConsole console, IFileSystem fileSystem) : base(console, fileSystem) + { + } + + protected override StepResult HandleResult(string result, Queue steps, Config config, string workingDirectory) { switch (result.ToLower()) { @@ -14,17 +17,17 @@ protected override StepResult HandleResult(string result, Queue steps, Config config, string workingDirectory, IFileSystem fileSystem) + public PickBranchingStrategy2Step(IConsole console, IFileSystem fileSystem) : base(console, fileSystem) + { + } + + protected override StepResult HandleResult(string result, Queue steps, Config config, string workingDirectory) { switch (result.ToLower()) { @@ -17,17 +20,17 @@ protected override StepResult HandleResult(string result, Queue steps, Config config, string workingDirectory, IFileSystem fileSystem) + public PickBranchingStrategy3Step(IConsole console, IFileSystem fileSystem) : base(console, fileSystem) + { + } + + protected override StepResult HandleResult(string result, Queue steps, Config config, string workingDirectory) { switch (result.ToLower()) { @@ -24,11 +27,11 @@ protected override StepResult HandleResult(string result, Queue steps, Config config, string workingDirectory, IFileSystem fileSystem) + public PickBranchingStrategyStep(IConsole console, IFileSystem fileSystem) : base(console, fileSystem) + { + } + + protected override StepResult HandleResult(string result, Queue steps, Config config, string workingDirectory) { switch (result) { case "1": - steps.Enqueue(new GitFlowSetupStep()); + steps.Enqueue(new GitFlowSetupStep(Console, FileSystem)); break; case "2": - steps.Enqueue(new GitHubFlowStep()); + steps.Enqueue(new GitHubFlowStep(Console, FileSystem)); break; case "3": - steps.Enqueue(new PickBranchingStrategy1Step()); + steps.Enqueue(new PickBranchingStrategy1Step(Console, FileSystem)); break; default: return StepResult.InvalidResponseSelected(); @@ -25,7 +29,7 @@ protected override StepResult HandleResult(string result, Queue + + diff --git a/src/GitVersionCore/GitVersionFinder.cs b/src/GitVersionCore/GitVersionFinder.cs index 36d49321a8..893228020c 100644 --- a/src/GitVersionCore/GitVersionFinder.cs +++ b/src/GitVersionCore/GitVersionFinder.cs @@ -1,6 +1,5 @@ namespace GitVersion { - using System; using System.IO; using System.Linq; using GitVersion.VersionCalculation; @@ -16,7 +15,7 @@ public SemanticVersion FindVersion(GitVersionContext context) var filePath = Path.Combine(context.Repository.GetRepositoryDirectory(), "NextVersion.txt"); if (File.Exists(filePath)) { - throw new Exception("NextVersion.txt has been depreciated. See https://github.com/ParticularLabs/GitVersion/wiki/GitVersionConfig.yaml-Configuration-File for replacement"); + throw new WarningException("NextVersion.txt has been depreciated. See http://gitversion.readthedocs.org/en/latest/configuration/ for replacement"); } return new NextVersionCalculator().FindVersion(context); @@ -25,7 +24,6 @@ public SemanticVersion FindVersion(GitVersionContext context) void EnsureMainTopologyConstraints(GitVersionContext context) { EnsureLocalBranchExists(context.Repository, "master"); - // TODO somehow enforce this? EnsureLocalBranchExists(context.Repository, "develop"); EnsureHeadIsNotDetached(context); } @@ -36,7 +34,10 @@ void EnsureHeadIsNotDetached(GitVersionContext context) return; } - var message = string.Format("It looks like the branch being examined is a detached Head pointing to commit '{0}'. Without a proper branch name GitVersion cannot determine the build version.", context.CurrentCommit.Id.ToString(7)); + var message = string.Format( + "It looks like the branch being examined is a detached Head pointing to commit '{0}'. " + + "Without a proper branch name GitVersion cannot determine the build version.", + context.CurrentCommit.Id.ToString(7)); throw new WarningException(message); } diff --git a/src/GitVersionCore/SemanticVersion.cs b/src/GitVersionCore/SemanticVersion.cs index 8f51b044ee..44775a82f4 100644 --- a/src/GitVersionCore/SemanticVersion.cs +++ b/src/GitVersionCore/SemanticVersion.cs @@ -258,6 +258,8 @@ public string ToString(string format, IFormatProvider formatProvider = null) return string.Format("{0}.{1}.{2}", Major, Minor, Patch); case "s": return PreReleaseTag.HasTag() ? string.Format("{0}-{1}", ToString("j"), PreReleaseTag) : ToString("j"); + case "t": + return PreReleaseTag.HasTag() ? string.Format("{0}-{1}", ToString("j"), PreReleaseTag.ToString("t")) : ToString("j"); case "l": return PreReleaseTag.HasTag() ? string.Format("{0}-{1}", ToString("j"), PreReleaseTag.ToString("l")) : ToString("j"); case "lp": diff --git a/src/GitVersionExe.Tests/AssemblyInfoFileUpdateTests.cs b/src/GitVersionExe.Tests/AssemblyInfoFileUpdateTests.cs index 2467e903a9..18b9dd15e4 100644 --- a/src/GitVersionExe.Tests/AssemblyInfoFileUpdateTests.cs +++ b/src/GitVersionExe.Tests/AssemblyInfoFileUpdateTests.cs @@ -39,11 +39,7 @@ public void ShouldReplaceAssemblyVersion() fileSystem.Exists("C:\\Testing\\AssemblyInfo.cs").Returns(true); fileSystem.ReadAllText("C:\\Testing\\AssemblyInfo.cs").Returns(assemblyInfoFile); - var config = new Config - { - AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinor - }; - var variable = VariableProvider.GetVariablesFor(version, config.AssemblyVersioningScheme, VersioningMode.ContinuousDelivery, "ci", false); + var variable = VariableProvider.GetVariablesFor(version, AssemblyVersioningScheme.MajorMinor, VersioningMode.ContinuousDelivery, "ci", false); var args = new Arguments { UpdateAssemblyInfo = true, @@ -77,11 +73,7 @@ public void ShouldReplaceAssemblyVersionWithStar() fileSystem.Exists("C:\\Testing\\AssemblyInfo.cs").Returns(true); fileSystem.ReadAllText("C:\\Testing\\AssemblyInfo.cs").Returns(assemblyInfoFile); - var config = new Config - { - AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinor - }; - var variable = VariableProvider.GetVariablesFor(version, config.AssemblyVersioningScheme, VersioningMode.ContinuousDelivery, "ci", false); + var variable = VariableProvider.GetVariablesFor(version, AssemblyVersioningScheme.MajorMinor, VersioningMode.ContinuousDelivery, "ci", false); var args = new Arguments { UpdateAssemblyInfo = true, diff --git a/src/GitVersionExe/Program.cs b/src/GitVersionExe/Program.cs index b800700cc9..d6a20c44a9 100644 --- a/src/GitVersionExe/Program.cs +++ b/src/GitVersionExe/Program.cs @@ -71,7 +71,7 @@ static int VerifyArgumentsAndRun() ConfigureLogging(arguments); if (arguments.Init) { - ConfigurationProvider.Init(arguments.TargetPath, fileSystem); + ConfigurationProvider.Init(arguments.TargetPath, fileSystem, new ConsoleAdapter()); return 0; } if (arguments.ShowConfig)