Skip to content

Commit b29725c

Browse files
committed
Merge pull request #371 from JakeGinnivan/ReviewAndCommentFixes
Review and comment fixes
2 parents c9dd9ba + a525cfb commit b29725c

18 files changed

+74
-60
lines changed

GitVersionCore.Tests/ConfigProviderTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,20 @@ public void OverwritesDefaultsWithProvidedConfig()
8888
config.Branches["develop"].Tag.ShouldBe("dev");
8989
}
9090

91+
[Test]
92+
public void CanProvideConfigForNewBranch()
93+
{
94+
const string text = @"
95+
next-version: 2.0.0
96+
branches:
97+
bug[/-]:
98+
tag: bugfix";
99+
SetupConfigFileContent(text);
100+
var config = ConfigurationProvider.Provide(gitDirectory, fileSystem);
101+
102+
config.Branches["bug[/-]"].Tag.ShouldBe("bugfix");
103+
}
104+
91105
[Test]
92106
[MethodImpl(MethodImplOptions.NoInlining)]
93107
public void CanWriteOutEffectiveConfiguration()

GitVersionCore.Tests/GitVersionCore.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
<Compile Include="IntegrationTests\HotfixBranchScenarios.cs" />
9191
<Compile Include="IntegrationTests\ReleaseBranchScenarios.cs" />
9292
<Compile Include="IntegrationTests\SwitchingToGitFlowScenarios.cs" />
93+
<Compile Include="IntegrationTests\VersionBumpingScenarios.cs" />
9394
<Compile Include="IntegrationTests\WikiScenarios.cs" />
9495
<Compile Include="IntegrationTests\OtherBranchScenarios.cs" />
9596
<Compile Include="Helpers\Constants.cs" />

GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,7 @@ public void CanChangeDevelopTagViaConfig()
2626
fixture.Repository.MakeATaggedCommit("1.0.0");
2727
fixture.Repository.CreateBranch("develop").Checkout();
2828
fixture.Repository.MakeACommit();
29-
fixture.AssertFullSemver("1.1.0-alpha.1+1");
30-
}
31-
}
32-
33-
[Test]
34-
public void CanClearDevelopTagViaConfig()
35-
{
36-
var config = new Config();
37-
config.Branches["develop"].Tag = "";
38-
using (var fixture = new EmptyRepositoryFixture(config))
39-
{
40-
fixture.Repository.MakeATaggedCommit("1.0.0");
41-
fixture.Repository.CreateBranch("develop").Checkout();
42-
fixture.Repository.MakeACommit();
43-
fixture.AssertFullSemver("1.1.0+1");
29+
fixture.AssertFullSemver("1.1.0-alpha.1");
4430
}
4531
}
4632

@@ -52,7 +38,7 @@ public void WhenDevelopBranchedFromMaster_MinorIsIncreased()
5238
fixture.Repository.MakeATaggedCommit("1.0.0");
5339
fixture.Repository.CreateBranch("develop").Checkout();
5440
fixture.Repository.MakeACommit();
55-
fixture.AssertFullSemver("1.1.0-unstable.1+1");
41+
fixture.AssertFullSemver("1.1.0-unstable.1");
5642
}
5743
}
5844

@@ -71,7 +57,7 @@ public void MergingReleaseBranchBackIntoDevelopWithMergingToMaster_DoesBumpDevel
7157

7258
fixture.Repository.Checkout("develop");
7359
fixture.Repository.MergeNoFF("release-2.0.0", Constants.SignatureNow());
74-
fixture.AssertFullSemver("2.1.0-unstable.1+0");
60+
fixture.AssertFullSemver("2.1.0-unstable.0");
7561
}
7662
}
7763

@@ -100,7 +86,7 @@ public void WhenDevelopBranchedFromMasterDetachedHead_MinorIsIncreased()
10086
var commit = fixture.Repository.Head.Tip;
10187
fixture.Repository.MakeACommit();
10288
fixture.Repository.Checkout(commit);
103-
fixture.AssertFullSemver("1.1.0-unstable.1+1");
89+
fixture.AssertFullSemver("1.1.0-unstable.1");
10490
}
10591
}
10692
}

