Skip to content

Config based versioning improvements #346

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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
f85cd83
Starting on base version calculators
JakeGinnivan Jan 10, 2015
62b6f42
Added merge message base version strategy
JakeGinnivan Jan 10, 2015
b25220a
Adding LastTagBaseVersionStrategy
JakeGinnivan Jan 10, 2015
8ee25e8
Created NewNextVersionCalculator which is the new version calculation
JakeGinnivan Jan 10, 2015
a74bbf5
Added MetaDataCalculator in and fixed up some other shortcomings in t…
JakeGinnivan Jan 10, 2015
aa54a21
Uncomment line in GitVersionFinder to test new way of doing things. I…
JakeGinnivan Jan 10, 2015
7a0267f
Should not increment version when current commit is tagged
JakeGinnivan Jan 11, 2015
83d3862
Added missing base version finder
JakeGinnivan Jan 11, 2015
a952bb1
Allow inheriting of the parent branches increment strategy. Allows fe…
JakeGinnivan Jan 11, 2015
690399e
When branch configuration has 'Tag' set to 'useBranchName' it will us…
JakeGinnivan Jan 11, 2015
810d309
Fixed a few tests and the way inheriting increment strategy works
JakeGinnivan Jan 11, 2015
3e0be76
Base versions can specify whether the tag should be updated
JakeGinnivan Jan 11, 2015
2dbcc84
Fixing incorrect tests, when develop is branched from master it is st…
JakeGinnivan Jan 11, 2015
204d2bc
Fixed some exceptions which were causing tests to blow up and not get…
JakeGinnivan Jan 11, 2015
e999a62
Think the code is mostly there. It is now mainly fixing commit counti…
JakeGinnivan Jan 11, 2015
900ccf6
Fixed failing tests
JakeGinnivan Jan 12, 2015
8ab088f
Fixed build issue
JakeGinnivan Jan 14, 2015
b7c090d
Removed branch comparer
JakeGinnivan Jan 16, 2015
f7e30c4
Turned on new code
JakeGinnivan Jan 16, 2015
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
17 changes: 0 additions & 17 deletions GitVersionCore.Tests/Fixtures/BaseGitFlowRepositoryFixture.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.IO;
using System.Text;
using GitVersion;
using GitVersion.Helpers;
using LibGit2Sharp;

/// <summary>
Expand Down Expand Up @@ -41,19 +39,4 @@ void SetupRepo(Action<IRepository> initialMasterAction)
Repository.CreateBranch("develop").Checkout();
Repository.MakeACommit();
}

public void DumpGraph()
{
var output = new StringBuilder();

ProcessHelper.Run(
o => output.AppendLine(o),
e => output.AppendLineFormat("ERROR: {0}", e),
null,
"git",
@"log --graph --abbrev-commit --decorate --date=relative --all",
RepositoryPath);

Console.Write(output.ToString());
}
}
17 changes: 17 additions & 0 deletions GitVersionCore.Tests/Fixtures/EmptyRepositoryFixture.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Text;
using GitVersion;
using GitVersion.Helpers;
using LibGit2Sharp;

public class EmptyRepositoryFixture : RepositoryFixtureBase
Expand All @@ -9,6 +11,21 @@ public EmptyRepositoryFixture(Config configuration) :
{
}

public void DumpGraph()
{
var output = new StringBuilder();

ProcessHelper.Run(
o => output.AppendLine(o),
e => output.AppendLineFormat("ERROR: {0}", e),
null,
"git",
@"log --graph --abbrev-commit --decorate --date=relative --all",
RepositoryPath);

Console.Write(output.ToString());
}

