Skip to content

Default config updates to recognize more defaults #622

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ branches:
increment: Patch
prevent-increment-of-merged-branch-version: true
track-merge-target: false
release[/-]:
releases?[/-]:
mode: ContinuousDelivery
tag: beta
increment: Patch
prevent-increment-of-merged-branch-version: true
track-merge-target: false
feature[/-]:
features?[/-]:
mode: ContinuousDelivery
tag: useBranchName
increment: Inherit
Expand All @@ -32,7 +32,7 @@ branches:
prevent-increment-of-merged-branch-version: false
tag-number-pattern: '[/-](?<number>\d+)[-/]'
track-merge-target: false
hotfix[/-]:
hotfix(es)?[/-]:
mode: ContinuousDelivery
tag: beta
increment: Patch
Expand All @@ -44,7 +44,7 @@ branches:
increment: Patch
prevent-increment-of-merged-branch-version: true
track-merge-target: false
develop:
dev(elop)?(ment)?$:
mode: ContinuousDeployment
tag: unstable
increment: Minor
Expand Down
22 changes: 11 additions & 11 deletions src/GitVersionCore.Tests/ConfigProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void Setup()
}

[Test]
public void CanReadDocument()
public void CanReadDocumentAndMigrate()
{
const string text = @"
assembly-versioning-scheme: MajorMinor
Expand All @@ -46,10 +46,10 @@ public void CanReadDocument()
config.NextVersion.ShouldBe("2.0.0");
config.TagPrefix.ShouldBe("[vV|version-]");
config.VersioningMode.ShouldBe(VersioningMode.ContinuousDelivery);
config.Branches["develop"].Tag.ShouldBe("dev");
config.Branches["release[/-]"].Tag.ShouldBe("rc");
config.Branches["release[/-]"].VersioningMode.ShouldBe(VersioningMode.ContinuousDeployment);
config.Branches["develop"].VersioningMode.ShouldBe(VersioningMode.ContinuousDeployment);
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]
Expand All @@ -75,16 +75,16 @@ public void OverwritesDefaultsWithProvidedConfig()
const string text = @"
next-version: 2.0.0
branches:
develop:
dev(elop)?(ment)?$:
mode: ContinuousDeployment
tag: dev";
SetupConfigFileContent(text);
var config = ConfigurationProvider.Provide(repoPath, fileSystem);

config.NextVersion.ShouldBe("2.0.0");
config.Branches["develop"].Increment.ShouldBe(defaultConfig.Branches["develop"].Increment);
config.Branches["develop"].VersioningMode.ShouldBe(defaultConfig.Branches["develop"].VersioningMode);
config.Branches["develop"].Tag.ShouldBe("dev");
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");
}

