Skip to content
Closed
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
50 changes: 41 additions & 9 deletions GitVersionCore.Tests/ConfigProviderTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.IO;
using System.Linq;
using System.Reflection;
Expand Down Expand Up @@ -26,28 +27,59 @@ public void CanReadDocument()
{
const string text = @"
assembly-versioning-scheme: MajorMinor
develop-branch-tag: alpha
release-branch-tag: rc
next-version: 2.0.0
tag-prefix: '[vV|version-]'
mode: ContinuousDelivery
branches:
develop:
mode: ContinuousDeployment
tag: dev
release[/-]:
mode: ContinuousDeployment
tag: rc
";
SetupConfigFileContent(text);

var config = ConfigurationProvider.Provide(gitDirectory, fileSystem);
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinor);
config.DevelopBranchTag.ShouldBe("alpha");
config.ReleaseBranchTag.ShouldBe("rc");
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);
}

[Test]
public void CanInheritVersioningMode()
{
const string text = @"
mode: ContinuousDelivery
branches:
develop:
mode: ContinuousDeployment
";
SetupConfigFileContent(text);
var config = ConfigurationProvider.Provide(gitDirectory, fileSystem);
config.Branches["develop"].VersioningMode.ShouldBe(VersioningMode.ContinuousDeployment);
config.Release.VersioningMode.ShouldBe(VersioningMode.ContinuousDelivery);
config.Develop.Tag.ShouldBe("unstable");
}

[Test]
public void CanReadOldDocument()
{
const string text = @"assemblyVersioningScheme: MajorMinor";
const string text = @"
assemblyVersioningScheme: MajorMinor
develop-branch-tag: alpha
release-branch-tag: rc
";
SetupConfigFileContent(text);
var config = ConfigurationProvider.Provide(gitDirectory, fileSystem);
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinor);
config.Branches["develop"].Tag.ShouldBe("alpha");
config.Branches["release[/-]"].Tag.ShouldBe("rc");
}

