Skip to content

Commit 88aa7aa

Browse files
committed
Added tests for overriding develop tag via config and updated msbuild Tasks
1 parent 681a741 commit 88aa7aa

File tree

3 files changed

+74
-2
lines changed

3 files changed

+74
-2
lines changed

GitVersionCore.Tests/GitFlow/DevelopScenarios.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,34 @@ public void WhenDevelopBranchedFromMaster_MinorIsIncreased()
1515
fixture.AssertFullSemver("1.1.0-unstable.0+0");
1616
}
1717
}
18+
19+
[Test]
20+
public void CanChangeDevelopTagViaConfig()
21+
{
22+
using (var fixture = new EmptyRepositoryFixture(new Config
23+
{
24+
DevelopBranchTag = "alpha"
25+
}))
26+
{
27+
fixture.Repository.MakeATaggedCommit("1.0.0");
28+
fixture.Repository.CreateBranch("develop").Checkout();
29+
fixture.AssertFullSemver("1.1.0-alpha.0+0");
30+
}
31+
}
32+
33+
[Test]
34+
public void CanClearDevelopTagViaConfig()
35+
{
36+
using (var fixture = new EmptyRepositoryFixture(new Config
37+
{
38+
DevelopBranchTag = ""
39+
}))
40+
{
41+
fixture.Repository.MakeATaggedCommit("1.0.0");
42+
fixture.Repository.CreateBranch("develop").Checkout();
43+
fixture.AssertFullSemver("1.1.0+0");
44+
}
45+
}
1846

1947
[Test]
2048
public void WhenDevelopBranchedFromMasterDetachedHead_MinorIsIncreased()

GitVersionTask/AssemblyInfoBuilder/UpdateAssemblyInfo.cs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ public class UpdateAssemblyInfo : Task
1212
{
1313
public string AssemblyVersioningScheme { get; set; }
1414

15+
public string DevelopBranchTag { get; set; }
16+
17+
public string ReleaseBranchTag { get; set; }
18+
1519
[Required]
1620
public string SolutionDirectory { get; set; }
1721

@@ -68,6 +72,30 @@ public void InnerExecute()
6872
return;
6973

7074
var config = ConfigurationProvider.Provide(gitDirectory);
75+
if (!string.IsNullOrEmpty(AssemblyVersioningScheme))
76+
{
77+
AssemblyVersioningScheme versioningScheme;
78+
if (Enum.TryParse(AssemblyVersioningScheme, true, out versioningScheme))
79+
{
80+
config.AssemblyVersioningScheme = versioningScheme;
81+
}
82+
else
83+
{
84+
throw new WarningException(string.Format("Unexpected assembly versioning scheme '{0}'.", AssemblyVersioningScheme));
85+
}
86+
}
87+
88+
// TODO This should be covered by tests
89+
// Null is intentional. Empty string means the user has set the value to an empty string and wants to clear the tag
90+
if (DevelopBranchTag != null)
91+
{
92+
config.DevelopBranchTag = DevelopBranchTag;
93+
}
94+
95+
if (ReleaseBranchTag != null)
96+
{
97+
config.ReleaseBranchTag = ReleaseBranchTag;
98+
}
7199

72100
CachedVersion semanticVersion;
73101
if (!VersionAndBranchFinder.TryGetVersion(SolutionDirectory, out semanticVersion, config))
@@ -96,11 +124,10 @@ AssemblyVersioningScheme GetAssemblyVersioningScheme(Config config)
96124

97125
void CreateTempAssemblyInfo(CachedVersion semanticVersion, Config config)
98126
{
99-
var versioningScheme = GetAssemblyVersioningScheme(config);
100127
var assemblyInfoBuilder = new AssemblyInfoBuilder
101128
{
102129
CachedVersion = semanticVersion,
103-
AssemblyVersioningScheme = versioningScheme,
130+
AssemblyVersioningScheme = config.AssemblyVersioningScheme,
104131
};
105132
var assemblyInfo = assemblyInfoBuilder.GetAssemblyInfoText();
106133

GitVersionTask/GetVersion.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ public class GetVersion : Task
7272
[Output]
7373
public string NuGetVersion { get; set; }
7474

75+
public string DevelopBranchTag { get; set; }
76+
77+
public string ReleaseBranchTag { get; set; }
78+
7579
TaskLogger logger;
7680

7781
public GetVersion()
@@ -88,6 +92,19 @@ public override bool Execute()
8892
CachedVersion versionAndBranch;
8993
var gitDirectory = GitDirFinder.TreeWalkForGitDir(SolutionDirectory);
9094
var config = ConfigurationProvider.Provide(gitDirectory);
95+
96+
// TODO This should be covered by tests
97+
// Null is intentional. Empty string means the user has set the value to an empty string and wants to clear the tag
98+
if (DevelopBranchTag != null)
99+
{
100+
config.DevelopBranchTag = DevelopBranchTag;
101+
}
102+
103+
if (ReleaseBranchTag != null)
104+
{
105+
config.ReleaseBranchTag = ReleaseBranchTag;
106+
}
107+
91108
if (VersionAndBranchFinder.TryGetVersion(SolutionDirectory, out versionAndBranch, config))
92109
{
93110
var thisType = typeof(GetVersion);

0 commit comments

Comments
 (0)