Skip to content
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

Feature/dont reset count when version will be the same #478

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
1 change: 0 additions & 1 deletion GitVersionCore.Tests/GitVersionCore.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@
<Compile Include="VersionCalculation\NextVersionCalculatorTests.cs" />
<Compile Include="VersionCalculation\Strategies\ConfigNextVersionBaseVersionStrategyTests.cs" />
<Compile Include="GitVersionContextBuilder.cs" />
<Compile Include="VersionCalculation\Strategies\LastTagBaseVersionStrategyTests.cs" />
<Compile Include="VersionCalculation\Strategies\MergeMessageBaseVersionStrategyTests.cs" />
<Compile Include="VersionCalculation\Strategies\VersionInBranchBaseVersionStrategyTests.cs" />
<Compile Include="VersionCalculation\TestBaseVersionCalculator.cs" />
Expand Down
14 changes: 7 additions & 7 deletions GitVersionCore.Tests/IntegrationTests/HotfixBranchScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ public void PatchLatestReleaseExample()
// create hotfix
fixture.Repository.CreateBranch("hotfix-1.2.1").Checkout();

fixture.AssertFullSemver("1.2.1-beta.1+0");
fixture.Repository.MakeACommit();
fixture.AssertFullSemver("1.2.1-beta.1+1");
fixture.Repository.MakeACommit();
fixture.AssertFullSemver("1.2.1-beta.1+2");
fixture.Repository.ApplyTag("1.2.1-beta.1");
fixture.AssertFullSemver("1.2.1-beta.1");
fixture.Repository.MakeACommit();
fixture.AssertFullSemver("1.2.1-beta.2+2");
fixture.AssertFullSemver("1.2.1-beta.2+3");

// Merge hotfix branch to master
fixture.Repository.Checkout("master");


fixture.Repository.MergeNoFF("hotfix-1.2.1", Constants.SignatureNow());
fixture.AssertFullSemver("1.2.1+0");
fixture.AssertFullSemver("1.2.1+4");

fixture.Repository.ApplyTag("1.2.1");
fixture.AssertFullSemver("1.2.1");
Expand All @@ -36,7 +36,7 @@ public void PatchLatestReleaseExample()
fixture.AssertFullSemver("1.3.0-unstable.1");

fixture.Repository.MergeNoFF("hotfix-1.2.1", Constants.SignatureNow());
fixture.AssertFullSemver("1.3.0-unstable.0");
fixture.AssertFullSemver("1.3.0-unstable.4");
}
}

Expand Down Expand Up @@ -73,12 +73,12 @@ public void PatchOlderReleaseExample()
fixture.AssertFullSemver("1.1.1-PullRequest.2+4");
fixture.Repository.Checkout("hotfix-1.1.1");
fixture.Repository.MergeNoFF("feature/fix", Constants.SignatureNow());
fixture.AssertFullSemver("1.1.1-beta.1+1");
fixture.AssertFullSemver("1.1.1-beta.1+4");

// Merge hotfix into support branch to complete hotfix
fixture.Repository.Checkout("support-1.1");
fixture.Repository.MergeNoFF("hotfix-1.1.1", Constants.SignatureNow());
fixture.AssertFullSemver("1.1.1+0");
fixture.AssertFullSemver("1.1.1+5");
fixture.Repository.ApplyTag("1.1.1");
fixture.AssertFullSemver("1.1.1");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ public void NoMergeBacksToDevelopInCaseThereAreChangesInReleaseBranch()
// Merge to develop
fixture.Repository.Checkout("develop");
fixture.Repository.MergeNoFF("release/1.0.0");
fixture.AssertFullSemver("1.1.0-unstable.1");

fixture.Repository.MakeACommit();
fixture.Repository.Branches.Remove(releaseBranch);

fixture.AssertFullSemver("1.1.0-unstable.1");
fixture.AssertFullSemver("1.1.0-unstable.2");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void SupportIsCalculatedCorrectly()
fixture.AssertFullSemver("1.2.1-beta.1+1");
fixture.Repository.Checkout("support/1.0.0");
fixture.Repository.MergeNoFF("hotfix/1.2.1");
fixture.AssertFullSemver("1.2.1+0");
fixture.AssertFullSemver("1.2.1+2");
}
}

Expand Down
4 changes: 3 additions & 1 deletion GitVersionCore.Tests/IntegrationTests/WikiScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ public void MinorReleaseExample()