static IRepository CreateNewRepository(string path)
{
LibGit2Sharp.Repository.Init(path);
Expand Down
80 changes: 80 additions & 0 deletions GitVersionCore.Tests/GitVersionContextBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
namespace GitVersionCore.Tests
{
using GitVersion;
using LibGit2Sharp;

public class GitVersionContextBuilder
{
IRepository repository;
Config config;

public GitVersionContextBuilder WithRepository(IRepository repository)
{
this.repository = repository;
return this;
}

public GitVersionContextBuilder WithConfig(Config config)
{
this.config = config;
return this;
}

public GitVersionContextBuilder WithTaggedMaster()
{
repository = CreateRepository();
var target = repository.Head.Tip;
((MockTagCollection)repository.Tags).Add(new MockTag ("1.0.0", target));
return this;
}

public GitVersionContextBuilder AddCommit()
{
((MockBranch)repository.Head).Add(new MockCommit());
return this;
}

public GitVersionContextBuilder WithDevelopBranch()
{
return WithBranch("develop");
}

public GitVersionContextBuilder WithBranch(string branchName)
{
repository = CreateRepository();
return AddBranch(branchName);
}

public GitVersionContextBuilder AddBranch(string branchName)
{
var mockBranch = new MockBranch(branchName)
{
new MockCommit()
};
((MockBranchCollection)repository.Branches).Add(mockBranch);
((MockRepository)repository).Head = mockBranch;
return this;
}

public GitVersionContext Build()
{
return new GitVersionContext(repository ?? CreateRepository(), config ?? new Config());
}

IRepository CreateRepository()
{
var mockBranch = new MockBranch("master") { new MockCommit { CommitterEx = SignatureBuilder.SignatureNow() } };
var mockRepository = new MockRepository
{
Branches = new MockBranchCollection
{
mockBranch
},
Tags = new MockTagCollection(),
Head = mockBranch
};

return mockRepository;
}
}
}
22 changes: 22 additions & 0 deletions GitVersionCore.Tests/GitVersionContextTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace GitVersionCore.Tests
{
using GitVersion;
using LibGit2Sharp;
using NUnit.Framework;
using Shouldly;

Expand Down Expand Up @@ -50,5 +51,26 @@ public void UsesBranchSpecificConfigOverTopLevelDefaults()
context.Configuration.VersioningMode.ShouldBe(VersioningMode.ContinuousDeployment);
context.Configuration.Tag.ShouldBe("alpha");
}

[Test]
public void CanFindParentBranchForInheritingIncrementStrategy()
{
var config = new Config();
config.Branches["develop"].Increment = IncrementStrategy.Major;
config.Branches["feature[/-]"].Increment = IncrementStrategy.Inherit;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This solves the issue with feature branches which are taken off master should bump patch but feature branches off develop should bump minor

Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't IncrementStrategy.Inherit default for feature branches?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I just thought I would make it explicit in the test. The test doesn't make sense without that knowledge

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I see


using (var repo = new EmptyRepositoryFixture(config))
{
repo.Repository.MakeACommit();
repo.Repository.CreateBranch("develop").Checkout();
repo.Repository.MakeACommit();
var featureBranch = repo.Repository.CreateBranch("feature/foo");
featureBranch.Checkout();
repo.Repository.MakeACommit();

var context = new GitVersionContext(repo.Repository, config);
context.Configuration.Increment.ShouldBe(IncrementStrategy.Major);
}
}
}
}
10 changes: 10 additions & 0 deletions GitVersionCore.Tests/GitVersionCore.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
<Compile Include="Mocks\MockCommit.cs" />
<Compile Include="Mocks\MockCommitLog.cs" />
<Compile Include="Mocks\MockMergeCommit.cs" />
<Compile Include="Mocks\MockQueryableCommitLog.cs" />
<Compile Include="Mocks\MockReferenceCollection.cs" />
<Compile Include="Mocks\MockReflogCollection.cs" />
<Compile Include="Mocks\MockRepository.cs" />
Expand All @@ -114,6 +115,15 @@
<Compile Include="TestEffectiveConfiguration.cs" />
<Compile Include="TestFileSystem.cs" />
<Compile Include="VariableProviderTests.cs" />
<Compile Include="VersionCalculation\BaseVersionCalculatorTests.cs" />
<Compile Include="VersionCalculation\NewNextVersionCalculatorTests.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" />
<Compile Include="VersionCalculation\TestMetaDataCalculator.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down
20 changes: 17 additions & 3 deletions GitVersionCore.Tests/IntegrationTests/GitFlow/DevelopScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,43 @@
public class DevelopScenarios
{
[Test]
public void WhenDevelopBranchedFromMaster_MinorIsIncreased()
public void WhenDevelopBranchedFromTaggedCommitOnMasterVersionDoesNotChange()
{
using (var fixture = new EmptyRepositoryFixture(new Config()))
{
fixture.Repository.MakeATaggedCommit("1.0.0");
fixture.Repository.CreateBranch("develop").Checkout();
// TODO Should actually be 1.0.0+0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we have a bug at the moment.

If I tag master, then branch develop from that tag it gets an unstable pre-release tag. It shouldn't because that commit is tagged.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed this seems like a bug

fixture.AssertFullSemver("1.1.0-unstable.0+0");
}
}

[Test]
public void WhenDevelopBranchedFromMaster_MinorIsIncreased()
{
using (var fixture = new EmptyRepositoryFixture(new Config()))
{
fixture.Repository.MakeATaggedCommit("1.0.0");
fixture.Repository.CreateBranch("develop").Checkout();
fixture.Repository.MakeACommit();
fixture.AssertFullSemver("1.1.0-unstable.1+1");
}
}

[Test]
public void MergingReleaseBranchBackIntoDevelopWithoutMergingToMaster_DoesNotBumpDevelopVersion()
{
using (var fixture = new EmptyRepositoryFixture(new Config()))
{
fixture.Repository.MakeATaggedCommit("1.0.0");
fixture.Repository.CreateBranch("develop").Checkout();
fixture.Repository.MakeACommit();
fixture.Repository.CreateBranch("release-2.0.0").Checkout();
fixture.AssertFullSemver("2.0.0-beta.1+0");
fixture.Repository.Checkout("develop");
fixture.AssertFullSemver("1.1.0-unstable.0+0");
fixture.AssertFullSemver("1.1.0-unstable.1+1");
fixture.Repository.MergeNoFF("release-2.0.0", Constants.SignatureNow());
fixture.AssertFullSemver("1.1.0-unstable.0+0");
fixture.AssertFullSemver("1.1.0-unstable.1+1");
}
}

Expand Down
9 changes: 7 additions & 2 deletions GitVersionCore.Tests/Mocks/MockCommit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@
[DebuggerDisplay("{DebuggerDisplay}")]
public class MockCommit : Commit
{
static int commitCount = 1;
static DateTimeOffset when = DateTimeOffset.Now;

public MockCommit(ObjectId id = null)
{
idEx = id ?? new ObjectId(Guid.NewGuid().ToString().Replace("-", "") + "00000000");
MessageEx = "";
MessageEx = "Commit " + commitCount++;
ParentsEx = new List<Commit> { null };
CommitterEx = new Signature("Joe", "[email protected]", DateTimeOffset.Now);
CommitterEx = new Signature("Joe", "[email protected]", when);
// Make sure each commit is a different time
when = when.AddSeconds(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

No issues with this and running test multithreaded? Can think of any but just wanted to ensure static shared state was ok

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really, if two tests get the same time that is not an issue. It is within the same test we want it to bump

}

public string MessageEx;
Expand Down
6 changes: 5 additions & 1 deletion GitVersionCore.Tests/Mocks/MockCommitLog.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using LibGit2Sharp;

public class MockCommitLog : ICommitLog, ICollection<Commit>
Expand All @@ -8,7 +9,10 @@ public class MockCommitLog : ICommitLog, ICollection<Commit>

public IEnumerator<Commit> GetEnumerator()
{
return Commits.GetEnumerator();
if (SortedBy == CommitSortStrategies.Reverse)
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems weird. If reverse then we dont reverse?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By default libgit2 starts at latest commit and goes back. Or at least seems to, I naively put reverse = oldest first. @nulltoken what should I do here

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure to understand why you'd like it reversed. Could you please me a little bit more context?

FWIW, CommitSortStrategies.Reverse will take more time as the whole log has to be walked before yielding the first result. The default mimics the git.git git log behavior that makes sense most of the time and allow to stream the results as the log is walked.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, so I think this is right.

Commits.Add() will add to the bottom of the list internally. So to replicate the commit log we call .Reverse(), but if you pass that flag I don't reverse.

I think this is all good

return Commits.GetEnumerator();

return Enumerable.Reverse(Commits).GetEnumerator();
}

IEnumerator IEnumerable.GetEnumerator()
Expand Down
44 changes: 44 additions & 0 deletions GitVersionCore.Tests/Mocks/MockQueryableCommitLog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections;
using System.Collections.Generic;
using LibGit2Sharp;

public class MockQueryableCommitLog : IQueryableCommitLog
{
readonly ICommitLog commits;

public MockQueryableCommitLog(ICommitLog commits)
{
this.commits = commits;
}

public IEnumerator<Commit> GetEnumerator()
{
return commits.GetEnumerator();
}

IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}

public CommitSortStrategies SortedBy
{
get { throw new NotImplementedException(); }
}

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

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

public Commit FindMergeBase(IEnumerable<Commit> commits, MergeBaseFindingStrategy strategy)
{
throw new NotImplementedException();
}
}
10 changes: 9 additions & 1 deletion GitVersionCore.Tests/Mocks/MockRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

public class MockRepository : IRepository
{
IQueryableCommitLog commits;

public MockRepository()
{
Tags = new MockTagCollection();
Expand Down Expand Up @@ -116,7 +118,13 @@ public BlameHunkCollection Blame(string path, BlameOptions options = null)
public Configuration Config { get; set; }
public Index Index { get; set; }
public ReferenceCollection Refs { get; set; }
public IQueryableCommitLog Commits { get; set; }

public IQueryableCommitLog Commits
{
get { return commits ?? new MockQueryableCommitLog(Head.Commits); }
set { commits = value; }
}

public BranchCollection Branches { get; set; }
public TagCollection Tags { get; set; }
public RepositoryInformation Info { get; set; }
Expand Down
9 changes: 9 additions & 0 deletions GitVersionCore.Tests/Mocks/MockTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ public override GitObject Target
get { return TargetEx; }
}
public TagAnnotation AnnotationEx;

public MockTag() { }

public MockTag(string name, Commit target)
{
NameEx = name;
TargetEx = target;
}

public override TagAnnotation Annotation
{
get { return AnnotationEx; }
Expand Down
5 changes: 3 additions & 2 deletions GitVersionCore.Tests/TestEffectiveConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ public TestEffectiveConfiguration(
VersioningMode versioningMode = VersioningMode.ContinuousDelivery,
string gitTagPrefix = "v",
string tag = "",
string nextVersion = null) :
base(assemblyVersioningScheme, versioningMode, gitTagPrefix, tag, nextVersion)
string nextVersion = null,
string branchPrefixToTrim = "") :
base(assemblyVersioningScheme, versioningMode, gitTagPrefix, tag, nextVersion, IncrementStrategy.Patch, branchPrefixToTrim)
{
}
}
Expand Down
Loading