GitVersionCore.Tests/IntegrationTests/HotfixBranchScenarios.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ public void PatchLatestReleaseExample()
3333

3434
// Verify develop version
3535
fixture.Repository.Checkout("develop");
36-
fixture.AssertFullSemver("1.3.0-unstable.1+1");
36+
fixture.AssertFullSemver("1.3.0-unstable.1");
3737

3838
fixture.Repository.MergeNoFF("hotfix-1.2.1", Constants.SignatureNow());
39-
fixture.AssertFullSemver("1.3.0-unstable.1+0");
39+
fixture.AssertFullSemver("1.3.0-unstable.0");
4040
}
4141
}
4242

@@ -84,9 +84,9 @@ public void PatchOlderReleaseExample()
8484

8585
// Verify develop version
8686
fixture.Repository.Checkout("develop");
87-
fixture.AssertFullSemver("2.1.0-unstable.1+1");
87+
fixture.AssertFullSemver("2.1.0-unstable.1");
8888
fixture.Repository.MergeNoFF("support-1.1", Constants.SignatureNow());
89-
fixture.AssertFullSemver("2.1.0-unstable.1+7");
89+
fixture.AssertFullSemver("2.1.0-unstable.7");
9090
}
9191
}
9292
}

GitVersionCore.Tests/IntegrationTests/ReleaseBranchScenarios.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public void WhenReleaseBranchIsMergedIntoDevelopHighestVersionIsTakenWithIt()
129129
fixture.Repository.Checkout("develop");
130130
fixture.Repository.MergeNoFF("release-1.0.0", Constants.SignatureNow());
131131

132-
fixture.AssertFullSemver("2.1.0-unstable.1+5");
132+
fixture.AssertFullSemver("2.1.0-unstable.5");
133133
}
134134
}
135135

GitVersionCore.Tests/IntegrationTests/SwitchingToGitFlowScenarios.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public void WhenDevelopBranchedFromMasterWithLegacyVersionTags_DevelopCanUseReac
1414
fixture.Repository.MakeATaggedCommit("1.0.0.0");
1515
fixture.Repository.MakeCommits(2);
1616
fixture.Repository.CreateBranch("develop").Checkout();
17-
fixture.AssertFullSemver("1.1.0-unstable.1+2");
17+
fixture.AssertFullSemver("1.1.0-unstable.2");
1818
}
1919
}
2020
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using GitVersion;
2+
using NUnit.Framework;
3+
4+
[TestFixture]
5+
public class VersionBumpingScenarios
6+
{
7+
[Test]
8+
public void AppliedPrereleaseTagCausesBump()
9+
{
10+
var configuration = new Config();
11+
configuration.Branches["master"].Tag = "pre";
12+
using (var fixture = new EmptyRepositoryFixture(configuration))
13+
{
14+
fixture.Repository.MakeACommit();
15+
fixture.Repository.MakeATaggedCommit("1.0.0-pre.1");
16+
fixture.Repository.MakeACommit();
17+
18+
fixture.AssertFullSemver("1.0.0-pre.2+1");
19+
}
20+
}
21+
}

GitVersionCore.Tests/IntegrationTests/WikiScenarios.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void MinorReleaseExample()
4545
// Branch to develop
4646
fixture.Repository.CreateBranch("develop").Checkout();
4747
fixture.Repository.MakeACommit();
48-
fixture.AssertFullSemver("1.3.0-unstable.1+1");
48+
fixture.AssertFullSemver("1.3.0-unstable.1");
4949

5050
// Open Pull Request
5151
fixture.Repository.CreateBranch("pull/2/merge").Checkout();
@@ -56,7 +56,7 @@ public void MinorReleaseExample()
5656
// Merge into develop
5757
fixture.Repository.Checkout("develop");
5858
fixture.Repository.MergeNoFF("pull/2/merge", Constants.SignatureNow());
59-
fixture.AssertFullSemver("1.3.0-unstable.1+3");
59+
fixture.AssertFullSemver("1.3.0-unstable.3");
6060

