Skip to content

Commit 93460fa

Browse files
committed
Added 'GitVersion init' command which creates a sample GitVersionConfig.yaml file
1 parent 9a93b11 commit 93460fa

16 files changed

+96
-11
lines changed

GitVersionCore.Tests/ConfigReaderTests.cs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
using System.IO;
2+
using System.Linq;
3+
using System.Reflection;
24
using GitVersion;
35
using NUnit.Framework;
46
using Shouldly;
7+
using YamlDotNet.Serialization;
58

69
[TestFixture]
710
public class ConfigReaderTests
@@ -11,15 +14,17 @@ public class ConfigReaderTests
1114
public void CanReadDocument()
1215
{
1316
const string text = @"
14-
assemblyVersioningScheme: MajorMinor
17+
assembly-versioning-scheme: MajorMinor
1518
develop-branch-tag: alpha
1619
release-branch-tag: rc
20+
next-version: 2.0.0
1721
tag-prefix: '[vV|version-]'
1822
";
1923
var config = ConfigReader.Read(new StringReader(text));
2024
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinor);
2125
config.DevelopBranchTag.ShouldBe("alpha");
2226
config.ReleaseBranchTag.ShouldBe("rc");
27+
config.NextVersion.ShouldBe("2.0.0");
2328
config.TagPrefix.ShouldBe("[vV|version-]");
2429
}
2530

@@ -32,5 +37,31 @@ public void CanReadDefaultDocument()
3237
config.DevelopBranchTag.ShouldBe("unstable");
3338
config.ReleaseBranchTag.ShouldBe("beta");
3439
config.TagPrefix.ShouldBe("[vV]");
40+
config.NextVersion.ShouldBe(null);
41+
}
42+
43+
[Test]
44+
public void VerifyInit()
45+
{
46+
var config = typeof(Config);
47+
var aliases = config.GetProperties().Select(p => ((YamlAliasAttribute) p.GetCustomAttribute(typeof(YamlAliasAttribute))).Alias);
48+
var writer = new StringWriter();
49+
50+
ConfigReader.WriteSample(writer);
51+
var initFile = writer.GetStringBuilder().ToString();
52+
53+
foreach (var alias in aliases)
54+
{
55+
initFile.ShouldContain(alias);
56+
}
57+
}
58+
59+
[Test]
60+
public void VerifyAliases()
61+
{
62+
var config = typeof(Config);
63+
var propertiesMissingAlias = config.GetProperties().Where(p => p.GetCustomAttribute(typeof(YamlAliasAttribute)) == null).Select(p => p.Name);
64+
65+
propertiesMissingAlias.ShouldBeEmpty();
3566
}
3667
}

GitVersionCore.Tests/GitVersionCore.Tests.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@
6060
<Reference Include="System.Data.DataSetExtensions" />
6161
<Reference Include="System.Data" />
6262
<Reference Include="System.Xml" />
63+
<Reference Include="YamlDotNet, Version=3.3.0.0, Culture=neutral, processorArchitecture=MSIL">
64+
<SpecificVersion>False</SpecificVersion>
65+
<HintPath>..\packages\YamlDotNet.3.3.1\lib\net35\YamlDotNet.dll</HintPath>
66+
</Reference>
6367
</ItemGroup>
6468
<ItemGroup>
6569
<Compile Include="..\GitVersionTask.Tests\Helpers\DirectoryHelper.cs">

GitVersionCore.Tests/SemanticVersionTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ public class SemanticVersionTests
88

99
[TestCase("1.2.3", 1, 2, 3, null, null, null, null, null, null, null)]
1010
[TestCase("1.2", 1, 2, 0, null, null, null, null, null, null, "1.2.0")]
11-
[TestCase("1", 1, 0, 0, null, null, null, null, null, null, "1.0.0")]
1211
[TestCase("1.2.3-beta", 1, 2, 3, "beta", null, null, null, null, null, null)]
1312
[TestCase("1.2.3-beta3", 1, 2, 3, "beta", 3, null, null, null, null, "1.2.3-beta.3")]
1413
[TestCase("1.2.3-alpha", 1, 2, 3, "alpha", null, null, null, null, null, null)]

