Skip to content

Better switching to git flow story #308

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
2 changes: 1 addition & 1 deletion GitVersionCore.Tests/GitVersionCore.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<Compile Include="IntegrationTests\GitFlow\MetaDataByCommitScenarios.cs" />
<Compile Include="IntegrationTests\GitFlow\PatchScenarios.cs" />
<Compile Include="IntegrationTests\GitFlow\ReleaseBranchTests.cs" />
<Compile Include="IntegrationTests\GitFlow\SwitchingToGitFlowScenarios.cs" />
<Compile Include="IntegrationTests\GitFlow\UncycloScenarios.cs" />
<Compile Include="IntegrationTests\GitHubFlow\OtherBranchTests.cs" />
<Compile Include="IntegrationTests\GitHubFlow\ReleaseBranchTests.cs" />
Expand All @@ -90,7 +91,6 @@
<Compile Include="ApprovalTestsConfig.cs" />
<Compile Include="Fixtures\RepositoryFixtureBase.cs" />
<Compile Include="SemanticVersionTests.cs" />
<Compile Include="ShortVersionParserTests.cs" />
<Compile Include="VariableProviderTests.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ static void EnsureBranchMatch(CommitCountingRepoFixture fixture, string branchNa
var referenceCommitFinder = commitFinder ?? (r => r.FindBranch(branchName).Tip);

var commit = referenceCommitFinder(fixture.Repository);
var releaseDate = LastMinorVersionFinder.Execute(fixture.Repository, commit);
var releaseDate = LastMinorVersionFinder.Execute(fixture.Repository, new Config(), commit);
releaseDate.ShouldBe(commit.When());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ public void CanTakeVersionFromReleaseBranchWithTagOverriden()
}
}

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

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

[Test]
public void WhenReleaseBranchIsMergedIntoMasterVersionIsTakenWithIt()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using GitVersion;
using LibGit2Sharp;
using NUnit.Framework;

[TestFixture]
public class SwitchingToGitFlowScenarios
{
[Test]
public void WhenDevelopBranchedFromMasterWithLegacyVersionTags_DevelopCanUseReachableTag()
{
using (var fixture = new EmptyRepositoryFixture(new Config()))
{
fixture.Repository.MakeCommits(5);
fixture.Repository.MakeATaggedCommit("1.0.0.0");
fixture.Repository.MakeCommits(2);
fixture.Repository.CreateBranch("develop").Checkout();
fixture.AssertFullSemver("1.1.0-unstable.0+0");
}
}
}
81 changes: 0 additions & 81 deletions GitVersionCore.Tests/ShortVersionParserTests.cs

This file was deleted.

6 changes: 3 additions & 3 deletions GitVersionCore/GitFlow/BranchFinders/HotfixVersionFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class HotfixVersionFinder
public SemanticVersion FindVersion(GitVersionContext context)
{
var versionString = GetSuffix(context.CurrentBranch);
var shortVersion = ShortVersionParser.Parse(versionString);
var shortVersion = SemanticVersion.Parse(versionString, context.Configuration.TagPrefix);

EnsureVersionIsValid(shortVersion, context.CurrentBranch);

Expand All @@ -24,7 +24,7 @@ public SemanticVersion FindVersion(GitVersionContext context)
};
}

static string GetSemanticVersionPreReleaseTag(GitVersionContext context, ShortVersion shortVersion, int nbHotfixCommits)
static string GetSemanticVersionPreReleaseTag(GitVersionContext context, SemanticVersion shortVersion, int nbHotfixCommits)
{
var semanticVersionPreReleaseTag = context.Configuration.ReleaseBranchTag + ".1";
var tagVersion = RecentTagVersionExtractor.RetrieveMostRecentOptionalTagVersion(context, shortVersion);
Expand All @@ -40,7 +40,7 @@ static string GetSuffix(Branch branch)
return branch.Name.TrimStart("hotfix-").TrimStart("hotfix/");
}

