-
Notifications
You must be signed in to change notification settings - Fork 654
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
Changes from all commits
f85cd83
62b6f42
b25220a
8ee25e8
a74bbf5
aa54a21
7a0267f
83d3862
a952bb1
690399e
810d309
3e0be76
2dbcc84
204d2bc
e999a62
900ccf6
8ab088f
b7c090d
f7e30c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
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> | ||
|
@@ -8,7 +9,10 @@ public class MockCommitLog : ICommitLog, ICollection<Commit> | |
|
||
public IEnumerator<Commit> GetEnumerator() | ||
{ | ||
return Commits.GetEnumerator(); | ||
if (SortedBy == CommitSortStrategies.Reverse) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems weird. If reverse then we dont reverse? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, so I think this is right.
I think this is all good |
||
return Commits.GetEnumerator(); | ||
|
||
return Enumerable.Reverse(Commits).GetEnumerator(); | ||
} | ||
|
||
IEnumerator IEnumerable.GetEnumerator() | ||
|
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(); | ||
} | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see