[Test]
Expand All @@ -57,8 +89,8 @@ public void CanReadDefaultDocument()
SetupConfigFileContent(text);
var config = ConfigurationProvider.Provide(gitDirectory, fileSystem);
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinorPatch);
config.DevelopBranchTag.ShouldBe("unstable");
config.ReleaseBranchTag.ShouldBe("beta");
config.Branches["develop"].Tag.ShouldBe("unstable");
config.Branches["release[/-]"].Tag.ShouldBe("beta");
config.TagPrefix.ShouldBe("[vV]");
config.NextVersion.ShouldBe(null);
}
Expand All @@ -67,7 +99,7 @@ public void CanReadDefaultDocument()
public void VerifyInit()
{
var config = typeof(Config);
var aliases = config.GetProperties().Select(p => ((YamlAliasAttribute) p.GetCustomAttribute(typeof(YamlAliasAttribute))).Alias);
var aliases = config.GetProperties().Where(p => p.GetCustomAttribute<ObsoleteAttribute>() == null).Select(p => ((YamlAliasAttribute) p.GetCustomAttribute(typeof(YamlAliasAttribute))).Alias);
var writer = new StringWriter();

ConfigReader.WriteSample(writer);
Expand All @@ -83,7 +115,7 @@ public void VerifyInit()
public void VerifyAliases()
{
var config = typeof(Config);
var propertiesMissingAlias = config.GetProperties().Where(p => p.GetCustomAttribute(typeof(YamlAliasAttribute)) == null).Select(p => p.Name);
var propertiesMissingAlias = config.GetProperties().Where(p => p.GetCustomAttribute<ObsoleteAttribute>() == null).Where(p => p.GetCustomAttribute(typeof(YamlAliasAttribute)) == null).Select(p => p.Name);

propertiesMissingAlias.ShouldBeEmpty();
}
Expand Down
23 changes: 18 additions & 5 deletions GitVersionCore.Tests/IntegrationTests/GitFlow/DevelopScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,36 @@ public void MergingReleaseBranchBackIntoDevelopWithoutMergingToMaster_DoesNotBum
[Test]
public void CanChangeDevelopTagViaConfig()
{
using (var fixture = new EmptyRepositoryFixture(new Config
{
DevelopBranchTag = "alpha"
}))
var config = new Config();
config.Branches["develop"].Tag = "alpha";
using (var fixture = new EmptyRepositoryFixture(config))
{
fixture.Repository.MakeATaggedCommit("1.0.0");
fixture.Repository.CreateBranch("develop").Checkout();
fixture.AssertFullSemver("1.1.0-alpha.0+0");
}
}

[Test]
public void CanHandleContinuousDelivery()
{
var config = new Config();
config.Branches["develop"].VersioningMode = VersioningMode.ContinuousDelivery;
using (var fixture = new EmptyRepositoryFixture(config))
{
fixture.Repository.MakeATaggedCommit("1.0.0");
fixture.Repository.CreateBranch("develop").Checkout();
fixture.Repository.MakeATaggedCommit("1.1.0-alpha7");
fixture.AssertFullSemver("1.1.0-alpha.7+1");
}
}

[Test]
public void CanClearDevelopTagViaConfig()
{
using (var fixture = new EmptyRepositoryFixture(new Config
{
DevelopBranchTag = ""
Develop = {Tag= ""}
}))
{
fixture.Repository.MakeATaggedCommit("1.0.0");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,25 @@ public void CanTakeVersionFromReleaseBranchWithTagOverriden()
}
}

[Test]
public void CanHandleContinuousDeployment()
{
var config = new Config
{
VersioningMode = VersioningMode.ContinuousDeployment
};
using (var fixture = new EmptyRepositoryFixture(config))
{
fixture.Repository.MakeATaggedCommit("1.0.3");
fixture.Repository.CreateBranch("develop");
fixture.Repository.MakeCommits(5);
fixture.Repository.CreateBranch("release-2.0.0");
fixture.Repository.Checkout("release-2.0.0");

fixture.AssertFullSemver("2.0.0-beta.5+5");
}
}

[Test]
public void CanHandleReleaseBranchWithStability()
{
Expand Down
13 changes: 13 additions & 0 deletions GitVersionCore/Configuration/BranchConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace GitVersion
{
using YamlDotNet.Serialization;

public class BranchConfig
{
[YamlAlias("mode")]
public VersioningMode VersioningMode { get; set; }

[YamlAlias("tag")]
public string Tag { get; set; }
}
}
96 changes: 92 additions & 4 deletions GitVersionCore/Configuration/Config.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,118 @@
namespace GitVersion
{
using System;
using System.Collections.Generic;
using System.Linq;

using YamlDotNet.Serialization;

public class Config
{
VersioningMode versioningMode;

Dictionary<string, BranchConfig> branches = new Dictionary<string, BranchConfig>();

public Config()
{
AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatch;
DevelopBranchTag = "unstable";
ReleaseBranchTag = "beta";
TagPrefix = "[vV]";
Branches["release[/-]"] = new BranchConfig { Tag = "beta" };
Branches["develop"] = new BranchConfig { Tag = "unstable" };
VersioningMode = VersioningMode.ContinuousDelivery;
Develop.VersioningMode = VersioningMode.ContinuousDeployment;
}

[YamlAlias("assembly-versioning-scheme")]
public AssemblyVersioningScheme AssemblyVersioningScheme { get; set; }

[YamlAlias("develop-branch-tag")]
public string DevelopBranchTag { get; set; }
[Obsolete]
public string DevelopBranchTag
{
set
{
Develop.Tag = value;
}
get
{
return Develop.Tag;
}
}

[YamlAlias("release-branch-tag")]
public string ReleaseBranchTag { get; set; }
[Obsolete]
public string ReleaseBranchTag
{
set
{
Release.Tag = value;
}
get
{
return Release.Tag;
}
}

[YamlAlias("mode")]
public VersioningMode VersioningMode
{
get
{
return versioningMode;
}
set
{
Branches.ToList().ForEach(b => b.Value.VersioningMode = value);
versioningMode = value;
}
}

[YamlAlias("branches")]
public Dictionary<string, BranchConfig> Branches
{
get
{
return branches;
}
set
{
value.ToList().ForEach(_ => branches[_.Key] = MergeObjects(branches[_.Key], _.Value));
}
}

private T MergeObjects<T>(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;
}

[YamlAlias("tag-prefix")]
public string TagPrefix { get; set; }

[YamlAlias("next-version")]
public string NextVersion { get; set; }

[Obsolete]
public BranchConfig Develop
{
get
{
return Branches["develop"];
}
}

[Obsolete]
public BranchConfig Release
{
get
{
return Branches["release[/-]"];
}
}
}
}
6 changes: 4 additions & 2 deletions GitVersionCore/Configuration/ConfigReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ public static Config Read(TextReader reader)
public static void WriteSample(TextWriter writer)
{
writer.WriteLine("# assembly-versioning-scheme: MajorMinorPatchMetadata | MajorMinorPatch | MajorMinor | Major");
writer.WriteLine("# develop-branch-tag: alpha");
writer.WriteLine("# release-branch-tag: rc");
writer.WriteLine("# tag-prefix: '[vV|version-] # regex to match git tag prefix");
writer.WriteLine("# next-version: 1.0.0");
writer.WriteLine("# mode: ContinuousDelivery | ContinuousDeployment");
writer.WriteLine("#branches:");
writer.WriteLine("# release[/-]*:\n mode: ContinuousDelivery | ContinuousDeployment\n tag: rc");
writer.WriteLine("# develop:\n mode: ContinuousDelivery | ContinuousDeployment\n tag: alpha");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ protected SemanticVersion FindVersion(
GitVersionContext context,
BranchType branchType)
{
context.CurrentBranchConfig = context.Configuration.Branches["develop"];
var ancestor = FindCommonAncestorWithDevelop(context.Repository, context.CurrentBranch, branchType);

if (!IsThereAnyCommitOnTheBranch(context.Repository, context.CurrentBranch))
Expand Down
19 changes: 15 additions & 4 deletions GitVersionCore/GitFlow/BranchFinders/DevelopVersionFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,23 @@ public SemanticVersion FindVersion(GitVersionContext context)
var c = context.Repository.Commits.QueryBy(f);
var numberOfCommitsSinceRelease = c.Count();

var shortVersion = new SemanticVersion
{
Major = versionFromMaster.Major,
Minor = versionFromMaster.Minor + 1,
Patch = 0,
};

var applicableTagsInDescendingOrder = context.Repository.SemVerTagsRelatedToVersion(context.Configuration, shortVersion).OrderByDescending(tag => SemanticVersion.Parse(tag.Name, context.Configuration.TagPrefix)).ToList();
var preReleaseTag = context.CurrentBranchConfig.VersioningMode.GetInstance().GetPreReleaseTag(context, applicableTagsInDescendingOrder, numberOfCommitsSinceRelease);


var semanticVersion = new SemanticVersion
{
Major = versionFromMaster.Major,
Minor = versionFromMaster.Minor + 1,
Patch = 0,
PreReleaseTag = context.Configuration.DevelopBranchTag + numberOfCommitsSinceRelease,
Major = shortVersion.Major,
Minor = shortVersion.Minor,
Patch = shortVersion.Patch,
PreReleaseTag = preReleaseTag,
BuildMetaData = new SemanticVersionBuildMetaData(numberOfCommitsSinceRelease, context.CurrentBranch.Name,tip.Sha,tip.When()),
};

Expand Down
17 changes: 4 additions & 13 deletions GitVersionCore/GitFlow/BranchFinders/HotfixVersionFinder.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace GitVersion
{
using System.Linq;

using LibGit2Sharp;

class HotfixVersionFinder
Expand All @@ -12,8 +14,8 @@ public SemanticVersion FindVersion(GitVersionContext context)
EnsureVersionIsValid(shortVersion, context.CurrentBranch);

var nbHotfixCommits = BranchCommitDifferenceFinder.NumberOfCommitsInBranchNotKnownFromBaseBranch(context.Repository, context.CurrentBranch, BranchType.Hotfix, "master");

var semanticVersionPreReleaseTag = GetSemanticVersionPreReleaseTag(context, shortVersion, nbHotfixCommits);
var tagsInDescendingOrder = context.Repository.SemVerTagsRelatedToVersion(context.Configuration, shortVersion).OrderByDescending(tag => SemanticVersion.Parse(tag.Name, context.Configuration.TagPrefix)).ToList();
var semanticVersionPreReleaseTag = context.CurrentBranchConfig.VersioningMode.GetInstance().GetPreReleaseTag(context, tagsInDescendingOrder, nbHotfixCommits);
return new SemanticVersion
{
Major = shortVersion.Major,
Expand All @@ -24,17 +26,6 @@ public SemanticVersion FindVersion(GitVersionContext context)
};
}

static string GetSemanticVersionPreReleaseTag(GitVersionContext context, SemanticVersion shortVersion, int nbHotfixCommits)
{
var semanticVersionPreReleaseTag = context.Configuration.ReleaseBranchTag + ".1";
var tagVersion = RecentTagVersionExtractor.RetrieveMostRecentOptionalTagVersion(context, shortVersion);
if (tagVersion != null)
{
semanticVersionPreReleaseTag = tagVersion;
}
return semanticVersionPreReleaseTag;
}

static string GetSuffix(Branch branch)
{
return branch.Name.TrimStart("hotfix-").TrimStart("hotfix/");
Expand Down
Loading