Skip to content

Commit 50d6f03

Browse files
committed
Merge pull request #320 from JakeGinnivan/GitVersionInit
Added 'GitVersion init' command which creates a sample GitVersionConfig....
2 parents 2c902c3 + dc8e2a1 commit 50d6f03

31 files changed

+276
-71
lines changed

GitVersionConfig.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
assembly-versioning-scheme: MajorMinor
2+
next-version: 2.0.0
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
using System.IO;
2+
using System.Linq;
3+
using System.Reflection;
4+
using GitVersion;
5+
using GitVersion.Helpers;
6+
using GitVersionCore.Tests;
7+
using NUnit.Framework;
8+
using Shouldly;
9+
using YamlDotNet.Serialization;
10+
11+
[TestFixture]
12+
public class ConfigProviderTests
13+
{
14+
string gitDirectory;
15+
IFileSystem fileSystem;
16+
17+
[SetUp]
18+
public void Setup()
19+
{
20+
fileSystem = new TestFileSystem();
21+
gitDirectory = "c:\\MyGitRepo\\.git";
22+
}
23+
24+
[Test]
25+
public void CanReadDocument()
26+
{
27+
const string text = @"
28+
assembly-versioning-scheme: MajorMinor
29+
develop-branch-tag: alpha
30+
release-branch-tag: rc
31+
next-version: 2.0.0
32+
tag-prefix: '[vV|version-]'
33+
";
34+
SetupConfigFileContent(text);
35+
36+
var config = ConfigurationProvider.Provide(gitDirectory, fileSystem);
37+
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinor);
38+
config.DevelopBranchTag.ShouldBe("alpha");
39+
config.ReleaseBranchTag.ShouldBe("rc");
40+
config.NextVersion.ShouldBe("2.0.0");
41+
config.TagPrefix.ShouldBe("[vV|version-]");
42+
}
43+
44+
[Test]
45+
public void CanReadOldDocument()
46+
{
47+
const string text = @"assemblyVersioningScheme: MajorMinor";
48+
SetupConfigFileContent(text);
49+
var config = ConfigurationProvider.Provide(gitDirectory, fileSystem);
50+
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinor);
51+
}
52+
53+
[Test]
54+
public void CanReadDefaultDocument()
55+
{
56+
const string text = "";
57+
SetupConfigFileContent(text);
58+
var config = ConfigurationProvider.Provide(gitDirectory, fileSystem);
59+
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinorPatch);
60+
config.DevelopBranchTag.ShouldBe("unstable");
61+
config.ReleaseBranchTag.ShouldBe("beta");
62+
config.TagPrefix.ShouldBe("[vV]");
63+
config.NextVersion.ShouldBe(null);
64+
}
65+
66+
[Test]
67+
public void VerifyInit()
68+
{
69+
var config = typeof(Config);
70+
var aliases = config.GetProperties().Select(p => ((YamlAliasAttribute) p.GetCustomAttribute(typeof(YamlAliasAttribute))).Alias);
71+
var writer = new StringWriter();
72+
73+
ConfigReader.WriteSample(writer);
74+
var initFile = writer.GetStringBuilder().ToString();
75+
76+
foreach (var alias in aliases)
77+
{
78+
initFile.ShouldContain(alias);
79+
}
80+
}
81+
82+
[Test]
83+
public void VerifyAliases()
84+
{
85+
var config = typeof(Config);
86+
var propertiesMissingAlias = config.GetProperties().Where(p => p.GetCustomAttribute(typeof(YamlAliasAttribute)) == null).Select(p => p.Name);
87+
88+
propertiesMissingAlias.ShouldBeEmpty();
89+
}
90+
91+
void SetupConfigFileContent(string text)
92+
{
93+
fileSystem.WriteAllText(Path.Combine(Directory.GetParent(gitDirectory).FullName, "GitVersionConfig.yaml"), text);
94+
}
95+
}

GitVersionCore.Tests/ConfigReaderTests.cs

Lines changed: 0 additions & 36 deletions
This file was deleted.

GitVersionCore.Tests/GitVersionCore.Tests.csproj

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,17 @@
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">
6670
<Link>Helpers\DirectoryHelper.cs</Link>
6771
</Compile>
6872
<Compile Include="Fixtures\CommitCountingRepoFixture.cs" />
69-
<Compile Include="ConfigReaderTests.cs" />
73+
<Compile Include="ConfigProviderTests.cs" />
7074
<Compile Include="GitDirFinderTests.cs" />
7175
<Compile Include="Fixtures\BaseGitFlowRepositoryFixture.cs" />
7276
<Compile Include="IntegrationTests\GitFlow\DevelopScenarios.cs" />
@@ -85,12 +89,13 @@
8589
<Compile Include="JsonVersionBuilderTests.cs" />
8690
<Compile Include="ModuleInitializer.cs" />
8791
<Compile Include="Fixtures\EmptyRepositoryFixture.cs" />
88-
<Compile Include="Helpers\GitHelper.cs" />
92+
<Compile Include="Helpers\GitTestExtensions.cs" />
8993
<Compile Include="Helpers\PathHelper.cs" />
9094
<Compile Include="IntegrationTests\GitHubFlow\MasterTests.cs" />
9195
<Compile Include="ApprovalTestsConfig.cs" />
9296
<Compile Include="Fixtures\RepositoryFixtureBase.cs" />
9397
<Compile Include="SemanticVersionTests.cs" />
98+
<Compile Include="TestFileSystem.cs" />
9499
<Compile Include="VariableProviderTests.cs" />
95100
</ItemGroup>
96101
<ItemGroup>

GitVersionCore.Tests/Helpers/GitHelper.cs renamed to GitVersionCore.Tests/Helpers/GitTestExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using GitVersion;
55
using LibGit2Sharp;
66

7-
public static class GitHelper
7+
public static class GitTestExtensions
88
{
99
public static Commit MakeACommit(this IRepository repository)
1010
{

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)]
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
namespace GitVersionCore.Tests
2+
{
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using GitVersion.Helpers;
6+
7+
public class TestFileSystem : IFileSystem
8+
{
9+
Dictionary<string, string> fileSystem = new Dictionary<string, string>();
10+
11+
public void Copy(string @from, string to, bool overwrite)
12+
{
13+
throw new System.NotImplementedException();
14+
}
15+
16+
public void Move(string @from, string to)
17+
{
18+
throw new System.NotImplementedException();
19+
}
20+
21+
public bool Exists(string file)
22+
{
23+
return fileSystem.ContainsKey(file);
24+
}
25+
26+
public void Delete(string path)
27+
{
28+
throw new System.NotImplementedException();
29+
}
30+
31+
public string ReadAllText(string path)
32+
{
33+
return fileSystem[path];
34+
}
35+
36+
public void WriteAllText(string file, string fileContents)
37+
{
38+
if (fileSystem.ContainsKey(file))
39+
fileSystem[file] = fileContents;
40+
else
41+
fileSystem.Add(file, fileContents);
42+
}
43+
44+
public IEnumerable<string> DirectoryGetFiles(string directory, string searchPattern, SearchOption searchOption)
45+
{
46+
throw new System.NotImplementedException();
47+
}
48+
49+
public Stream OpenWrite(string path)
50+
{
51+
throw new System.NotImplementedException();
52+
}
53+
}
54+
}

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")]

0 commit comments

Comments
 (0)