[Test]
Expand Down Expand Up @@ -117,8 +117,8 @@ public void CanReadDefaultDocument()
SetupConfigFileContent(text);
var config = ConfigurationProvider.Provide(repoPath, fileSystem);
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinorPatch);
config.Branches["develop"].Tag.ShouldBe("unstable");
config.Branches["release[/-]"].Tag.ShouldBe("beta");
config.Branches["dev(elop)?(ment)?$"].Tag.ShouldBe("unstable");
config.Branches["releases?[/-]"].Tag.ShouldBe("beta");
config.TagPrefix.ShouldBe(ConfigurationProvider.DefaultTagPrefix);
config.NextVersion.ShouldBe(null);
}
Expand Down
6 changes: 3 additions & 3 deletions src/GitVersionCore.Tests/GitVersionContextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void UsesBranchSpecificConfigOverTopLevelDefaults()
Branches =
{
{
"develop", new BranchConfig
"dev(elop)?(ment)?$", new BranchConfig
{
VersioningMode = VersioningMode.ContinuousDeployment,
Tag = "alpha"
Expand Down Expand Up @@ -68,8 +68,8 @@ public void CanFindParentBranchForInheritingIncrementStrategy()
{
Branches =
{
{ "develop", new BranchConfig { Increment = IncrementStrategy.Major} },
{ "feature[/-]", new BranchConfig { Increment = IncrementStrategy.Inherit} }
{ "dev(elop)?(ment)?$", new BranchConfig { Increment = IncrementStrategy.Major} },
{ "features?[/-]", new BranchConfig { Increment = IncrementStrategy.Inherit} }
}
};

Expand Down
16 changes: 14 additions & 2 deletions src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void CanChangeDevelopTagViaConfig()
{
Branches =
{
{"develop", new BranchConfig
{"dev(elop)?(ment)?$", new BranchConfig
{
Tag = "alpha"
}
Expand All @@ -75,6 +75,18 @@ public void CanChangeDevelopTagViaConfig()
}
}

[Test]
public void WhenDeveloperBranchExistsDontTreatAsDevelop()
{
using (var fixture = new EmptyRepositoryFixture(new Config()))
{
fixture.Repository.MakeATaggedCommit("1.0.0");
fixture.Repository.Checkout(fixture.Repository.CreateBranch("developer"));
fixture.Repository.MakeACommit();
fixture.AssertFullSemver("1.0.1-developer.1+1"); // this tag should be the branch name by default, not unstable
}
}

[Test]
public void WhenDevelopBranchedFromMaster_MinorIsIncreased()
{
Expand Down Expand Up @@ -113,7 +125,7 @@ public void CanHandleContinuousDelivery()
{
Branches =
{
{"develop", new BranchConfig
{"dev(elop)?(ment)?$", new BranchConfig
{
VersioningMode = VersioningMode.ContinuousDelivery
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,20 @@ public void TestFeatureBranch()
}
}

[Test]
public void TestFeaturesBranch()
{
using (var fixture = new EmptyRepositoryFixture(new Config()))
{
fixture.Repository.MakeATaggedCommit("1.0.0");
fixture.Repository.CreateBranch("features/test");
fixture.Repository.Checkout("features/test");
fixture.Repository.MakeCommits(5);

fixture.AssertFullSemver("1.0.1-test.1+5");
}
}

[Test]
public void WhenTwoFeatureBranchPointToTheSameCommit()
{
Expand Down
27 changes: 27 additions & 0 deletions src/GitVersionCore.Tests/IntegrationTests/HotfixBranchScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,33 @@ public void PatchLatestReleaseExample()
}
}

[Test]
public void CanTakeVersionFromHotfixesBranch()
{
using (var fixture = new BaseGitFlowRepositoryFixture(r =>
{
r.MakeATaggedCommit("1.0.0");
r.MakeATaggedCommit("1.1.0");
r.MakeATaggedCommit("2.0.0");
}))
{

// Merge hotfix branch to support
fixture.Repository.Checkout("master");
fixture.Repository.Checkout(fixture.Repository.CreateBranch("support-1.1", (Commit)fixture.Repository.Tags.Single(t => t.Name == "1.1.0").Target));
fixture.AssertFullSemver("1.1.0");

// create hotfix branch
fixture.Repository.Checkout(fixture.Repository.CreateBranch("hotfixes/1.1.1"));
fixture.AssertFullSemver("1.1.0"); // We are still on a tagged commit
fixture.Repository.MakeACommit();

fixture.AssertFullSemver("1.1.1-beta.1+1");
fixture.Repository.MakeACommit();
fixture.AssertFullSemver("1.1.1-beta.1+2");
}
}

[Test]
public void PatchOlderReleaseExample()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,22 @@ public void CanTakeVersionFromReleaseBranch()
}
}

[Test]
public void CanTakeVersionFromReleasesBranch()
{
using (var fixture = new EmptyRepositoryFixture(new Config()))
{
fixture.Repository.MakeATaggedCommit("1.0.3");
fixture.Repository.MakeCommits(5);
fixture.Repository.CreateBranch("releases/2.0.0");
fixture.Repository.Checkout("releases/2.0.0");

fixture.AssertFullSemver("2.0.0-beta.1+0");
fixture.Repository.MakeCommits(2);
fixture.AssertFullSemver("2.0.0-beta.1+2");
}
}

[Test]
public void ReleaseBranchWithNextVersionSetInConfig()
{
Expand All @@ -95,7 +111,7 @@ public void CanTakeVersionFromReleaseBranchWithTagOverridden()
{
Branches =
{
{ "release[/-]", new BranchConfig { Tag = "rc" } }
{ "releases?[/-]", new BranchConfig { Tag = "rc" } }
}
};
using (var fixture = new EmptyRepositoryFixture(config))
Expand Down
38 changes: 34 additions & 4 deletions src/GitVersionCore/Configuration/ConfigurationProvider.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace GitVersion
{
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
Expand All @@ -20,6 +21,8 @@ public static Config Provide(string workingDirectory, IFileSystem fileSystem, bo

public static void ApplyDefaultsTo(Config config)
{
MigrateBranches(config);

config.AssemblyVersioningScheme = config.AssemblyVersioningScheme ?? AssemblyVersioningScheme.MajorMinorPatch;
config.TagPrefix = config.TagPrefix ?? DefaultTagPrefix;
config.VersioningMode = config.VersioningMode ?? VersioningMode.ContinuousDelivery;
Expand All @@ -31,15 +34,15 @@ public static void ApplyDefaultsTo(Config config)
var configBranches = config.Branches.ToList();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add another parameter to this which is migrate: and then it takes an array. You can then add migrate: new[] { "release[/-]" } and ApplyBranchDefaults should rename the configs to be migrated, then apply the defaults.

Just one idea on how to solve.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I'm not sure how the migration should work? Should apply branch defaults look for the old keys and rename them?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah exactly. So I have:

branches:
  develop:
    tag: beta

The effective config will have both develop and dev(elop)?.... We need to look for develop, rename it to the new one then delete it


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, "releases?[/-]"), defaultTag: "beta", defaultPreventIncrement: true);
ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, "features?[/-]"), defaultIncrementStrategy: IncrementStrategy.Inherit);
ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, @"(pull|pull\-requests|pr)[/-]"),
defaultTag: "PullRequest",
defaultTagNumberPattern: @"[/-](?<number>\d+)[-/]",
defaultIncrementStrategy: IncrementStrategy.Inherit);
ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, "hotfix[/-]"), defaultTag: "beta");
ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, "hotfix(es)?[/-]"), defaultTag: "beta");
ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, "support[/-]"), defaultTag: string.Empty, defaultPreventIncrement: true);
ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, "develop"),
ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, "dev(elop)?(ment)?$"),
defaultTag: "unstable",
defaultIncrementStrategy: IncrementStrategy.Minor,
defaultVersioningMode: VersioningMode.ContinuousDeployment,
Expand All @@ -53,6 +56,33 @@ public static void ApplyDefaultsTo(Config config)
}
}

static void MigrateBranches(Config config)
{
// Map of current names and previous names
var dict = new Dictionary<string, string[]>
{
{ "hotfix(es)?[/-]", new []{"hotfix[/-]"}},
{ "features?[/-]", new []{"feature[/-]"}},
{ "releases?[/-]", new []{"release[/-]"}},
{ "dev(elop)?(ment)?$", new []{"develop"}}
};

foreach (var mapping in dict)
{
foreach (var source in mapping.Value)
{
if (config.Branches.ContainsKey(source))
{
// found one, rename
var bc = config.Branches[source];
config.Branches.Remove(source);
config.Branches[mapping.Key] = bc; // re-add with new name
}
}
}
}


static BranchConfig GetOrCreateBranchDefaults(Config config, string branch)
{
if (!config.Branches.ContainsKey(branch))
Expand Down