diff --git a/BREAKING CHANGES.md b/BREAKING CHANGES.md index a2eced2b79..412d737cf9 100644 --- a/BREAKING CHANGES.md +++ b/BREAKING CHANGES.md @@ -1,3 +1,14 @@ +v4.0.0 + - When using GitFlow, a few things have changed. Hopefully the new settings just work for you + - develop has pre-release tag of `alpha` now, not unstable + - develop will bump as soon as a release branch is created + - Look at the [GitFlow examples](http://gitversion.readthedocs.io/en/latest/git-branching-strategies/gitflow-examples/) for details of how it works now + - Regex's are no longer used as keys in branch config + - We have named branches, and introduced a `regex` config which you can override. + - The default keys are: master, develop, feature, release, pull-request, hotfix, support + - Just run GitVersion.exe in your project directory and it will tell you what to change your config keys to + - For example, `dev(elop)?(ment)?$` is now just `develop`, we suggest not overring regex's unless you really want to use a different convention. + v3.0.0 - NextVersion.txt has been deprecated, only GitVersionConfig.yaml is supported - `AssemblyFileSemVer` variable removed, AssemblyVersioningScheme configuration value makes this variable obsolete diff --git a/docs/configuration.md b/docs/configuration.md index c720497cd9..e6b2ef0e1f 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -126,7 +126,21 @@ The header for ignore configuration. #### sha A sequence of SHAs to be excluded from the version calculations. Useful when -there is a rogue commit in history yielding a bad version. +there is a rogue commit in history yielding a bad version. You can use either style below: + +``` +ignore: + sha: [e7bc24c0f34728a25c9187b8d0b041d935763e3a, 764e16321318f2fdb9cdeaa56d1156a1cba307d7] +``` + +or + +``` +ignore: + sha: + - e7bc24c0f34728a25c9187b8d0b041d935763e3a + - 764e16321318f2fdb9cdeaa56d1156a1cba307d7 +``` #### commits-before Date and time in the format `yyyy-MM-ddTHH:mm:ss` (eg `commits-before: @@ -136,9 +150,14 @@ Date and time in the format `yyyy-MM-ddTHH:mm:ss` (eg `commits-before: ## Branch configuration Then we have branch specific configuration, which looks something like this: +**NOTE: ** v4 changed from using regexes for keys, to named configs + +If you have branch specific configuration upgrading to v4 will force you to upgrade. + ```yaml branches: master: + regex: master mode: ContinuousDelivery tag: '' increment: Patch @@ -146,7 +165,8 @@ branches: track-merge-target: false is-develop: false is-release-branch: false - releases?[/-]: + release: + regex: releases?[/-] mode: ContinuousDelivery tag: beta increment: Patch @@ -154,7 +174,8 @@ branches: track-merge-target: false is-develop: false is-release-branch: true - features?[/-]: + feature: + regex: features?[/-] mode: ContinuousDelivery tag: useBranchName increment: Inherit @@ -162,7 +183,8 @@ branches: track-merge-target: false is-develop: false is-release-branch: false - (pull|pull\-requests|pr)[/-]: + pull-request: + regex: (pull|pull\-requests|pr)[/-] mode: ContinuousDelivery tag: PullRequest increment: Inherit @@ -171,7 +193,8 @@ branches: track-merge-target: false is-develop: false is-release-branch: false - hotfix(es)?[/-]: + hotfix: + regex: hotfix(es)?[/-] mode: ContinuousDelivery tag: beta increment: Patch @@ -179,7 +202,8 @@ branches: track-merge-target: false is-develop: false is-release-branch: false - support[/-]: + support: + regex: support[/-] mode: ContinuousDelivery tag: '' increment: Patch @@ -187,7 +211,8 @@ branches: track-merge-target: false is-develop: false is-release-branch: false - dev(elop)?(ment)?$: + develop: + regex: dev(elop)?(ment)?$ mode: ContinuousDeployment tag: unstable increment: Minor @@ -197,9 +222,14 @@ branches: is-release-branch: false ``` +If you don't specify the regex the inbuilt for that branch config will be used (recommended) + We don't envision many people needing to change most of these configuration values, but here they are if you need to: +### regex +This is the regex which is used to match the current branch to the correct branch configuration. + ### branches The header for all the individual branch configuration. @@ -239,7 +269,7 @@ the branch is configured to use ContinuousDeployment mode. ```yaml branches: - (pull|pull\-requests|pr)[/-]: + pull-request: mode: ContinuousDeployment tag: PullRequest increment: Inherit diff --git a/src/GitVersionCore.Tests/ConfigProviderTests.CanWriteOutEffectiveConfiguration.approved.txt b/src/GitVersionCore.Tests/ConfigProviderTests.CanWriteOutEffectiveConfiguration.approved.txt index 8dbda75afd..72644c90b6 100644 --- a/src/GitVersionCore.Tests/ConfigProviderTests.CanWriteOutEffectiveConfiguration.approved.txt +++ b/src/GitVersionCore.Tests/ConfigProviderTests.CanWriteOutEffectiveConfiguration.approved.txt @@ -17,61 +17,68 @@ branches: increment: Patch prevent-increment-of-merged-branch-version: true track-merge-target: false + regex: master is-develop: false is-release-branch: false is-mainline: true - releases?[/-]: + release: mode: ContinuousDelivery tag: beta increment: Patch prevent-increment-of-merged-branch-version: true track-merge-target: false + regex: releases?[/-] is-develop: false is-release-branch: true is-mainline: false - features?[/-]: + feature: mode: ContinuousDelivery tag: useBranchName increment: Inherit prevent-increment-of-merged-branch-version: false track-merge-target: false + regex: features?[/-] is-develop: false is-release-branch: false is-mainline: false - (pull|pull\-requests|pr)[/-]: + pull-request: mode: ContinuousDelivery tag: PullRequest increment: Inherit prevent-increment-of-merged-branch-version: false tag-number-pattern: '[/-](?\d+)[-/]' track-merge-target: false + regex: (pull|pull\-requests|pr)[/-] is-develop: false is-release-branch: false is-mainline: false - hotfix(es)?[/-]: + hotfix: mode: ContinuousDelivery tag: beta increment: Patch prevent-increment-of-merged-branch-version: false track-merge-target: false + regex: hotfix(es)?[/-] is-develop: false is-release-branch: false is-mainline: false - support[/-]: + support: mode: ContinuousDelivery tag: '' increment: Patch prevent-increment-of-merged-branch-version: true track-merge-target: false + regex: support[/-] is-develop: false is-release-branch: false is-mainline: true - dev(elop)?(ment)?$: + develop: mode: ContinuousDeployment tag: alpha increment: Minor prevent-increment-of-merged-branch-version: false track-merge-target: true + regex: dev(elop)?(ment)?$ is-develop: true is-release-branch: false is-mainline: false diff --git a/src/GitVersionCore.Tests/ConfigProviderTests.cs b/src/GitVersionCore.Tests/ConfigProviderTests.cs index f7f1fc8d4f..32ec828b2d 100644 --- a/src/GitVersionCore.Tests/ConfigProviderTests.cs +++ b/src/GitVersionCore.Tests/ConfigProviderTests.cs @@ -29,46 +29,28 @@ public void Setup() } [Test] - public void CanReadDocumentAndMigrate() + public void CanReadOldDocument() { const string text = @" -assembly-versioning-scheme: MajorMinor -next-version: 2.0.0 -tag-prefix: '[vV|version-]' -mode: ContinuousDelivery +assemblyVersioningScheme: MajorMinor +develop-branch-tag: alpha +release-branch-tag: rc branches: - develop: + master: + mode: ContinuousDeployment + dev(elop)?(ment)?$: mode: ContinuousDeployment tag: dev release[/-]: mode: continuousDeployment - tag: rc -"; - SetupConfigFileContent(text); - - var config = ConfigurationProvider.Provide(repoPath, fileSystem); - config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinor); - config.AssemblyInformationalFormat.ShouldBe(null); - config.NextVersion.ShouldBe("2.0.0"); - config.TagPrefix.ShouldBe("[vV|version-]"); - config.VersioningMode.ShouldBe(VersioningMode.ContinuousDelivery); - config.Branches["dev(elop)?(ment)?$"].Tag.ShouldBe("dev"); - config.Branches["releases?[/-]"].Tag.ShouldBe("rc"); - config.Branches["releases?[/-]"].VersioningMode.ShouldBe(VersioningMode.ContinuousDeployment); - config.Branches["dev(elop)?(ment)?$"].VersioningMode.ShouldBe(VersioningMode.ContinuousDeployment); - } - - [Test] - public void CanReadOldDocument() - { - const string text = @" -assemblyVersioningScheme: MajorMinor -develop-branch-tag: alpha -release-branch-tag: rc + tag: rc "; SetupConfigFileContent(text); var error = Should.Throw(() => ConfigurationProvider.Provide(repoPath, fileSystem)); error.Message.ShouldContainWithoutWhitespace(@"GitVersion configuration file contains old configuration, please fix the following errors: +GitVersion branch configs no longer are keyed by regexes, update: + dev(elop)?(ment)?$ -> develop + release[/-] -> release assemblyVersioningScheme has been replaced by assembly-versioning-scheme 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"); @@ -81,16 +63,16 @@ public void OverwritesDefaultsWithProvidedConfig() const string text = @" next-version: 2.0.0 branches: - dev(elop)?(ment)?$: + develop: mode: ContinuousDeployment tag: dev"; SetupConfigFileContent(text); var config = ConfigurationProvider.Provide(repoPath, fileSystem); config.NextVersion.ShouldBe("2.0.0"); - config.Branches["dev(elop)?(ment)?$"].Increment.ShouldBe(defaultConfig.Branches["dev(elop)?(ment)?$"].Increment); - config.Branches["dev(elop)?(ment)?$"].VersioningMode.ShouldBe(defaultConfig.Branches["dev(elop)?(ment)?$"].VersioningMode); - config.Branches["dev(elop)?(ment)?$"].Tag.ShouldBe("dev"); + config.Branches["develop"].Increment.ShouldBe(defaultConfig.Branches["develop"].Increment); + config.Branches["develop"].VersioningMode.ShouldBe(defaultConfig.Branches["develop"].VersioningMode); + config.Branches["develop"].Tag.ShouldBe("dev"); } [Test] @@ -99,13 +81,26 @@ public void CanRemoveTag() const string text = @" next-version: 2.0.0 branches: - releases?[/-]: + release: tag: """""; SetupConfigFileContent(text); var config = ConfigurationProvider.Provide(repoPath, fileSystem); config.NextVersion.ShouldBe("2.0.0"); - config.Branches["releases?[/-]"].Tag.ShouldBe(string.Empty); + config.Branches["release"].Tag.ShouldBe(string.Empty); + } + + [Test] + public void RegexIsRequired() + { + const string text = @" +next-version: 2.0.0 +branches: + bug: + tag: bugfix"; + SetupConfigFileContent(text); + var ex = Should.Throw(() => ConfigurationProvider.Provide(repoPath, fileSystem)); + ex.Message.ShouldBe("Branch configuration 'bug' is missing required configuration 'regex'"); } [Test] @@ -114,12 +109,14 @@ public void CanProvideConfigForNewBranch() const string text = @" next-version: 2.0.0 branches: - bug[/-]: + bug: + regex: 'bug[/-]' tag: bugfix"; SetupConfigFileContent(text); var config = ConfigurationProvider.Provide(repoPath, fileSystem); - config.Branches["bug[/-]"].Tag.ShouldBe("bugfix"); + config.Branches["bug"].Regex.ShouldBe("bug[/-]"); + config.Branches["bug"].Tag.ShouldBe("bugfix"); } [Test] @@ -216,8 +213,8 @@ public void CanReadDefaultDocument() var config = ConfigurationProvider.Provide(repoPath, fileSystem); config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinorPatch); config.AssemblyInformationalFormat.ShouldBe(null); - config.Branches["dev(elop)?(ment)?$"].Tag.ShouldBe("alpha"); - config.Branches["releases?[/-]"].Tag.ShouldBe("beta"); + config.Branches["develop"].Tag.ShouldBe("alpha"); + config.Branches["release"].Tag.ShouldBe("beta"); config.TagPrefix.ShouldBe(ConfigurationProvider.DefaultTagPrefix); config.NextVersion.ShouldBe(null); } diff --git a/src/GitVersionCore.Tests/GitVersionContextTests.cs b/src/GitVersionCore.Tests/GitVersionContextTests.cs index d0413480ae..b5a567703a 100644 --- a/src/GitVersionCore.Tests/GitVersionContextTests.cs +++ b/src/GitVersionCore.Tests/GitVersionContextTests.cs @@ -40,7 +40,7 @@ public void UsesBranchSpecificConfigOverTopLevelDefaults() Branches = { { - "dev(elop)?(ment)?$", new BranchConfig + "develop", new BranchConfig { VersioningMode = VersioningMode.ContinuousDeployment, Tag = "alpha" @@ -69,8 +69,8 @@ public void CanFindParentBranchForInheritingIncrementStrategy() { Branches = { - { "dev(elop)?(ment)?$", new BranchConfig { Increment = IncrementStrategy.Major} }, - { "features?[/-]", new BranchConfig { Increment = IncrementStrategy.Inherit} } + { "develop", new BranchConfig { Increment = IncrementStrategy.Major} }, + { "feature", new BranchConfig { Increment = IncrementStrategy.Inherit} } } }.ApplyDefaults(); diff --git a/src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs b/src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs index 6310903f01..91c5ad2382 100644 --- a/src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs +++ b/src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs @@ -62,7 +62,7 @@ public void CanChangeDevelopTagViaConfig() Branches = { { - "dev(elop)?(ment)?$", new BranchConfig + "develop", new BranchConfig { Tag = "alpha" } @@ -128,7 +128,7 @@ public void CanHandleContinuousDelivery() { Branches = { - {"dev(elop)?(ment)?$", new BranchConfig + {"develop", new BranchConfig { VersioningMode = VersioningMode.ContinuousDelivery } diff --git a/src/GitVersionCore.Tests/IntegrationTests/FeatureBranchScenarios.cs b/src/GitVersionCore.Tests/IntegrationTests/FeatureBranchScenarios.cs index d078218c69..3e05956b49 100644 --- a/src/GitVersionCore.Tests/IntegrationTests/FeatureBranchScenarios.cs +++ b/src/GitVersionCore.Tests/IntegrationTests/FeatureBranchScenarios.cs @@ -41,7 +41,7 @@ public void BranchCreatedAfterFastForwardMergeShouldInheritCorrectly() { Branches = { - { "unstable", new BranchConfig { Increment = IncrementStrategy.Minor } } + { "unstable", new BranchConfig { Increment = IncrementStrategy.Minor, Regex = "unstable"} } } }; @@ -183,7 +183,7 @@ public void ShouldUseConfiguredTag(string tag, string featureName, string preRel { Branches = { - { "features?[/-]", new BranchConfig { Tag = tag } } + { "feature", new BranchConfig { Tag = tag } } } }; diff --git a/src/GitVersionCore.Tests/IntegrationTests/OtherScenarios.cs b/src/GitVersionCore.Tests/IntegrationTests/OtherScenarios.cs index f4872407f7..d8b63e3699 100644 --- a/src/GitVersionCore.Tests/IntegrationTests/OtherScenarios.cs +++ b/src/GitVersionCore.Tests/IntegrationTests/OtherScenarios.cs @@ -49,8 +49,9 @@ public void AllowNotHavingMaster() public void AllowHavingMainInsteadOfMaster() { var config = new Config(); - config.Branches.Add("main", new BranchConfig + config.Branches.Add("master", new BranchConfig { + Regex = "main", VersioningMode = VersioningMode.ContinuousDelivery, Tag = "useBranchName", Increment = IncrementStrategy.Patch, diff --git a/src/GitVersionCore.Tests/IntegrationTests/ReleaseBranchScenarios.cs b/src/GitVersionCore.Tests/IntegrationTests/ReleaseBranchScenarios.cs index f7009c6db7..e091068c0a 100644 --- a/src/GitVersionCore.Tests/IntegrationTests/ReleaseBranchScenarios.cs +++ b/src/GitVersionCore.Tests/IntegrationTests/ReleaseBranchScenarios.cs @@ -113,7 +113,7 @@ public void CanTakeVersionFromReleaseBranchWithTagOverridden() { Branches = { - { "releases?[/-]", new BranchConfig { Tag = "rc" } } + { "release", new BranchConfig { Tag = "rc" } } } }; using (var fixture = new EmptyRepositoryFixture()) diff --git a/src/GitVersionCore.Tests/VersionCalculation/NextVersionCalculatorTests.cs b/src/GitVersionCore.Tests/VersionCalculation/NextVersionCalculatorTests.cs index a236d4e517..7e73edd311 100644 --- a/src/GitVersionCore.Tests/VersionCalculation/NextVersionCalculatorTests.cs +++ b/src/GitVersionCore.Tests/VersionCalculation/NextVersionCalculatorTests.cs @@ -62,8 +62,9 @@ public void PreReleaseTagCanUseBranchName() var semanticVersionBuildMetaData = new SemanticVersionBuildMetaData(2, "develop", "b1a34e", DateTimeOffset.Now); var sut = new NextVersionCalculator(baseCalculator, new TestMetaDataCalculator(semanticVersionBuildMetaData)); var config = new Config(); - config.Branches.Add("custom/", new BranchConfig + config.Branches.Add("custom", new BranchConfig { + Regex = "custom/", Tag = "useBranchName" }); var context = new GitVersionContextBuilder() @@ -84,8 +85,9 @@ public void PreReleaseTagCanUseBranchNameVariable() var semanticVersionBuildMetaData = new SemanticVersionBuildMetaData(2, "develop", "b1a34e", DateTimeOffset.Now); var sut = new NextVersionCalculator(baseCalculator, new TestMetaDataCalculator(semanticVersionBuildMetaData)); var config = new Config(); - config.Branches.Add("custom/", new BranchConfig + config.Branches.Add("custom", new BranchConfig { + Regex = "custom/", Tag = "alpha.{BranchName}" }); var context = new GitVersionContextBuilder() diff --git a/src/GitVersionCore/BranchConfigurationCalculator.cs b/src/GitVersionCore/BranchConfigurationCalculator.cs index e04723b0bf..f8a10ba196 100644 --- a/src/GitVersionCore/BranchConfigurationCalculator.cs +++ b/src/GitVersionCore/BranchConfigurationCalculator.cs @@ -17,8 +17,12 @@ public static KeyValuePair GetBranchConfiguration(Commit c if (matchingBranches.Length == 0) { + Logger.WriteInfo(string.Format( + "No branch configuration found for branch {0}, falling back to default configuration", + currentBranch.FriendlyName)); + var branchConfig = new BranchConfig(); - ConfigurationProvider.ApplyBranchDefaults(config, branchConfig); + ConfigurationProvider.ApplyBranchDefaults(config, branchConfig, ""); return new KeyValuePair(string.Empty, branchConfig); } if (matchingBranches.Length == 1) @@ -49,8 +53,8 @@ static KeyValuePair[] LookupBranchConfiguration([NotNull] { throw new ArgumentNullException("currentBranch"); } - - return config.Branches.Where(b => Regex.IsMatch(currentBranch.FriendlyName, "^" + b.Key, RegexOptions.IgnoreCase)).ToArray(); + + return config.Branches.Where(b => Regex.IsMatch(currentBranch.FriendlyName, "^" + b.Value.Regex, RegexOptions.IgnoreCase)).ToArray(); } diff --git a/src/GitVersionCore/Configuration/BranchConfig.cs b/src/GitVersionCore/Configuration/BranchConfig.cs index a437a5686a..b3abee74df 100644 --- a/src/GitVersionCore/Configuration/BranchConfig.cs +++ b/src/GitVersionCore/Configuration/BranchConfig.cs @@ -10,6 +10,7 @@ public BranchConfig() public BranchConfig(BranchConfig branchConfiguration) { + Regex = branchConfiguration.Regex; VersioningMode = branchConfiguration.VersioningMode; Tag = branchConfiguration.Tag; Increment = branchConfiguration.Increment; @@ -46,6 +47,9 @@ public BranchConfig(BranchConfig branchConfiguration) [YamlMember(Alias = "commit-message-incrementing")] public CommitMessageIncrementMode? CommitMessageIncrementing { get; set; } + [YamlMember(Alias = "regex")] + public string Regex { get; set; } + [YamlMember(Alias = "is-develop")] public bool? IsDevelop { get; set; } diff --git a/src/GitVersionCore/Configuration/Config.cs b/src/GitVersionCore/Configuration/Config.cs index dac4786940..f6e04af6e4 100644 --- a/src/GitVersionCore/Configuration/Config.cs +++ b/src/GitVersionCore/Configuration/Config.cs @@ -86,7 +86,7 @@ public Dictionary Branches } } - private T MergeObjects(T target, T source) + T MergeObjects(T target, T source) { typeof(T).GetProperties() .Where(prop => prop.CanRead && prop.CanWrite) diff --git a/src/GitVersionCore/Configuration/ConfigurationProvider.cs b/src/GitVersionCore/Configuration/ConfigurationProvider.cs index 1475aa8ece..59b9969419 100644 --- a/src/GitVersionCore/Configuration/ConfigurationProvider.cs +++ b/src/GitVersionCore/Configuration/ConfigurationProvider.cs @@ -1,12 +1,11 @@ namespace GitVersion { - using System; - using GitVersion.Configuration.Init.Wizard; + using Configuration.Init.Wizard; using GitVersion.Helpers; - using System.ComponentModel; using System.IO; using System.Linq; using System.Text; + using WarningException = System.ComponentModel.WarningException; public class ConfigurationProvider { @@ -15,6 +14,21 @@ public class ConfigurationProvider public const string DefaultConfigFileName = "GitVersion.yml"; public const string ObsoleteConfigFileName = "GitVersionConfig.yaml"; + public const string ReleaseBranchRegex = "releases?[/-]"; + public const string FeatureBranchRegex = "features?[/-]"; + public const string PullRequestRegex = @"(pull|pull\-requests|pr)[/-]"; + public const string HotfixBranchRegex = "hotfix(es)?[/-]"; + public const string SupportBranchRegex = "support[/-]"; + public const string DevelopBranchRegex = "dev(elop)?(ment)?$"; + public const string MasterBranchRegex = "master"; + public const string MasterBranchKey = "master"; + public const string ReleaseBranchKey = "release"; + public const string FeatureBranchKey = "feature"; + public const string PullRequestBranchKey = "pull-request"; + public const string HotfixBranchKey = "hotfix"; + public const string SupportBranchKey = "support"; + public const string DevelopBranchKey = "develop"; + public static Config Provide(GitPreparer gitPreparer, IFileSystem fileSystem, bool applyDefaults = true, Config overrideConfig = null) { var workingDirectory = gitPreparer.WorkingDirectory; @@ -58,7 +72,7 @@ static void VerifyConfiguration(Config readConfig) // Verify no branches are set to mainline mode if (readConfig.Branches.Any(b => b.Value.VersioningMode == VersioningMode.Mainline)) { - throw new Exception(@"Mainline mode only works at the repository level, a single branch cannot be put into mainline mode + throw new GitVersionConfigurationException(@"Mainline mode only works at the repository level, a single branch cannot be put into mainline mode This is because mainline mode treats your entire git repository as an event source with each merge into the 'mainline' incrementing the version. @@ -68,8 +82,6 @@ This is because mainline mode treats your entire git repository as an event sour public static void ApplyDefaultsTo(Config config) { - MigrateBranches(config); - config.AssemblyVersioningScheme = config.AssemblyVersioningScheme ?? AssemblyVersioningScheme.MajorMinorPatch; config.AssemblyInformationalFormat = config.AssemblyInformationalFormat; config.TagPrefix = config.TagPrefix ?? DefaultTagPrefix; @@ -86,22 +98,25 @@ public static void ApplyDefaultsTo(Config config) var configBranches = config.Branches.ToList(); - ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, "master"), + ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, MasterBranchKey), + MasterBranchRegex, defaultTag: string.Empty, defaultPreventIncrement: true, isMainline: true); - ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, "releases?[/-]"), defaultTag: "beta", defaultPreventIncrement: true, isReleaseBranch: true); - ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, "features?[/-]"), defaultIncrementStrategy: IncrementStrategy.Inherit); - ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, @"(pull|pull\-requests|pr)[/-]"), + ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, ReleaseBranchKey), ReleaseBranchRegex, defaultTag: "beta", defaultPreventIncrement: true, isReleaseBranch: true); + ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, FeatureBranchKey), FeatureBranchRegex, defaultIncrementStrategy: IncrementStrategy.Inherit); + ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, PullRequestBranchKey), PullRequestRegex, defaultTag: "PullRequest", defaultTagNumberPattern: @"[/-](?\d+)[-/]", defaultIncrementStrategy: IncrementStrategy.Inherit); - ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, "hotfix(es)?[/-]"), defaultTag: "beta"); - ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, "support[/-]"), + ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, HotfixBranchKey), HotfixBranchRegex, defaultTag: "beta"); + ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, SupportBranchKey), + SupportBranchRegex, defaultTag: string.Empty, defaultPreventIncrement: true, isMainline: true); - ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, "dev(elop)?(ment)?$"), + ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, DevelopBranchKey), + DevelopBranchRegex, defaultTag: "alpha", defaultIncrementStrategy: IncrementStrategy.Minor, defaultVersioningMode: VersioningMode.ContinuousDeployment, @@ -112,53 +127,36 @@ public static void ApplyDefaultsTo(Config config) // This allows users to override one value of foreach (var branchConfig in configBranches) { - ApplyBranchDefaults(config, branchConfig.Value); + var regex = branchConfig.Value.Regex; + if (regex == null) + { + throw new GitVersionConfigurationException(string.Format("Branch configuration '{0}' is missing required configuration 'regex'", branchConfig.Key)); + } + + ApplyBranchDefaults(config, branchConfig.Value, regex); } } - public static void ApplyOverridesTo(Config config, Config overrideConfig) + static void ApplyOverridesTo(Config config, Config overrideConfig) { config.TagPrefix = string.IsNullOrWhiteSpace(overrideConfig.TagPrefix) ? config.TagPrefix : overrideConfig.TagPrefix; } - static void MigrateBranches(Config config) - { - MigrateObsoleteBranches(config, "hotfix(es)?[/-]", "hotfix[/-]"); - MigrateObsoleteBranches(config, "features?[/-]", "feature[/-]", "feature(s)?[/-]"); - MigrateObsoleteBranches(config, "releases?[/-]", "release[/-]"); - MigrateObsoleteBranches(config, "dev(elop)?(ment)?$", "develop"); - } - - static void MigrateObsoleteBranches(Config config, string newBranch, params string[] obsoleteBranches) - { - foreach (var obsoleteBranch in obsoleteBranches) - { - if (!config.Branches.ContainsKey(obsoleteBranch)) - { - continue; - } - - // found one, rename - var bc = config.Branches[obsoleteBranch]; - config.Branches.Remove(obsoleteBranch); - config.Branches[newBranch] = bc; // re-add with new name - } - } - - static BranchConfig GetOrCreateBranchDefaults(Config config, string branch) + static BranchConfig GetOrCreateBranchDefaults(Config config, string branchKey) { - if (!config.Branches.ContainsKey(branch)) + if (!config.Branches.ContainsKey(branchKey)) { var branchConfig = new BranchConfig(); - config.Branches.Add(branch, branchConfig); + config.Branches.Add(branchKey, branchConfig); return branchConfig; } - return config.Branches[branch]; + return config.Branches[branchKey]; } public static void ApplyBranchDefaults(Config config, BranchConfig branchConfig, + string branchRegex, string defaultTag = "useBranchName", IncrementStrategy defaultIncrementStrategy = IncrementStrategy.Patch, bool defaultPreventIncrement = false, @@ -169,6 +167,7 @@ public static void ApplyBranchDefaults(Config config, bool isReleaseBranch = false, bool isMainline = false) { + branchConfig.Regex = string.IsNullOrEmpty(branchConfig.Regex) ? branchRegex : branchConfig.Regex; branchConfig.Tag = branchConfig.Tag ?? defaultTag; branchConfig.TagNumberPattern = branchConfig.TagNumberPattern ?? defaultTagNumberPattern; branchConfig.Increment = branchConfig.Increment ?? defaultIncrementStrategy; @@ -188,7 +187,6 @@ static Config ReadConfig(string workingDirectory, IFileSystem fileSystem) { var readAllText = fileSystem.ReadAllText(configFilePath); LegacyConfigNotifier.Notify(new StringReader(readAllText)); - return ConfigSerialiser.Read(new StringReader(readAllText)); } @@ -229,7 +227,7 @@ public static void Verify(string workingDirectory, string projectRootDirectory, WarnAboutAmbiguousConfigFileSelection(workingDirectory, projectRootDirectory, fileSystem); } - private static void WarnAboutAmbiguousConfigFileSelection(string workingDirectory, string projectRootDirectory, IFileSystem fileSystem) + static void WarnAboutAmbiguousConfigFileSelection(string workingDirectory, string projectRootDirectory, IFileSystem fileSystem) { var workingConfigFile = GetConfigFilePath(workingDirectory, fileSystem); var projectRootConfigFile = GetConfigFilePath(projectRootDirectory, fileSystem); @@ -242,7 +240,7 @@ private static void WarnAboutAmbiguousConfigFileSelection(string workingDirector } } - public static string GetConfigFilePath(string workingDirectory, IFileSystem fileSystem) + static string GetConfigFilePath(string workingDirectory, IFileSystem fileSystem) { var ymlPath = Path.Combine(workingDirectory, DefaultConfigFileName); if (fileSystem.Exists(ymlPath)) @@ -259,7 +257,7 @@ public static string GetConfigFilePath(string workingDirectory, IFileSystem file return ymlPath; } - public static bool HasConfigFileAt(string workingDirectory, IFileSystem fileSystem) + static bool HasConfigFileAt(string workingDirectory, IFileSystem fileSystem) { var defaultConfigFilePath = Path.Combine(workingDirectory, DefaultConfigFileName); if (fileSystem.Exists(defaultConfigFilePath)) @@ -276,23 +274,22 @@ public static bool HasConfigFileAt(string workingDirectory, IFileSystem fileSyst return false; } - static bool WarnAboutObsoleteConfigFile(string workingDirectory, IFileSystem fileSystem) + static void WarnAboutObsoleteConfigFile(string workingDirectory, IFileSystem fileSystem) { var deprecatedConfigFilePath = Path.Combine(workingDirectory, ObsoleteConfigFileName); if (!fileSystem.Exists(deprecatedConfigFilePath)) { - return false; + return; } var defaultConfigFilePath = Path.Combine(workingDirectory, DefaultConfigFileName); if (fileSystem.Exists(defaultConfigFilePath)) { Logger.WriteWarning(string.Format("Ambiguous config files at '{0}': '{1}' (deprecated) and '{2}'. Will be used '{2}'", workingDirectory, ObsoleteConfigFileName, DefaultConfigFileName)); - return true; + return; } Logger.WriteWarning(string.Format("'{0}' is deprecated, use '{1}' instead.", deprecatedConfigFilePath, DefaultConfigFileName)); - return true; } public static void Init(string workingDirectory, IFileSystem fileSystem, IConsole console) diff --git a/src/GitVersionCore/Configuration/GitVersionConfigurationException.cs b/src/GitVersionCore/Configuration/GitVersionConfigurationException.cs new file mode 100644 index 0000000000..76cfb026e8 --- /dev/null +++ b/src/GitVersionCore/Configuration/GitVersionConfigurationException.cs @@ -0,0 +1,11 @@ +namespace GitVersion +{ + using System; + + public class GitVersionConfigurationException : Exception + { + public GitVersionConfigurationException(string msg) : base(msg) + { + } + } +} \ No newline at end of file diff --git a/src/GitVersionCore/Configuration/LegacyConfig.cs b/src/GitVersionCore/Configuration/LegacyConfig.cs index dea5a9076d..9347abca70 100644 --- a/src/GitVersionCore/Configuration/LegacyConfig.cs +++ b/src/GitVersionCore/Configuration/LegacyConfig.cs @@ -5,7 +5,7 @@ namespace GitVersion /// /// Obsolete properties are added to this, so we can check to see if they are used and provide good error messages for migration /// - public class LegacyConfig + public class LegacyConfig : Config { public string assemblyVersioningScheme { get; set; } diff --git a/src/GitVersionCore/Configuration/LegacyConfigNotifier.cs b/src/GitVersionCore/Configuration/LegacyConfigNotifier.cs index ed2daddf9a..c7d94655d7 100644 --- a/src/GitVersionCore/Configuration/LegacyConfigNotifier.cs +++ b/src/GitVersionCore/Configuration/LegacyConfigNotifier.cs @@ -8,6 +8,21 @@ namespace GitVersion public class LegacyConfigNotifier { + static readonly Dictionary OldConfigKnownRegexes = new Dictionary + { + {ConfigurationProvider.MasterBranchRegex, ConfigurationProvider.MasterBranchKey}, + {ConfigurationProvider.DevelopBranchRegex, ConfigurationProvider.DevelopBranchKey}, + {ConfigurationProvider.FeatureBranchRegex, ConfigurationProvider.FeatureBranchKey}, + {ConfigurationProvider.HotfixBranchRegex, ConfigurationProvider.HotfixBranchKey}, + {ConfigurationProvider.ReleaseBranchRegex, ConfigurationProvider.ReleaseBranchKey}, + {ConfigurationProvider.SupportBranchRegex, ConfigurationProvider.SupportBranchKey}, + {ConfigurationProvider.PullRequestRegex, ConfigurationProvider.PullRequestBranchKey}, + {"release[/-]", ConfigurationProvider.ReleaseBranchKey}, + {"hotfix[/-]", ConfigurationProvider.HotfixBranchKey }, + {"feature(s)?[/-]", ConfigurationProvider.FeatureBranchKey }, + {"feature[/-]", ConfigurationProvider.FeatureBranchKey } + }; + public static void Notify(StringReader reader) { var deserializer = new Deserializer(null, new NullNamingConvention(), ignoreUnmatched: true); @@ -17,6 +32,17 @@ public static void Notify(StringReader reader) var issues = new List(); + var oldConfigs = legacyConfig.Branches.Keys.Where(k => OldConfigKnownRegexes.Keys.Contains(k) && k != OldConfigKnownRegexes[k]).ToList(); + if (oldConfigs.Any()) + { + var max = oldConfigs.Max(c => c.Length); + var oldBranchConfigs = oldConfigs.Select(c => string.Format("{0} -> {1}", c.PadRight(max), OldConfigKnownRegexes[c])); + var branchErrors = string.Join("\r\n ", oldBranchConfigs); + issues.Add(string.Format( +@"GitVersion branch configs no longer are keyed by regexes, update: + {0}", branchErrors)); + } + if (legacyConfig.assemblyVersioningScheme != null) issues.Add("assemblyVersioningScheme has been replaced by assembly-versioning-scheme"); diff --git a/src/GitVersionCore/GitVersionContext.cs b/src/GitVersionCore/GitVersionContext.cs index 72ec9b2650..bdf64bdb94 100644 --- a/src/GitVersionCore/GitVersionContext.cs +++ b/src/GitVersionCore/GitVersionContext.cs @@ -129,7 +129,8 @@ void CalculateEffectiveConfiguration() Configuration = new EffectiveConfiguration( assemblyVersioningScheme, assemblyInformationalFormat, versioningMode, gitTagPrefix, - tag, nextVersion, incrementStrategy, currentBranchConfig.Key, + tag, nextVersion, incrementStrategy, + currentBranchConfig.Value.Regex, preventIncrementForMergedBranchVersion, tagNumberPattern, FullConfiguration.ContinuousDeploymentFallbackTag, trackMergeTarget, diff --git a/src/GitVersionCore/GitVersionCore.csproj b/src/GitVersionCore/GitVersionCore.csproj index 27f3e2f1ac..cd4b515941 100644 --- a/src/GitVersionCore/GitVersionCore.csproj +++ b/src/GitVersionCore/GitVersionCore.csproj @@ -86,6 +86,7 @@ +