6161
// Create release branch
6262
fixture.Repository.CreateBranch("release-1.3.0").Checkout();
@@ -65,7 +65,7 @@ public void MinorReleaseExample()
6565
// Make another commit on develop
6666
fixture.Repository.Checkout("develop");
6767
fixture.Repository.MakeACommit();
68-
fixture.AssertFullSemver("1.3.0-unstable.1+4");
68+
fixture.AssertFullSemver("1.3.0-unstable.4");
6969

7070
// Make a commit to release-1.3.0
7171
fixture.Repository.Checkout("release-1.3.0");
@@ -89,7 +89,7 @@ public void MinorReleaseExample()
8989
// Verify develop version
9090
fixture.Repository.Checkout("develop");
9191
fixture.Repository.MergeNoFF("release-1.3.0", Constants.SignatureNow());
92-
fixture.AssertFullSemver("1.4.0-unstable.1+0");
92+
fixture.AssertFullSemver("1.4.0-unstable.0");
9393
}
9494
}
9595
}

GitVersionCore.Tests/VariableProviderTests.ProvidesVariablesInContinuousDeploymentModeForPreRelease.approved.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
"LegacySemVer":"1.2.3-unstable5",
1212
"LegacySemVerPadded":"1.2.3-unstable0005",
1313
"AssemblySemVer":"1.2.3.0",
14-
"FullSemVer":"1.2.3-unstable.5+4",
15-
"InformationalVersion":"1.2.3-unstable.5+4.Branch.develop.Sha.commitSha",
14+
"FullSemVer":"1.2.3-unstable.5",
15+
"InformationalVersion":"1.2.3-unstable.5+Branch.develop.Sha.commitSha",
1616
"BranchName":"develop",
1717
"Sha":"commitSha",
1818
"NuGetVersionV2":"1.2.3-unstable0005",

GitVersionCore/BranchConfigurationCalculator.cs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static KeyValuePair<string, BranchConfig> InheritBranchConfiguration(
3939
BranchConfig branchConfiguration, Config config)
4040
{
4141
Logger.WriteInfo("Attempting to inherit branch configuration from parent branch");
42-
var excludedBranches = new Branch[0];
42+
var excludedBranches = new [] { currentBranch };
4343
// Check if we are a merge commit. If so likely we are a pull request
4444
var parentCount = currentCommit.Parents.Count();
4545
if (parentCount == 2)
@@ -68,15 +68,12 @@ static KeyValuePair<string, BranchConfig> InheritBranchConfiguration(
6868
List<Branch> possibleParents;
6969
if (branchPoint.Sha == currentCommit.Sha)
7070
{
71-
possibleParents = ListBranchesContaininingCommit(repository, currentCommit.Sha, excludedBranches).Except(new[]
72-
{
73-
currentBranch
74-
}).ToList();
71+
possibleParents = currentCommit.GetBranchesContainingCommit(repository, true).Except(excludedBranches).ToList();
7572
}
7673
else
7774
{
78-
var branches = ListBranchesContaininingCommit(repository, branchPoint.Sha, excludedBranches).ToList();
79-
var currentTipBranches = ListBranchesContaininingCommit(repository, currentCommit.Sha, excludedBranches).ToList();
75+
var branches = branchPoint.GetBranchesContainingCommit(repository, true).Except(excludedBranches).ToList();
76+
var currentTipBranches = currentCommit.GetBranchesContainingCommit(repository, true).Except(excludedBranches).ToList();
8077
possibleParents = branches
8178
.Except(currentTipBranches)
8279
.ToList();
@@ -119,14 +116,5 @@ static KeyValuePair<string, BranchConfig> InheritBranchConfiguration(
119116
Increment = GetBranchConfiguration(currentCommit, repository, onlyEvaluateTrackedBranches, config, repository.Branches[branchName]).Value.Increment
120117
});
121118
}
122-
123-
static IEnumerable<Branch> ListBranchesContaininingCommit(IRepository repo, string commitSha, Branch[] excludedBranches)
124-
{
125-
return from branch in repo.Branches.Except(excludedBranches)
126-
where !branch.IsRemote
127-
let commits = repo.Commits.QueryBy(new CommitFilter { Since = branch }).Where(c => c.Sha == commitSha)
128-
where commits.Any()
129-
select branch;
130-
}
131119
}
132120
}

0 commit comments

Comments
 (0)