-
Notifications
You must be signed in to change notification settings - Fork 649
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #320 from JakeGinnivan/GitVersionInit
Added 'GitVersion init' command which creates a sample GitVersionConfig....
- Loading branch information
Showing
31 changed files
with
276 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
assembly-versioning-scheme: MajorMinor | ||
next-version: 2.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using GitVersion; | ||
using GitVersion.Helpers; | ||
using GitVersionCore.Tests; | ||
using NUnit.Framework; | ||
using Shouldly; | ||
using YamlDotNet.Serialization; | ||
|
||
[TestFixture] | ||
public class ConfigProviderTests | ||
{ | ||
string gitDirectory; | ||
IFileSystem fileSystem; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
fileSystem = new TestFileSystem(); | ||
gitDirectory = "c:\\MyGitRepo\\.git"; | ||
} | ||
|
||
[Test] | ||
public void CanReadDocument() | ||
{ | ||
const string text = @" | ||
assembly-versioning-scheme: MajorMinor | ||
develop-branch-tag: alpha | ||
release-branch-tag: rc | ||
next-version: 2.0.0 | ||
tag-prefix: '[vV|version-]' | ||
"; | ||
SetupConfigFileContent(text); | ||
|
||
var config = ConfigurationProvider.Provide(gitDirectory, fileSystem); | ||
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinor); | ||
config.DevelopBranchTag.ShouldBe("alpha"); | ||
config.ReleaseBranchTag.ShouldBe("rc"); | ||
config.NextVersion.ShouldBe("2.0.0"); | ||
config.TagPrefix.ShouldBe("[vV|version-]"); | ||
} | ||
|
||
[Test] | ||
public void CanReadOldDocument() | ||
{ | ||
const string text = @"assemblyVersioningScheme: MajorMinor"; | ||
SetupConfigFileContent(text); | ||
var config = ConfigurationProvider.Provide(gitDirectory, fileSystem); | ||
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinor); | ||
} | ||
|
||
[Test] | ||
public void CanReadDefaultDocument() | ||
{ | ||
const string text = ""; | ||
SetupConfigFileContent(text); | ||
var config = ConfigurationProvider.Provide(gitDirectory, fileSystem); | ||
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinorPatch); | ||
config.DevelopBranchTag.ShouldBe("unstable"); | ||
config.ReleaseBranchTag.ShouldBe("beta"); | ||
config.TagPrefix.ShouldBe("[vV]"); | ||
config.NextVersion.ShouldBe(null); | ||
} | ||
|
||
[Test] | ||
public void VerifyInit() | ||
{ | ||
var config = typeof(Config); | ||
var aliases = config.GetProperties().Select(p => ((YamlAliasAttribute) p.GetCustomAttribute(typeof(YamlAliasAttribute))).Alias); | ||
var writer = new StringWriter(); | ||
|
||
ConfigReader.WriteSample(writer); | ||
var initFile = writer.GetStringBuilder().ToString(); | ||
|
||
foreach (var alias in aliases) | ||
{ | ||
initFile.ShouldContain(alias); | ||
} | ||
} | ||
|
||
[Test] | ||
public void VerifyAliases() | ||
{ | ||
var config = typeof(Config); | ||
var propertiesMissingAlias = config.GetProperties().Where(p => p.GetCustomAttribute(typeof(YamlAliasAttribute)) == null).Select(p => p.Name); | ||
|
||
propertiesMissingAlias.ShouldBeEmpty(); | ||
} | ||
|
||
void SetupConfigFileContent(string text) | ||
{ | ||
fileSystem.WriteAllText(Path.Combine(Directory.GetParent(gitDirectory).FullName, "GitVersionConfig.yaml"), text); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
namespace GitVersionCore.Tests | ||
{ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using GitVersion.Helpers; | ||
|
||
public class TestFileSystem : IFileSystem | ||
{ | ||
Dictionary<string, string> fileSystem = new Dictionary<string, string>(); | ||
|
||
public void Copy(string @from, string to, bool overwrite) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
|
||
public void Move(string @from, string to) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
|
||
public bool Exists(string file) | ||
{ | ||
return fileSystem.ContainsKey(file); | ||
} | ||
|
||
public void Delete(string path) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
|
||
public string ReadAllText(string path) | ||
{ | ||
return fileSystem[path]; | ||
} | ||
|
||
public void WriteAllText(string file, string fileContents) | ||
{ | ||
if (fileSystem.ContainsKey(file)) | ||
fileSystem[file] = fileContents; | ||
else | ||
fileSystem.Add(file, fileContents); | ||
} | ||
|
||
public IEnumerable<string> DirectoryGetFiles(string directory, string searchPattern, SearchOption searchOption) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
|
||
public Stream OpenWrite(string path) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,6 @@ public enum AssemblyVersioningScheme | |
MajorMinorPatchMetadata, | ||
MajorMinorPatch, | ||
MajorMinor, | ||
Major, | ||
Major | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,29 @@ | ||
using System.IO; | ||
using YamlDotNet.Serialization; | ||
using YamlDotNet.Serialization.NamingConventions; | ||
|
||
namespace GitVersion | ||
namespace GitVersion | ||
{ | ||
using System.IO; | ||
using YamlDotNet.Serialization; | ||
using YamlDotNet.Serialization.NamingConventions; | ||
|
||
public class ConfigReader | ||
{ | ||
public static Config Read(TextReader reader) | ||
{ | ||
var deserializer = new Deserializer(null, new CamelCaseNamingConvention()); | ||
var deserializer = new Deserializer(null, new HyphenatedNamingConvention()); | ||
var deserialize = deserializer.Deserialize<Config>(reader); | ||
if (deserialize == null) | ||
{ | ||
return new Config(); | ||
} | ||
return deserialize; | ||
} | ||
|
||
public static void WriteSample(TextWriter writer) | ||
{ | ||
writer.WriteLine("# assembly-versioning-scheme: MajorMinorPatchMetadata | MajorMinorPatch | MajorMinor | Major"); | ||
writer.WriteLine("# develop-branch-tag: alpha"); | ||
writer.WriteLine("# release-branch-tag: rc"); | ||
writer.WriteLine("# tag-prefix: '[vV|version-] # regex to match git tag prefix"); | ||
writer.WriteLine("# next-version: 1.0.0"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,54 @@ | ||
namespace GitVersion | ||
{ | ||
using System.IO; | ||
using System.Text.RegularExpressions; | ||
using GitVersion.Helpers; | ||
|
||
public class ConfigurationProvider | ||
{ | ||
public static Config Provide(string gitDirectory) | ||
static Regex oldAssemblyVersioningScheme = new Regex("assemblyVersioningScheme", RegexOptions.Compiled | RegexOptions.IgnoreCase); | ||
|
||
public static Config Provide(string gitDirectory, IFileSystem fileSystem) | ||
{ | ||
var configFilePath = Path.Combine(Directory.GetParent(gitDirectory).FullName, "GitVersionConfig.yaml"); | ||
if (File.Exists(configFilePath)) | ||
var configFilePath = GetConfigFilePath(gitDirectory); | ||
|
||
if (fileSystem.Exists(configFilePath)) | ||
{ | ||
using (var reader = File.OpenText(configFilePath)) | ||
var readAllText = fileSystem.ReadAllText(configFilePath); | ||
if (oldAssemblyVersioningScheme.IsMatch(readAllText)) | ||
{ | ||
return ConfigReader.Read(reader); | ||
readAllText = oldAssemblyVersioningScheme.Replace(readAllText, "assembly-versioning-scheme"); | ||
fileSystem.WriteAllText(configFilePath, readAllText); | ||
Logger.WriteWarning("Found legacy configuration value 'assemblyVersioningScheme', replaced with 'assembly-versioning-scheme"); | ||
} | ||
|
||
return ConfigReader.Read(new StringReader(readAllText)); | ||
} | ||
|
||
return new Config(); | ||
} | ||
|
||
public static void WriteSample(string gitDirectory, IFileSystem fileSystem) | ||
{ | ||
var configFilePath = GetConfigFilePath(gitDirectory); | ||
|
||
if (!fileSystem.Exists(configFilePath)) | ||
{ | ||
using (var stream = fileSystem.OpenWrite(configFilePath)) | ||
using (var writer = new StreamWriter(stream)) | ||
{ | ||
ConfigReader.WriteSample(writer); | ||
} | ||
} | ||
else | ||
{ | ||
Logger.WriteError("Cannot write sample, GitVersionConfig.yaml already exists"); | ||
} | ||
} | ||
|
||
static string GetConfigFilePath(string gitDirectory) | ||
{ | ||
return Path.Combine(Directory.GetParent(gitDirectory).FullName, "GitVersionConfig.yaml"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,9 +39,5 @@ public VersionPoint Execute(GitVersionContext context, DateTimeOffset olderThan) | |
}; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.