Skip to content

Commit 2a95a40

Browse files
author
Ruh Ullah Shah
committed
Provided default values for the pre-release-weight, add a testcase to check for default value on the release branch, updated the approved file
1 parent 7ec72fc commit 2a95a40

File tree

3 files changed

+70
-9
lines changed

3 files changed

+70
-9
lines changed

src/GitVersionCore.Tests/ConfigProviderTests.CanWriteOutEffectiveConfiguration.approved.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ branches:
3737
tracks-release-branches: false
3838
is-release-branch: false
3939
is-mainline: true
40-
pre-release-weight: 0
40+
pre-release-weight: 60000
4141
release:
4242
mode: ContinuousDelivery
4343
tag: beta
@@ -53,7 +53,7 @@ branches:
5353
tracks-release-branches: false
5454
is-release-branch: true
5555
is-mainline: false
56-
pre-release-weight: 0
56+
pre-release-weight: 30000
5757
feature:
5858
mode: ContinuousDelivery
5959
tag: useBranchName
@@ -71,7 +71,7 @@ branches:
7171
tracks-release-branches: false
7272
is-release-branch: false
7373
is-mainline: false
74-
pre-release-weight: 0
74+
pre-release-weight: 30000
7575
pull-request:
7676
mode: ContinuousDelivery
7777
tag: PullRequest
@@ -90,7 +90,7 @@ branches:
9090
tracks-release-branches: false
9191
is-release-branch: false
9292
is-mainline: false
93-
pre-release-weight: 0
93+
pre-release-weight: 30000
9494
hotfix:
9595
mode: ContinuousDelivery
9696
tag: beta
@@ -105,7 +105,7 @@ branches:
105105
tracks-release-branches: false
106106
is-release-branch: false
107107
is-mainline: false
108-
pre-release-weight: 0
108+
pre-release-weight: 30000
109109
support:
110110
mode: ContinuousDelivery
111111
tag: ''
@@ -118,7 +118,7 @@ branches:
118118
tracks-release-branches: false
119119
is-release-branch: false
120120
is-mainline: true
121-
pre-release-weight: 0
121+
pre-release-weight: 60000
122122
ignore:
123123
sha: []
124124
commit-date-format: yyyy-MM-dd

src/GitVersionCore.Tests/IntegrationTests/ReleaseBranchScenarios.cs

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using GitTools.Testing;
1+
using GitTools.Testing;
22
using GitVersion;
33
using GitVersionCore.Tests;
44
using LibGit2Sharp;
@@ -551,6 +551,54 @@ public void FeatureFromReleaseBranch_ShouldNotResetCount()
551551
}
552552
}
553553

554+
<<<<<<< HEAD
555+
=======
556+
[Test]
557+
public void AssemblySemFileVerShouldBeWeightedByPreReleaseWeight()
558+
{
559+
var config = new Config
560+
{
561+
AssemblyFileVersioningFormat = "{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}",
562+
Branches =
563+
{
564+
{ "release", new BranchConfig
565+
{
566+
PreReleaseWeight = 1000
567+
}
568+
}
569+
}
570+
};
571+
using (var fixture = new EmptyRepositoryFixture())
572+
{
573+
fixture.Repository.MakeATaggedCommit("1.0.3");
574+
fixture.Repository.MakeCommits(5);
575+
fixture.Repository.CreateBranch("release-2.0.0");
576+
fixture.Checkout("release-2.0.0");
577+
ConfigurationProvider.ApplyDefaultsTo(config);
578+
var variables = fixture.GetVersion(config);
579+
Assert.AreEqual(variables.AssemblySemFileVer, "2.0.0.1001");
580+
}
581+
}
582+
583+
[Test]
584+
public void AssemblySemFileVerShouldBeWeightedByDefaultPreReleaseWeight()
585+
{
586+
var config = new Config
587+
{
588+
AssemblyFileVersioningFormat = "{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}",
589+
};
590+
using (var fixture = new EmptyRepositoryFixture())
591+
{
592+
fixture.Repository.MakeATaggedCommit("1.0.3");
593+
fixture.Repository.MakeCommits(5);
594+
fixture.Repository.CreateBranch("release-2.0.0");
595+
fixture.Checkout("release-2.0.0");
596+
ConfigurationProvider.ApplyDefaultsTo(config);
597+
var variables = fixture.GetVersion(config);
598+
Assert.AreEqual(variables.AssemblySemFileVer, "2.0.0.30001");
599+
}
600+
}
601+
554602
/// <summary>
555603
/// Create a feature branch from a release branch, and merge back, then delete it
556604
/// </summary>
@@ -650,4 +698,4 @@ public void AssemblySemFileVerShouldBeWeightedByPreReleaseWeight()
650698
Assert.AreEqual(variables.AssemblySemFileVer, "2.0.0.1001");
651699
}
652700
}
653-
}
701+
}

src/GitVersionCore/Configuration/ConfigurationProvider.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ public class ConfigurationProvider
2828
public const string HotfixBranchKey = "hotfix";
2929
public const string SupportBranchKey = "support";
3030
public const string DevelopBranchKey = "develop";
31+
public static Dictionary<string, int> DefaultPreReleaseWeight =
32+
new Dictionary<string, int>
33+
{
34+
{ DevelopBranchRegex, 0 },
35+
{ HotfixBranchRegex, 30000 },
36+
{ ReleaseBranchRegex, 30000 },
37+
{ FeatureBranchRegex, 30000 },
38+
{ PullRequestRegex, 30000 },
39+
{ SupportBranchRegex, 60000 },
40+
{ MasterBranchRegex, 60000 }
41+
};
3142

3243
private const IncrementStrategy DefaultIncrementStrategy = IncrementStrategy.Inherit;
3344

@@ -231,7 +242,9 @@ public static void ApplyBranchDefaults(Config config,
231242
branchConfig.TracksReleaseBranches = branchConfig.TracksReleaseBranches ?? tracksReleaseBranches;
232243
branchConfig.IsReleaseBranch = branchConfig.IsReleaseBranch ?? isReleaseBranch;
233244
branchConfig.IsMainline = branchConfig.IsMainline ?? isMainline;
234-
branchConfig.PreReleaseWeight = branchConfig.PreReleaseWeight ?? 0;
245+
int defaultPreReleaseNumber = 0;
246+
DefaultPreReleaseWeight.TryGetValue(branchRegex, out defaultPreReleaseNumber);
247+
branchConfig.PreReleaseWeight = branchConfig.PreReleaseWeight ?? defaultPreReleaseNumber;
235248
}
236249

237250
static Config ReadConfig(string workingDirectory, IFileSystem fileSystem)

0 commit comments

Comments
 (0)