Skip to content

Commit 9d97fbd

Browse files
author
Jake Ginnivan
committed
Starting to fix GitTools#112
1 parent c885610 commit 9d97fbd

15 files changed

+119
-22
lines changed

AcceptanceTests/AcceptanceTests.csproj

+3-4
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@
5959
</ItemGroup>
6060
<ItemGroup>
6161
<Compile Include="ExecArgSpecification.cs" />
62+
<Compile Include="GitFlow\DevelopScenarios.cs" />
6263
<Compile Include="NormaliseGitDirectoryInTeamCity.cs" />
63-
<Compile Include="RepositoryFixture.cs" />
64+
<Compile Include="EmptyRepository.cs" />
6465
<Compile Include="Helpers\ExecutionResults.cs" />
6566
<Compile Include="Helpers\GitHelper.cs" />
6667
<Compile Include="Helpers\GitVersionHelper.cs" />
@@ -95,9 +96,7 @@
9596
<Name>GitVersion</Name>
9697
</ProjectReference>
9798
</ItemGroup>
98-
<ItemGroup>
99-
<Folder Include="GitFlow\" />
100-
</ItemGroup>
99+
<ItemGroup />
101100
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
102101
<PropertyGroup>
103102
<PostBuildEvent>

AcceptanceTests/RepositoryFixture.cs renamed to AcceptanceTests/EmptyRepository.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
namespace GitHubFlowVersion.AcceptanceTests
77
{
8-
public class RepositoryFixture : IDisposable
8+
public class EmptyRepository : IDisposable
99
{
1010
public readonly string RepositoryPath;
1111
public readonly Repository Repository;
1212

13-
public RepositoryFixture()
13+
public EmptyRepository()
1414
{
1515
RepositoryPath = PathHelper.GetTempPath();
1616
Repository.Init(RepositoryPath);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
namespace AcceptanceTests.GitFlow
2+
{
3+
using GitHubFlowVersion.AcceptanceTests;
4+
using GitHubFlowVersion.AcceptanceTests.Helpers;
5+
using GitVersion;
6+
using LibGit2Sharp;
7+
using Shouldly;
8+
using Xunit;
9+
10+
public class DevelopScenarios
11+
{
12+
[Fact]
13+
public void WhenDevelopBranchedFromMaster_MinorIsIncreased()
14+
{
15+
using (var fixture = new EmptyRepository())
16+
{
17+
fixture.Repository.MakeATaggedCommit("1.0.0");
18+
fixture.Repository.CreateBranch("develop").Checkout();
19+
20+
var result = GitVersionHelper.ExecuteIn(fixture.RepositoryPath);
21+
22+
result.Output[VariableProvider.SemVer].ShouldBe("1.1.0.1-unstable");
23+
}
24+
}
25+
}
26+
}

AcceptanceTests/GitHubFlow/MasterTests.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class MasterTests
1010
[Fact]
1111
public void GivenARepositoryWithCommitsButNoTags_VersionShouldBe_0_1()
1212
{
13-
using (var fixture = new RepositoryFixture())
13+
using (var fixture = new EmptyRepository())
1414
{
1515
// Given
1616
fixture.Repository.MakeACommit();
@@ -28,7 +28,7 @@ public void GivenARepositoryWithCommitsButNoTags_VersionShouldBe_0_1()
2828
[Fact]
2929
public void GivenARepositoryWithNoTagsAndANextVersionTxtFile_VersionShouldMatchVersionTxtFile()
3030
{
31-
using (var fixture = new RepositoryFixture())
31+
using (var fixture = new EmptyRepository())
3232
{
3333
const string ExpectedNextVersion = "1.0.0";
3434
fixture.Repository.MakeACommit();
@@ -46,7 +46,7 @@ public void GivenARepositoryWithNoTagsAndANextVersionTxtFile_VersionShouldMatchV
4646
[Fact]
4747
public void GivenARepositoryWithTagAndANextVersionTxtFile_VersionShouldMatchVersionTxtFile()
4848
{
49-
using (var fixture = new RepositoryFixture())
49+
using (var fixture = new EmptyRepository())
5050
{
5151
const string ExpectedNextVersion = "1.1.0";
5252
const string TaggedVersion = "1.0.3";
@@ -64,7 +64,7 @@ public void GivenARepositoryWithTagAndANextVersionTxtFile_VersionShouldMatchVers
6464
[Fact]
6565
public void GivenARepositoryWithTagAndNoNextVersionTxtFile_VersionShouldBeTagWithBumpedPatch()
6666
{
67-
using (var fixture = new RepositoryFixture())
67+
using (var fixture = new EmptyRepository())
6868
{
6969
const string TaggedVersion = "1.0.3";
7070
fixture.Repository.MakeATaggedCommit(TaggedVersion);
@@ -80,7 +80,7 @@ public void GivenARepositoryWithTagAndNoNextVersionTxtFile_VersionShouldBeTagWit
8080
[Fact]
8181
public void GivenARepositoryWithTagAndOldNextVersionTxtFile_VersionShouldBeTagWithBumpedPatch()
8282
{
83-
using (var fixture = new RepositoryFixture())
83+
using (var fixture = new EmptyRepository())
8484
{
8585
const string NextVersionTxt = "1.0.0";
8686
const string TaggedVersion = "1.1.0";

AcceptanceTests/NormaliseGitDirectoryInTeamCity.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class NormaliseGitDirectoryInTeamCity
1717
[InlineData("refs/pull/5/merge")]
1818
public void GivenARemoteWithATagOnMaster_AndAPullRequestWithTwoCommits_AndBuildIsRunningInTeamCity_VersionIsCalclatedProperly(string pullRequestRef)
1919
{
20-
using (var fixture = new RepositoryFixture())
20+
using (var fixture = new EmptyRepository())
2121
{
2222
var remoteRepositoryPath = PathHelper.GetTempPath();
2323
Repository.Init(remoteRepositoryPath);

GitVersion/OutputVariables/VariableProvider.cs

+38-5
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@ public static class VariableProvider
1919
public const string FullSemVerPadded = "FullSemVerPadded";
2020
public const string AssemblySemVer = "AssemblySemVer";
2121
public const string ClassicVersion = "ClassicVersion";
22+
public const string ClassicVersionWithTag = "ClassicVersionWithTag";
2223
public const string PreReleaseTag = "PreReleaseTag";
2324
public const string PreReleaseTagWithDash = "PreReleaseTagWithDash";
2425
public const string InformationalVersion = "InformationalVersion";
2526

2627
public static Dictionary<string, string> GetVariablesFor(SemanticVersion semanticVersion)
2728
{
29+
var formatter = semanticVersion.BuildMetaData.Branch == "develop" ? new CiFeedFormatter() : null;
30+
2831
var variables = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase)
2932
{
3033
{Major, semanticVersion.Major.ToString()},
@@ -35,18 +38,48 @@ public static Dictionary<string, string> GetVariablesFor(SemanticVersion semanti
3538
{BuildMetaData, semanticVersion.BuildMetaData},
3639
{FullBuildMetaData, semanticVersion.BuildMetaData.ToString("f")},
3740
{MajorMinorPatch, string.Format("{0}.{1}.{2}", semanticVersion.Major, semanticVersion.Minor, semanticVersion.Patch)},
38-
{SemVer, semanticVersion.ToString()},
39-
{SemVerPadded, semanticVersion.ToString("sp")},
41+
{SemVer, semanticVersion.ToString(null, formatter)},
42+
{SemVerPadded, semanticVersion.ToString("sp", formatter)},
4043
{AssemblySemVer, semanticVersion.ToString("j") + ".0"},
4144
{FullSemVer, semanticVersion.ToString("f")},
42-
{FullSemVerPadded, semanticVersion.ToString("fp")},
43-
{InformationalVersion, semanticVersion.ToString("i")},
45+
{FullSemVerPadded, semanticVersion.ToString("fp", formatter)},
46+
{InformationalVersion, semanticVersion.ToString("i", formatter)},
4447
{ClassicVersion, string.Format("{0}.{1}", semanticVersion.ToString("j"), (semanticVersion.BuildMetaData.CommitsSinceTag ?? 0))},
48+
{ClassicVersionWithTag, string.Format("{0}.{1}{2}", semanticVersion.ToString("j"),
49+
semanticVersion.BuildMetaData.CommitsSinceTag ?? 0,
50+
semanticVersion.PreReleaseTag.HasTag() ? "-" + semanticVersion.PreReleaseTag : null)},
4551
{BranchName, semanticVersion.BuildMetaData.Branch},
46-
{Sha, semanticVersion.BuildMetaData.Sha},
52+
{Sha, semanticVersion.BuildMetaData.Sha}
4753
};
4854

4955
return variables;
5056
}
5157
}
58+
59+
public class CiFeedFormatter : IFormatProvider, ICustomFormatter
60+
{
61+
public object GetFormat(Type formatType)
62+
{
63+
if (formatType == typeof(SemanticVersion))
64+
return this;
65+
66+
return null;
67+
}
68+
69+
public string Format(string format, object arg, IFormatProvider formatProvider)
70+
{
71+
var semanticVersion = (SemanticVersion) arg;
72+
73+
switch (format)
74+
{
75+
case "s":
76+
case "sp":
77+
return string.Format("{0}.{1}{2}", semanticVersion.ToString("j"),
78+
semanticVersion.BuildMetaData.CommitsSinceTag ?? 0,
79+
semanticVersion.PreReleaseTag.HasTag() ? "-" + semanticVersion.PreReleaseTag.Name: null);
80+
default:
81+
return semanticVersion.ToString(format);
82+
}
83+
}
84+
}
5285
}

GitVersion/SemanticVersion.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ public override string ToString()
183183
/// </summary>
184184
public string ToString(string format, IFormatProvider formatProvider = null)
185185
{
186+
if (string.IsNullOrEmpty(format))
187+
format = "s";
188+
186189
if (formatProvider != null)
187190
{
188191
var formatter = formatProvider.GetFormat(GetType()) as ICustomFormatter;
@@ -191,9 +194,6 @@ public string ToString(string format, IFormatProvider formatProvider = null)
191194
return formatter.Format(format, this, formatProvider);
192195
}
193196

194-
if (string.IsNullOrEmpty(format))
195-
format = "s";
196-
197197
switch (format.ToLower())
198198
{
199199
case "j":

GitVersion/ShortVersionParser.cs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ namespace GitVersion
22
{
33
using System;
44

5+
//TODO Replace with SemVer class
56
public class ShortVersionParser
67
{
78
public static void Parse(string versionString, out int major, out int minor, out int patch)

GitVersionTask/GetVersion.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,17 @@ public class GetVersion : Task
4949
public string FullSemVer { get; set; }
5050

5151
[Output]
52-
public string InformationalVersion { get; set; }
52+
public string FullSemVerPadded { get; set; }
5353

5454
[Output]
55-
public string FullSemVerPadded { get; set; }
55+
public string InformationalVersion { get; set; }
5656

5757
[Output]
5858
public string ClassicVersion { get; set; }
5959

60+
[Output]
61+
public string ClassicVersionWithTag { get; set; }
62+
6063
[Output]
6164
public string BranchName { get; set; }
6265

Tests/AssemblyInfoBuilderTests.VerifyCreatedCode.approved.txt

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ static class GitVersionInformation
3838
public static string FullSemVerPadded = "1.2.3-unstable.0004+5";
3939
public static string InformationalVersion = "1.2.3-unstable.4+5.Branch.feature1.Sha.a682956dc1a2752aa24597a0f5cd939f93614509";
4040
public static string ClassicVersion = "1.2.3.5";
41+
public static string ClassicVersionWithTag = "1.2.3.5-unstable.4";
4142
public static string BranchName = "feature1";
4243
public static string Sha = "a682956dc1a2752aa24597a0f5cd939f93614509";
4344

Tests/JsonVersionBuilderTests.Json.approved.txt

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"FullSemVerPadded":"1.2.3-unstable.0004+5",
1515
"InformationalVersion":"1.2.3-unstable.4+5.Branch.feature1.Sha.a682956dc1a2752aa24597a0f5cd939f93614509",
1616
"ClassicVersion":"1.2.3.5",
17+
"ClassicVersionWithTag":"1.2.3.5-unstable.4",
1718
"BranchName":"feature1",
1819
"Sha":"a682956dc1a2752aa24597a0f5cd939f93614509"
1920
}

Tests/SemanticVersionTests.cs

+1
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,5 @@ public void ValidateInvalidVersionParsing(string versionString)
5151
Assert.IsFalse(SemanticVersion.TryParse(versionString, out version), "TryParse Result");
5252
}
5353

54+
5455
}

Tests/Tests.csproj

+4
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@
8484
<Reference Include="Roslyn.Compilers.CSharp">
8585
<HintPath>..\packages\Roslyn.Compilers.CSharp.1.2.20906.2\lib\net45\Roslyn.Compilers.CSharp.dll</HintPath>
8686
</Reference>
87+
<Reference Include="Shouldly">
88+
<HintPath>..\packages\Shouldly.2.1.1\lib\net40\Shouldly.dll</HintPath>
89+
</Reference>
8790
<Reference Include="System" />
8891
<Reference Include="System.Core" />
8992
<Reference Include="System.Xml.Linq" />
@@ -121,6 +124,7 @@
121124
<Compile Include="SemanticVersionTests.cs" />
122125
<Compile Include="ShortVersionParserTests.cs" />
123126
<Compile Include="UpdateAssemblyInfoTests.cs" />
127+
<Compile Include="VariableProviderTests.cs" />
124128
<Compile Include="VersionOnMasterFinderTests.cs" />
125129
<Compile Include="Mocks\SignatureBuilder.cs" />
126130
<Compile Include="Mocks\MockCommitLog.cs" />

Tests/VariableProviderTests.cs

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
namespace Tests
2+
{
3+
using GitVersion;
4+
using NUnit.Framework;
5+
using Shouldly;
6+
7+
[TestFixture]
8+
public class VariableProviderTests
9+
{
10+
[Test]
11+
public void DevelopBranchFormatsSemVerForCiFeed()
12+
{
13+
var semVer = new SemanticVersion
14+
{
15+
Major = 1,
16+
Minor = 2,
17+
Patch = 3,
18+
PreReleaseTag = "beta.4",
19+
BuildMetaData = "5.Branch.develop"
20+
};
21+
22+
var vars = VariableProvider.GetVariablesFor(semVer);
23+
24+
vars[VariableProvider.SemVer].ShouldBe("1.2.3.5-beta.4");
25+
}
26+
}
27+
}

Tests/packages.config

+1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@
1313
<package id="ObjectApproval" version="0.1.4" targetFramework="net45" />
1414
<package id="Roslyn.Compilers.Common" version="1.2.20906.2" targetFramework="net45" />
1515
<package id="Roslyn.Compilers.CSharp" version="1.2.20906.2" targetFramework="net45" />
16+
<package id="Shouldly" version="2.1.1" targetFramework="net45" />
1617
</packages>

0 commit comments

Comments
 (0)