// Verify develop version
fixture.Repository.Checkout("develop");
fixture.AssertFullSemver("1.3.0-unstable.4");
fixture.Repository.MergeNoFF("release-1.3.0", Constants.SignatureNow());
fixture.AssertFullSemver("1.4.0-unstable.0");
// Not 0 for commit count as we can't know the increment rules of the merged branch
fixture.AssertFullSemver("1.4.0-unstable.2");
}
}
}
4 changes: 2 additions & 2 deletions GitVersionCore.Tests/Mocks/MockQueryableCommitLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ public CommitSortStrategies SortedBy

public ICommitLog QueryBy(CommitFilter filter)
{
throw new NotImplementedException();
return this;
}

public Commit FindMergeBase(Commit first, Commit second)
{
throw new NotImplementedException();
return null;
}

public Commit FindMergeBase(IEnumerable<Commit> commits, MergeBaseFindingStrategy strategy)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace GitVersionCore.Tests.VersionCalculation
{
using System;
using System.Collections.Generic;
using GitVersion;
using GitVersion.VersionCalculation;
using GitVersion.VersionCalculation.BaseVersionCalculators;
Expand Down Expand Up @@ -62,9 +63,9 @@ public V1Strategy(DateTimeOffset? when)
this.when = when == null ? null : new MockCommit { CommitterEx = when.Value.ToSignature() };
}

public override BaseVersion GetVersion(GitVersionContext context)
public override IEnumerable<BaseVersion> GetVersions(GitVersionContext context)
{
return new BaseVersion("Source 1", false, new SemanticVersion(1), when, null);
yield return new BaseVersion("Source 1", false, new SemanticVersion(1), when, null);
}
}

Expand All @@ -77,9 +78,9 @@ public V2Strategy(DateTimeOffset? when)
this.when = when == null ? null : new MockCommit { CommitterEx = when.Value.ToSignature() };
}

public override BaseVersion GetVersion(GitVersionContext context)
public override IEnumerable<BaseVersion> GetVersions(GitVersionContext context)
{
return new BaseVersion("Source 2", true, new SemanticVersion(2), when, null);
yield return new BaseVersion("Source 2", true, new SemanticVersion(2), when, null);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace GitVersionCore.Tests.VersionCalculation.Strategies
{
using System.Linq;
using GitVersion;
using GitVersion.VersionCalculation.BaseVersionCalculators;
using NUnit.Framework;
Expand All @@ -18,7 +19,7 @@ public void ShouldNotBeIncremented()
});
var sut = new ConfigNextVersionBaseVersionStrategy();

var baseVersion = sut.GetVersion(contextBuilder.Build());
var baseVersion = sut.GetVersions(contextBuilder.Build()).Single();

baseVersion.ShouldIncrement.ShouldBe(false);
baseVersion.SemanticVersion.ToString().ShouldBe("1.0.0");
Expand All @@ -30,7 +31,7 @@ public void ReturnsNullWhenNoNextVersionIsInConfig()
var contextBuilder = new GitVersionContextBuilder();
var sut = new ConfigNextVersionBaseVersionStrategy();

var baseVersion = sut.GetVersion(contextBuilder.Build());
var baseVersion = sut.GetVersions(contextBuilder.Build()).SingleOrDefault();

baseVersion.ShouldBe(null);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace GitVersionCore.Tests.VersionCalculation.Strategies
{
using System.Collections.Generic;
using System.Linq;
using GitVersion.VersionCalculation.BaseVersionCalculators;
using LibGit2Sharp;
using NUnit.Framework;
Expand All @@ -24,7 +25,7 @@ public void ShouldNotAllowIncrementOfVersion()
}).Build();
var sut = new MergeMessageBaseVersionStrategy();

var baseVersion = sut.GetVersion(context);
var baseVersion = sut.GetVersions(context).Single();