GitVersionCore.Tests/packages.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
<package id="LibGit2Sharp" version="0.19.0.0" targetFramework="net45" />
77
<package id="NUnit" version="2.6.3" targetFramework="net45" />
88
<package id="Shouldly" version="2.2.0" targetFramework="net45" />
9+
<package id="YamlDotNet" version="3.3.1" targetFramework="net45" />
910
</packages>

GitVersionCore/AssemblyVersioningScheme.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ public enum AssemblyVersioningScheme
55
MajorMinorPatchMetadata,
66
MajorMinorPatch,
77
MajorMinor,
8-
Major,
8+
Major
99
}
1010
}

GitVersionCore/Configuration/Config.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public Config()
1212
TagPrefix = "[vV]";
1313
}
1414

15+
[YamlAlias("assembly-versioning-scheme")]
1516
public AssemblyVersioningScheme AssemblyVersioningScheme { get; set; }
1617

1718
[YamlAlias("develop-branch-tag")]

GitVersionCore/Configuration/ConfigReader.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,14 @@ public static Config Read(TextReader reader)
1616
}
1717
return deserialize;
1818
}
19+
20+
public static void WriteSample(TextWriter writer)
21+
{
22+
writer.WriteLine("# assembly-versioning-scheme: MajorMinorPatchMetadata | MajorMinorPatch | MajorMinor | Major");
23+
writer.WriteLine("# develop-branch-tag: alpha");
24+
writer.WriteLine("# release-branch-tag: rc");
25+
writer.WriteLine("# tag-prefix: '[vV|version-] # regex to match git tag prefix");
26+
writer.WriteLine("# next-version: 1.0.0");
27+
}
1928
}
2029
}

GitVersionCore/Configuration/ConfigurationProvider.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public class ConfigurationProvider
66
{
77
public static Config Provide(string gitDirectory)
88
{
9-
var configFilePath = Path.Combine(Directory.GetParent(gitDirectory).FullName, "GitVersionConfig.yaml");
9+
var configFilePath = GetConfigFilePath(gitDirectory);
1010
if (File.Exists(configFilePath))
1111
{
1212
using (var reader = File.OpenText(configFilePath))
@@ -17,5 +17,25 @@ public static Config Provide(string gitDirectory)
1717

1818
return new Config();
1919
}
20+
21+
public static void WriteSample(string gitDirectory)
22+
{
23+
var configFilePath = GetConfigFilePath(gitDirectory);
24+
25+
if (!File.Exists(configFilePath))
26+
{
27+
using (var stream = File.OpenWrite(configFilePath))
28+
using (var writer = new StreamWriter(stream))
29+
{
30+
ConfigReader.WriteSample(writer);
31+
}
32+
}
33+
// TODO else write warning?
34+
}
35+
36+
static string GetConfigFilePath(string gitDirectory)
37+
{
38+
return Path.Combine(Directory.GetParent(gitDirectory).FullName, "GitVersionConfig.yaml");
39+
}
2040
}
2141
}

GitVersionCore/GitFlow/BranchFinders/VersionOnMasterFinder.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,5 @@ public VersionPoint Execute(GitVersionContext context, DateTimeOffset olderThan)
3939
};
4040
}
4141

42-
43-
44-
45-
4642
}
4743
}

GitVersionCore/GitVersionCore.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@
5353
<SpecificVersion>False</SpecificVersion>
5454
<HintPath>..\Packages\Visualize.Fody.0.4.0.0\Lib\portable-net4+sl4+wp7+win8+MonoAndroid16+MonoTouch40\Visualize.dll</HintPath>
5555
</Reference>
56-
<Reference Include="YamlDotNet">
57-
<HintPath>..\packages\YamlDotNet.3.3.0\lib\net35\YamlDotNet.dll</HintPath>
56+
<Reference Include="YamlDotNet, Version=3.3.0.0, Culture=neutral, processorArchitecture=MSIL">
57+
<SpecificVersion>False</SpecificVersion>
58+
<HintPath>..\packages\YamlDotNet.3.3.1\lib\net35\YamlDotNet.dll</HintPath>
5859
</Reference>
5960
</ItemGroup>
6061
<ItemGroup>

0 commit comments

Comments
 (0)