diff --git a/docs/configuration.md b/docs/configuration.md index c720497cd9..2b35ed2c0e 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -144,7 +144,7 @@ branches: increment: Patch prevent-increment-of-merged-branch-version: true track-merge-target: false - is-develop: false + tracks-release-branches: false is-release-branch: false releases?[/-]: mode: ContinuousDelivery @@ -152,7 +152,7 @@ branches: increment: Patch prevent-increment-of-merged-branch-version: true track-merge-target: false - is-develop: false + tracks-release-branches: false is-release-branch: true features?[/-]: mode: ContinuousDelivery @@ -160,7 +160,7 @@ branches: increment: Inherit prevent-increment-of-merged-branch-version: false track-merge-target: false - is-develop: false + tracks-release-branches: false is-release-branch: false (pull|pull\-requests|pr)[/-]: mode: ContinuousDelivery @@ -169,7 +169,7 @@ branches: prevent-increment-of-merged-branch-version: false tag-number-pattern: '[/-](?\d+)[-/]' track-merge-target: false - is-develop: false + tracks-release-branches: false is-release-branch: false hotfix(es)?[/-]: mode: ContinuousDelivery @@ -177,7 +177,7 @@ branches: increment: Patch prevent-increment-of-merged-branch-version: false track-merge-target: false - is-develop: false + tracks-release-branches: false is-release-branch: false support[/-]: mode: ContinuousDelivery @@ -185,7 +185,7 @@ branches: increment: Patch prevent-increment-of-merged-branch-version: true track-merge-target: false - is-develop: false + tracks-release-branches: false is-release-branch: false dev(elop)?(ment)?$: mode: ContinuousDeployment @@ -193,7 +193,7 @@ branches: increment: Minor prevent-increment-of-merged-branch-version: false track-merge-target: true - is-develop: true + tracks-release-branches: true is-release-branch: false ``` @@ -252,7 +252,7 @@ Strategy which will look for tagged merge commits directly off the current branch. For example `develop` → `release/1.0.0` → merge into `master` and tag `1.0.0`. The tag is *not* on develop, but develop should be version `1.0.0` now. -### is-develop +### tracks-release-branches Indicates this branch config represents develop in GitFlow. ### is-release-branch diff --git a/src/GitVersionCore.Tests/ConfigProviderTests.CanWriteOutEffectiveConfiguration.approved.txt b/src/GitVersionCore.Tests/ConfigProviderTests.CanWriteOutEffectiveConfiguration.approved.txt index 8dbda75afd..d9a08491a2 100644 --- a/src/GitVersionCore.Tests/ConfigProviderTests.CanWriteOutEffectiveConfiguration.approved.txt +++ b/src/GitVersionCore.Tests/ConfigProviderTests.CanWriteOutEffectiveConfiguration.approved.txt @@ -17,7 +17,7 @@ branches: increment: Patch prevent-increment-of-merged-branch-version: true track-merge-target: false - is-develop: false + tracks-release-branches: false is-release-branch: false is-mainline: true releases?[/-]: @@ -26,7 +26,7 @@ branches: increment: Patch prevent-increment-of-merged-branch-version: true track-merge-target: false - is-develop: false + tracks-release-branches: false is-release-branch: true is-mainline: false features?[/-]: @@ -35,7 +35,7 @@ branches: increment: Inherit prevent-increment-of-merged-branch-version: false track-merge-target: false - is-develop: false + tracks-release-branches: false is-release-branch: false is-mainline: false (pull|pull\-requests|pr)[/-]: @@ -45,7 +45,7 @@ branches: prevent-increment-of-merged-branch-version: false tag-number-pattern: '[/-](?\d+)[-/]' track-merge-target: false - is-develop: false + tracks-release-branches: false is-release-branch: false is-mainline: false hotfix(es)?[/-]: @@ -54,7 +54,7 @@ branches: increment: Patch prevent-increment-of-merged-branch-version: false track-merge-target: false - is-develop: false + tracks-release-branches: false is-release-branch: false is-mainline: false support[/-]: @@ -63,7 +63,7 @@ branches: increment: Patch prevent-increment-of-merged-branch-version: true track-merge-target: false - is-develop: false + tracks-release-branches: false is-release-branch: false is-mainline: true dev(elop)?(ment)?$: @@ -72,7 +72,7 @@ branches: increment: Minor prevent-increment-of-merged-branch-version: false track-merge-target: true - is-develop: true + tracks-release-branches: true is-release-branch: false is-mainline: false ignore: diff --git a/src/GitVersionCore.Tests/ConfigProviderTests.cs b/src/GitVersionCore.Tests/ConfigProviderTests.cs index f7f1fc8d4f..78786ea29e 100644 --- a/src/GitVersionCore.Tests/ConfigProviderTests.cs +++ b/src/GitVersionCore.Tests/ConfigProviderTests.cs @@ -42,7 +42,7 @@ public void CanReadDocumentAndMigrate() tag: dev release[/-]: mode: continuousDeployment - tag: rc + tag: rc "; SetupConfigFileContent(text); @@ -308,4 +308,23 @@ string SetupConfigFileContent(string text, string fileName, string path) return fullPath; } + + [Test] + public void WarnOnObsoleteIsDevelopBranchConfigurationSetting() + { + const string text = @" +assembly-versioning-scheme: MajorMinorPatch +branches: + master: + tag: beta + is-develop: true"; + + OldConfigurationException exception = Should.Throw(() => + { + LegacyConfigNotifier.Notify(new StringReader(text)); + }); + + var expecedMessage = string.Format("'is-develop' is deprecated, use 'track-release-branches' instead."); + exception.Message.ShouldContain(expecedMessage); + } } diff --git a/src/GitVersionCore.Tests/IntegrationTests/FeatureBranchScenarios.cs b/src/GitVersionCore.Tests/IntegrationTests/FeatureBranchScenarios.cs index d078218c69..2941dd98c7 100644 --- a/src/GitVersionCore.Tests/IntegrationTests/FeatureBranchScenarios.cs +++ b/src/GitVersionCore.Tests/IntegrationTests/FeatureBranchScenarios.cs @@ -3,6 +3,7 @@ using GitVersionCore.Tests; using LibGit2Sharp; using NUnit.Framework; +using System.Collections.Generic; [TestFixture] public class FeatureBranchScenarios @@ -223,7 +224,7 @@ public void BranchCreatedAfterFinishReleaseShouldInheritAndIncrementFromLastMast fixture.Checkout("develop"); fixture.Repository.MergeNoFF("release/0.2.0"); fixture.Repository.Branches.Remove("release/2.0.0"); - + fixture.Repository.MakeACommit(); //validate develop branch version after merging release 0.2.0 to master and develop (finish release) @@ -237,4 +238,49 @@ public void BranchCreatedAfterFinishReleaseShouldInheritAndIncrementFromLastMast fixture.AssertFullSemver("0.3.0-TEST-1.1+2"); } } -} \ No newline at end of file + + [Test] + public void PickUpVersionFromMasterMarkedWithIsDevelop() + { + var config = new Config + { + VersioningMode = VersioningMode.ContinuousDelivery, + Branches = new Dictionary + { + { + "master", new BranchConfig() + { + Tag = "pre", + TracksReleaseBranches = true, + } + }, + { + "releases?[/-]", new BranchConfig() + { + Tag = "rc", + } + } + } + }; + + using (var fixture = new EmptyRepositoryFixture()) + { + fixture.MakeACommit(); + + // create a release branch and tag a release + fixture.BranchTo("release/0.10.0"); + fixture.MakeACommit(); + fixture.MakeACommit(); + fixture.AssertFullSemver(config, "0.10.0-rc.1+2"); + + // switch to master and verify the version + fixture.Checkout("master"); + fixture.MakeACommit(); + fixture.AssertFullSemver(config, "0.10.1-pre.1+1"); + + // create a feature branch from master and verify the version + fixture.BranchTo("MyFeatureD"); + fixture.AssertFullSemver(config, "0.10.1-MyFeatureD.1+1"); + } + } +} diff --git a/src/GitVersionCore.Tests/TestEffectiveConfiguration.cs b/src/GitVersionCore.Tests/TestEffectiveConfiguration.cs index d8ea075bc7..c2fa33b310 100644 --- a/src/GitVersionCore.Tests/TestEffectiveConfiguration.cs +++ b/src/GitVersionCore.Tests/TestEffectiveConfiguration.cs @@ -1,9 +1,9 @@ namespace GitVersionCore.Tests { - using System.Collections.Generic; - using System.Linq; using GitVersion; using GitVersion.VersionFilters; + using System.Collections.Generic; + using System.Linq; public class TestEffectiveConfiguration : EffectiveConfiguration { @@ -28,15 +28,15 @@ public TestEffectiveConfiguration( int buildMetaDataPadding = 4, int commitsSinceVersionSourcePadding = 4, IEnumerable versionFilters = null, - bool isDevelop = false, - bool isRelease = false) : + bool tracksReleaseBranches = false, + bool isRelease = false) : base(assemblyVersioningScheme, assemblyInformationalFormat, versioningMode, gitTagPrefix, tag, nextVersion, IncrementStrategy.Patch, branchPrefixToTrim, preventIncrementForMergedBranchVersion, tagNumberPattern, continuousDeploymentFallbackTag, trackMergeTarget, majorMessage, minorMessage, patchMessage, noBumpMessage, commitMessageMode, legacySemVerPadding, buildMetaDataPadding, commitsSinceVersionSourcePadding, versionFilters ?? Enumerable.Empty(), - isDevelop, isRelease) + tracksReleaseBranches, isRelease) { } } diff --git a/src/GitVersionCore/BranchConfigurationCalculator.cs b/src/GitVersionCore/BranchConfigurationCalculator.cs index 957c9ab0a8..89b0ac2328 100644 --- a/src/GitVersionCore/BranchConfigurationCalculator.cs +++ b/src/GitVersionCore/BranchConfigurationCalculator.cs @@ -1,14 +1,12 @@ namespace GitVersion { + using JetBrains.Annotations; + using LibGit2Sharp; using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; - using JetBrains.Annotations; - - using LibGit2Sharp; - public class BranchConfigurationCalculator { public static KeyValuePair GetBranchConfiguration(Commit currentCommit, IRepository repository, bool onlyEvaluateTrackedBranches, Config config, Branch currentBranch, IList excludedInheritBranches = null) @@ -18,7 +16,7 @@ public static KeyValuePair GetBranchConfiguration(Commit c if (matchingBranches.Length == 0) { var branchConfig = new BranchConfig(); - ConfigurationProvider.ApplyBranchDefaults(config, branchConfig); + ConfigurationProvider.ApplyBranchDefaults(config, branchConfig, tracksReleaseBranches: true); return new KeyValuePair(string.Empty, branchConfig); } if (matchingBranches.Length == 1) @@ -44,12 +42,12 @@ static KeyValuePair[] LookupBranchConfiguration([NotNull] { throw new ArgumentNullException("config"); } - + if (currentBranch == null) { throw new ArgumentNullException("currentBranch"); } - + return config.Branches.Where(b => Regex.IsMatch(currentBranch.FriendlyName, "^" + b.Key, RegexOptions.IgnoreCase)).ToArray(); } @@ -116,7 +114,7 @@ static KeyValuePair InheritBranchConfiguration(bool onlyEv Increment = branchConfig.Increment, PreventIncrementOfMergedBranchVersion = branchConfig.PreventIncrementOfMergedBranchVersion, // If we are inheriting from develop then we should behave like develop - IsDevelop = branchConfig.IsDevelop + TracksReleaseBranches = branchConfig.TracksReleaseBranches }); } @@ -144,7 +142,7 @@ static KeyValuePair InheritBranchConfiguration(bool onlyEv Increment = inheritingBranchConfig.Increment, PreventIncrementOfMergedBranchVersion = inheritingBranchConfig.PreventIncrementOfMergedBranchVersion, // If we are inheriting from develop then we should behave like develop - IsDevelop = inheritingBranchConfig.IsDevelop + TracksReleaseBranches = inheritingBranchConfig.TracksReleaseBranches }); } } diff --git a/src/GitVersionCore/Configuration/BranchConfig.cs b/src/GitVersionCore/Configuration/BranchConfig.cs index a437a5686a..148c25f471 100644 --- a/src/GitVersionCore/Configuration/BranchConfig.cs +++ b/src/GitVersionCore/Configuration/BranchConfig.cs @@ -17,7 +17,7 @@ public BranchConfig(BranchConfig branchConfiguration) TagNumberPattern = branchConfiguration.TagNumberPattern; TrackMergeTarget = branchConfiguration.TrackMergeTarget; CommitMessageIncrementing = branchConfiguration.CommitMessageIncrementing; - IsDevelop = branchConfiguration.IsDevelop; + TracksReleaseBranches = branchConfiguration.TracksReleaseBranches; IsReleaseBranch = branchConfiguration.IsReleaseBranch; IsMainline = branchConfiguration.IsMainline; } @@ -42,12 +42,12 @@ public BranchConfig(BranchConfig branchConfiguration) [YamlMember(Alias = "track-merge-target")] public bool? TrackMergeTarget { get; set; } - + [YamlMember(Alias = "commit-message-incrementing")] public CommitMessageIncrementMode? CommitMessageIncrementing { get; set; } - [YamlMember(Alias = "is-develop")] - public bool? IsDevelop { get; set; } + [YamlMember(Alias = "tracks-release-branches")] + public bool? TracksReleaseBranches { get; set; } [YamlMember(Alias = "is-release-branch")] public bool? IsReleaseBranch { get; set; } diff --git a/src/GitVersionCore/Configuration/ConfigurationProvider.cs b/src/GitVersionCore/Configuration/ConfigurationProvider.cs index 1475aa8ece..6b6caca815 100644 --- a/src/GitVersionCore/Configuration/ConfigurationProvider.cs +++ b/src/GitVersionCore/Configuration/ConfigurationProvider.cs @@ -1,8 +1,8 @@ namespace GitVersion { - using System; using GitVersion.Configuration.Init.Wizard; using GitVersion.Helpers; + using System; using System.ComponentModel; using System.IO; using System.Linq; @@ -106,10 +106,10 @@ public static void ApplyDefaultsTo(Config config) defaultIncrementStrategy: IncrementStrategy.Minor, defaultVersioningMode: VersioningMode.ContinuousDeployment, defaultTrackMergeTarget: true, - isDevelop: true); + tracksReleaseBranches: true); // Any user defined branches should have other values defaulted after known branches filled in - // This allows users to override one value of + // This allows users to override one value of foreach (var branchConfig in configBranches) { ApplyBranchDefaults(config, branchConfig.Value); @@ -165,7 +165,7 @@ public static void ApplyBranchDefaults(Config config, VersioningMode? defaultVersioningMode = null, // Looked up from main config bool defaultTrackMergeTarget = false, string defaultTagNumberPattern = null, - bool isDevelop = false, + bool tracksReleaseBranches = false, bool isReleaseBranch = false, bool isMainline = false) { @@ -175,7 +175,7 @@ public static void ApplyBranchDefaults(Config config, branchConfig.PreventIncrementOfMergedBranchVersion = branchConfig.PreventIncrementOfMergedBranchVersion ?? defaultPreventIncrement; branchConfig.TrackMergeTarget = branchConfig.TrackMergeTarget ?? defaultTrackMergeTarget; branchConfig.VersioningMode = branchConfig.VersioningMode ?? defaultVersioningMode ?? config.VersioningMode; - branchConfig.IsDevelop = branchConfig.IsDevelop ?? isDevelop; + branchConfig.TracksReleaseBranches = branchConfig.TracksReleaseBranches ?? tracksReleaseBranches; branchConfig.IsReleaseBranch = branchConfig.IsReleaseBranch ?? isReleaseBranch; branchConfig.IsMainline = branchConfig.IsMainline ?? isMainline; } diff --git a/src/GitVersionCore/Configuration/LegacyBranchConfig.cs b/src/GitVersionCore/Configuration/LegacyBranchConfig.cs new file mode 100644 index 0000000000..8553497f8a --- /dev/null +++ b/src/GitVersionCore/Configuration/LegacyBranchConfig.cs @@ -0,0 +1,16 @@ +namespace GitVersion +{ + using YamlDotNet.Serialization; + + /// + /// 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 LegacyBranchConfig + { + [YamlMember(Alias = "is-develop")] + public string IsDevelop + { + get; set; + } + } +} diff --git a/src/GitVersionCore/Configuration/LegacyConfig.cs b/src/GitVersionCore/Configuration/LegacyConfig.cs index dea5a9076d..d2b12ddecb 100644 --- a/src/GitVersionCore/Configuration/LegacyConfig.cs +++ b/src/GitVersionCore/Configuration/LegacyConfig.cs @@ -1,5 +1,7 @@ namespace GitVersion { + using System.Collections.Generic; + using System.Linq; using YamlDotNet.Serialization; /// @@ -7,6 +9,8 @@ namespace GitVersion /// public class LegacyConfig { + private Dictionary branches = new Dictionary(); + public string assemblyVersioningScheme { get; set; } [YamlMember(Alias = "develop-branch-tag")] @@ -14,5 +18,39 @@ public class LegacyConfig [YamlMember(Alias = "release-branch-tag")] public string ReleaseBranchTag { get; set; } + + [YamlMember(Alias = "branches")] + public Dictionary Branches + { + get + { + return branches; + } + set + { + value.ToList().ForEach(_ => + { + if (!branches.ContainsKey(_.Key)) + branches.Add(_.Key, new LegacyBranchConfig()); + + branches[_.Key] = MergeObjects(branches[_.Key], _.Value); + }); + } + } + + private T MergeObjects(T target, T source) + { + typeof(T).GetProperties() + .Where(prop => prop.CanRead && prop.CanWrite) + .Select(_ => new + { + prop = _, + value = _.GetValue(source, null) + }) + .Where(_ => _.value != null) + .ToList() + .ForEach(_ => _.prop.SetValue(target, _.value, null)); + return target; + } } -} \ No newline at end of file +} diff --git a/src/GitVersionCore/Configuration/LegacyConfigNotifier.cs b/src/GitVersionCore/Configuration/LegacyConfigNotifier.cs index ed2daddf9a..6d973eacdb 100644 --- a/src/GitVersionCore/Configuration/LegacyConfigNotifier.cs +++ b/src/GitVersionCore/Configuration/LegacyConfigNotifier.cs @@ -26,6 +26,9 @@ public static void Notify(StringReader reader) if (legacyConfig.ReleaseBranchTag != null) issues.Add("release-branch-tag has been replaced by branch specific configuration. See http://gitversion.readthedocs.org/en/latest/configuration/#branch-configuration"); + if (legacyConfig.Branches != null && legacyConfig.Branches.Any(branches => branches.Value.IsDevelop != null)) + issues.Add("'is-develop' is deprecated, use 'track-release-branches' instead. See http://gitversion.readthedocs.org/en/latest/configuration/#branch-configuration"); + if (issues.Any()) throw new OldConfigurationException("GitVersion configuration file contains old configuration, please fix the following errors:\r\n" + string.Join("\r\n", issues)); } diff --git a/src/GitVersionCore/GitVersionContext.cs b/src/GitVersionCore/GitVersionContext.cs index 72ec9b2650..ec293bbe40 100644 --- a/src/GitVersionCore/GitVersionContext.cs +++ b/src/GitVersionCore/GitVersionContext.cs @@ -71,11 +71,9 @@ public GitVersionContext(IRepository repository, Branch currentBranch, Config co /// Contains the raw configuration, use Configuration for specific config based on the current GitVersion context. /// public Config FullConfiguration { get; private set; } - public SemanticVersion CurrentCommitTaggedVersion { get; private set; } public bool OnlyEvaluateTrackedBranches { get; private set; } public EffectiveConfiguration Configuration { get; private set; } - public IRepository Repository { get; private set; } public Branch CurrentBranch { get; private set; } public Commit CurrentCommit { get; private set; } @@ -93,8 +91,8 @@ void CalculateEffectiveConfiguration() throw new Exception(string.Format("Configuration value for 'PreventIncrementOfMergedBranchVersion' for branch {0} has no value. (this should not happen, please report an issue)", currentBranchConfig.Key)); if (!currentBranchConfig.Value.TrackMergeTarget.HasValue) throw new Exception(string.Format("Configuration value for 'TrackMergeTarget' for branch {0} has no value. (this should not happen, please report an issue)", currentBranchConfig.Key)); - if (!currentBranchConfig.Value.IsDevelop.HasValue) - throw new Exception(string.Format("Configuration value for 'IsDevelop' for branch {0} has no value. (this should not happen, please report an issue)", currentBranchConfig.Key)); + if (!currentBranchConfig.Value.TracksReleaseBranches.HasValue) + throw new Exception(string.Format("Configuration value for 'TracksReleaseBranches' for branch {0} has no value. (this should not happen, please report an issue)", currentBranchConfig.Key)); if (!currentBranchConfig.Value.IsReleaseBranch.HasValue) throw new Exception(string.Format("Configuration value for 'IsReleaseBranch' for branch {0} has no value. (this should not happen, please report an issue)", currentBranchConfig.Key)); @@ -139,7 +137,7 @@ void CalculateEffectiveConfiguration() FullConfiguration.BuildMetaDataPadding.Value, FullConfiguration.CommitsSinceVersionSourcePadding.Value, FullConfiguration.Ignore.ToFilters(), - currentBranchConfig.Value.IsDevelop.Value, + currentBranchConfig.Value.TracksReleaseBranches.Value, currentBranchConfig.Value.IsReleaseBranch.Value); } } diff --git a/src/GitVersionCore/GitVersionCore.csproj b/src/GitVersionCore/GitVersionCore.csproj index 0208ef28f3..2741e5a65d 100644 --- a/src/GitVersionCore/GitVersionCore.csproj +++ b/src/GitVersionCore/GitVersionCore.csproj @@ -97,6 +97,7 @@ +