baseVersion.ShouldIncrement.ShouldBe(false);
}
Expand Down Expand Up @@ -109,7 +110,7 @@ static void AssertMergeMessage(string message, string expectedVersion, List<Comm
.Build();
var sut = new MergeMessageBaseVersionStrategy();

var baseVersion = sut.GetVersion(context);
var baseVersion = sut.GetVersions(context).SingleOrDefault();

if (expectedVersion == null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace GitVersionCore.Tests.VersionCalculation.Strategies
{
using System.Linq;
using GitVersion;
using GitVersion.VersionCalculation.BaseVersionCalculators;
using LibGit2Sharp;
Expand All @@ -25,7 +26,7 @@ public void CanTakeVersionFromBranchName(string branchName, string expectedBaseV
var branch = fixture.Repository.CreateBranch(branchName);
var sut = new VersionInBranchBaseVersionStrategy();

var baseVersion = sut.GetVersion(new GitVersionContext(fixture.Repository, branch, configuration));
var baseVersion = sut.GetVersions(new GitVersionContext(fixture.Repository, branch, configuration)).SingleOrDefault();

if (expectedBaseVersion == null)
baseVersion.ShouldBe(null);
Expand Down
43 changes: 33 additions & 10 deletions GitVersionCore/LibGitExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,43 @@ public static Branch FindBranch(this IRepository repository, string branchName)
return repository.Branches.FirstOrDefault(x => x.Name == "origin/" + branchName);
}

public static SemanticVersion LastVersionTagOnBranch(this Branch branch, IRepository repository, string tagPrefixRegex)
{
var tags = repository.Tags.Select(t => t).ToList();
var until = FindCommitBranchWasBranchedFrom(branch, repository);

return repository.Commits.QueryBy(new CommitFilter
{
Since = branch.Tip,
Until = until
})
.SelectMany(c => tags.Where(t => c.Sha == t.Target.Sha).SelectMany(t =>
{
SemanticVersion semver;
if (SemanticVersion.TryParse(t.Name, tagPrefixRegex, out semver))
return new [] { semver };
return new SemanticVersion[0];
}))
.FirstOrDefault();
}

public static Commit FindCommitBranchWasBranchedFrom(this Branch branch, IRepository repository, params Branch[] excludedBranches)
{
var otherBranches = repository.Branches.Except(excludedBranches).Where(b => IsSameBranch(branch, b)).ToList();
var mergeBases = otherBranches.Select(b =>
using (Logger.IndentLog("Finding branch source"))
{
var otherCommit = b.Tip;
if (b.Tip.Parents.Contains(branch.Tip))
var otherBranches = repository.Branches.Except(excludedBranches).Where(b => IsSameBranch(branch, b)).ToList();
var mergeBases = otherBranches.Select(b =>
{
otherCommit = b.Tip.Parents.First();
}
var mergeBase = repository.Commits.FindMergeBase(otherCommit, branch.Tip);
return mergeBase;
}).Where(b => b != null).ToList();
return mergeBases.OrderByDescending(b => b.Committer.When).FirstOrDefault();
var otherCommit = b.Tip;
if (b.Tip.Parents.Contains(branch.Tip))
{
otherCommit = b.Tip.Parents.First();
}
var mergeBase = repository.Commits.FindMergeBase(otherCommit, branch.Tip);
return mergeBase;
}).Where(b => b != null).ToList();
return mergeBases.OrderByDescending(b => b.Committer.When).FirstOrDefault();
}
}

static bool IsSameBranch(Branch branch, Branch b)
Expand Down
2 changes: 1 addition & 1 deletion GitVersionCore/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ static Logger()
public static IDisposable IndentLog(string operationDescription)
{
var start = DateTime.Now;
indent = indent + " ";
WriteInfo("Begin: " + operationDescription);
indent = indent + " ";
return new ActionDisposable(() =>
{
indent = indent.Substring(0, indent.Length - 2);
Expand Down
5 changes: 0 additions & 5 deletions GitVersionCore/SemanticVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,22 +280,18 @@ public SemanticVersion IncrementVersion(IncrementStrategy incrementStrategy)
switch (incrementStrategy)
{
case IncrementStrategy.None:
Logger.WriteInfo("Skipping version increment");
break;
case IncrementStrategy.Major:
Logger.WriteInfo("Incrementing Major Version");
incremented.Major++;
incremented.Minor = 0;
incremented.Patch = 0;
break;
case IncrementStrategy.Minor:
incremented.Minor++;
incremented.Patch = 0;
Logger.WriteInfo("Incrementing Minor Version");
break;
case IncrementStrategy.Patch:
incremented.Patch++;
Logger.WriteInfo("Incrementing Patch Version");
break;
default:
throw new ArgumentOutOfRangeException();
Expand All @@ -305,7 +301,6 @@ public SemanticVersion IncrementVersion(IncrementStrategy incrementStrategy)
{
if (incremented.PreReleaseTag.Number != null)
{
Logger.WriteInfo("Incrementing prerelease");
incremented.PreReleaseTag.Number = incremented.PreReleaseTag.Number;
incremented.PreReleaseTag.Number++;
}
Expand Down
Loading