void EnsureVersionIsValid(ShortVersion version, Branch branch)
void EnsureVersionIsValid(SemanticVersion version, Branch branch)
{
if (version.Patch == 0)
{
Expand Down
18 changes: 9 additions & 9 deletions GitVersionCore/GitFlow/BranchFinders/MasterVersionFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ namespace GitVersion

class MasterVersionFinder
{
public SemanticVersion FindVersion(IRepository repository, Commit tip)
public SemanticVersion FindVersion(GitVersionContext context)
{
foreach (var tag in repository.TagsByDate(tip))
foreach (var tag in context.Repository.TagsByDate(context.CurrentCommit))
{
ShortVersion shortVersion;
if (ShortVersionParser.TryParse(tag.Name, out shortVersion))
SemanticVersion shortVersion;
if (SemanticVersion.TryParse(tag.Name, context.Configuration.TagPrefix, out shortVersion))
{
return BuildVersion(tip, shortVersion);
return BuildVersion(context.CurrentCommit, shortVersion);
}
}

ShortVersion versionFromTip;
if (MergeMessageParser.TryParse(tip, out versionFromTip))
SemanticVersion versionFromTip;
if (MergeMessageParser.TryParse(context.CurrentCommit, context.Configuration, out versionFromTip))
{
return BuildVersion(tip, versionFromTip);
return BuildVersion(context.CurrentCommit, versionFromTip);
}
throw new WarningException("The head of master should always be a merge commit if you follow gitflow. Please create one or work around this by tagging the commit with SemVer compatible Id.");
}

SemanticVersion BuildVersion(Commit tip, ShortVersion shortVersion)
SemanticVersion BuildVersion(Commit tip, SemanticVersion shortVersion)
{
return new SemanticVersion
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace GitVersion

class RecentTagVersionExtractor
{
internal static SemanticVersionPreReleaseTag RetrieveMostRecentOptionalTagVersion(GitVersionContext context, ShortVersion matchVersion)
internal static SemanticVersionPreReleaseTag RetrieveMostRecentOptionalTagVersion(GitVersionContext context, SemanticVersion matchVersion)
{
var tagsInDescendingOrder = context.Repository.SemVerTagsRelatedToVersion(context.Configuration, matchVersion).OrderByDescending(tag => SemanticVersion.Parse(tag.Name, context.Configuration.TagPrefix));
return RetrieveMostRecentOptionalTagVersion(context, tagsInDescendingOrder.ToList());
Expand Down
4 changes: 2 additions & 2 deletions GitVersionCore/GitFlow/BranchFinders/ReleaseVersionFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ReleaseVersionFinder
public SemanticVersion FindVersion(GitVersionContext context)
{
var versionString = GetSuffix(context.CurrentBranch);
var shortVersion = ShortVersionParser.Parse(versionString);
var shortVersion = SemanticVersion.Parse(versionString, context.Configuration.TagPrefix);

EnsureVersionIsValid(shortVersion, context.CurrentBranch);

Expand All @@ -26,7 +26,7 @@ public SemanticVersion FindVersion(GitVersionContext context)
};
}

static void EnsureVersionIsValid(ShortVersion version, Branch branch)
static void EnsureVersionIsValid(SemanticVersion version, Branch branch)
{
if (version.Patch != 0)
{
Expand Down
10 changes: 5 additions & 5 deletions GitVersionCore/GitFlow/BranchFinders/SupportVersionFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ public SemanticVersion FindVersion(IRepository repository, Commit tip, Config co
{
foreach (var tag in repository.TagsByDate(tip))
{
ShortVersion shortVersion;
if (ShortVersionParser.TryParse(tag.Name, out shortVersion))
SemanticVersion shortVersion;
if (SemanticVersion.TryParse(tag.Name, configuration.TagPrefix, out shortVersion))
{
return BuildVersion(tip, shortVersion);
}
}

ShortVersion versionFromTip;
if (MergeMessageParser.TryParse(tip, out versionFromTip))
SemanticVersion versionFromTip;
if (MergeMessageParser.TryParse(tip, configuration, out versionFromTip))
{
var semanticVersion = BuildVersion(tip, versionFromTip);
semanticVersion.OverrideVersionManuallyIfNeeded(repository, configuration);
Expand All @@ -25,7 +25,7 @@ public SemanticVersion FindVersion(IRepository repository, Commit tip, Config co
throw new WarningException("The head of a support branch should always be a merge commit if you follow gitflow. Please create one or work around this by tagging the commit with SemVer compatible Id.");
}

SemanticVersion BuildVersion(Commit tip, ShortVersion shortVersion)
SemanticVersion BuildVersion(Commit tip, SemanticVersion shortVersion)
{
return new SemanticVersion
{
Expand Down
16 changes: 8 additions & 8 deletions GitVersionCore/GitFlow/BranchFinders/VersionOnMasterFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ public VersionPoint Execute(GitVersionContext context, DateTimeOffset olderThan)
{
foreach (var tag in context.Repository.TagsByDate(commit))
{
ShortVersion shortVersion;
if (ShortVersionParser.TryParseMajorMinor(tag.Name, out shortVersion))
SemanticVersion semanticVersion;
if (SemanticVersion.TryParse(tag.Name, context.Configuration.TagPrefix, out semanticVersion))
{
return new VersionPoint
{
Major = shortVersion.Major,
Minor = shortVersion.Minor,
Major = semanticVersion.Major,
Minor = semanticVersion.Minor,
};
}
}

ShortVersion shortVersionFromMergeMessage;
if (MergeMessageParser.TryParse(commit, out shortVersionFromMergeMessage))
SemanticVersion semanticVersionFromMergeMessage;
if (MergeMessageParser.TryParse(commit, context.Configuration, out semanticVersionFromMergeMessage))
{
return new VersionPoint
{
Major = shortVersionFromMergeMessage.Major,
Minor = shortVersionFromMergeMessage.Minor,
Major = semanticVersionFromMergeMessage.Major,
Minor = semanticVersionFromMergeMessage.Minor,
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion GitVersionCore/GitFlow/GitFlowVersionFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public SemanticVersion FindVersion(GitVersionContext context)
{
if (context.CurrentBranch.IsMaster())
{
return new MasterVersionFinder().FindVersion(context.Repository, context.CurrentCommit);
return new MasterVersionFinder().FindVersion(context);
}

if (context.CurrentBranch.IsHotfix())
Expand Down
6 changes: 3 additions & 3 deletions GitVersionCore/GitHubFlow/MergedBranchesWithVersionFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ public bool TryGetVersion(out SemanticVersion semanticVersion)
return true;
}

static IEnumerable<ShortVersion> GetAllVersions(GitVersionContext context)
static IEnumerable<SemanticVersion> GetAllVersions(GitVersionContext context)
{
foreach (var commit in context.CurrentBranch.Commits)
{
ShortVersion version;
if (MergeMessageParser.TryParse(commit, out version))
SemanticVersion version;
if (MergeMessageParser.TryParse(commit, context.Configuration, out version))
{
yield return version;
}
Expand Down
2 changes: 1 addition & 1 deletion GitVersionCore/GitHubFlow/OtherBranchVersionFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public bool FindVersion(GitVersionContext context, out SemanticVersion semanticV
semanticVersion = null;
return false;
}
var shortVersion = ShortVersionParser.Parse(versionString);
var shortVersion = SemanticVersion.Parse(versionString, context.Configuration.TagPrefix);


var applicableTagsInDescendingOrder = context.Repository.SemVerTagsRelatedToVersion(context.Configuration, shortVersion).OrderByDescending(tag => SemanticVersion.Parse(tag.Name, context.Configuration.TagPrefix)).ToList();
Expand Down
2 changes: 0 additions & 2 deletions GitVersionCore/GitVersionCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
<Compile Include="GitFlow\BranchFinders\BranchCommitDifferenceFinder.cs" />
<Compile Include="GitFlow\BranchFinders\RecentTagVersionExtractor.cs" />
<Compile Include="LastMinorVersionFinder.cs" />
<Compile Include="ShortVersion.cs" />
<Compile Include="SemanticVersionExtensions.cs" />
<Compile Include="WarningException.cs" />
<Compile Include="ExtensionMethods.cs" />
Expand Down Expand Up @@ -118,7 +117,6 @@
<Compile Include="SemanticVersion.cs" />
<Compile Include="SemanticVersionBuildMetaData.cs" />
<Compile Include="SemanticVersionPreReleaseTag.cs" />
<Compile Include="ShortVersionParser.cs" />
<Compile Include="GitFlow\BranchFinders\VersionOnMasterFinder.cs" />
<Compile Include="VersionPoint.cs" />
</ItemGroup>
Expand Down
Loading