diff --git a/.gitignore b/.gitignore index 609c30d779..dc2ab02461 100644 --- a/.gitignore +++ b/.gitignore @@ -80,3 +80,4 @@ Thumbs.db # Folder config file Desktop.ini +_NCrunch_GitVersion diff --git a/AcceptanceTests/AcceptanceTests.csproj b/AcceptanceTests/AcceptanceTests.csproj new file mode 100644 index 0000000000..18593ee199 --- /dev/null +++ b/AcceptanceTests/AcceptanceTests.csproj @@ -0,0 +1,118 @@ + + + + + Debug + AnyCPU + {BF905F84-382C-440D-92F5-C61108626D8D} + Library + Properties + AcceptanceTests + AcceptanceTests + v4.0 + 512 + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\ApprovalTests.3.0.5\lib\net40\ApprovalTests.dll + + + ..\packages\ApprovalUtilities.3.0.5\lib\net35\ApprovalUtilities.dll + + + ..\packages\LibGit2Sharp.0.16.0.0\lib\net35\LibGit2Sharp.dll + + + + + + + + + + False + ..\packages\TestStack.BDDfy.3.19.1\lib\NET40\TestStack.BDDfy.dll + + + ..\packages\xunit.1.9.2\lib\net20\xunit.dll + + + ..\packages\xunit.extensions.1.9.2\lib\net20\xunit.extensions.dll + + + + + + + + + + + + + + + + + + True + True + Resources.resx + + + + + + + + + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + + {c3578a7b-09a6-4444-9383-0deafa4958bd} + GitVersion + + + + + +if not exist "$(TargetDir)NativeBinaries" md "$(TargetDir)NativeBinaries" +if not exist "$(TargetDir)NativeBinaries\x86" md "$(TargetDir)NativeBinaries\x86" +xcopy /s /y /d "$(SolutionDir)packages\LibGit2Sharp.0.16.0.0\lib\net35\NativeBinaries\x86\*.*" "$(TargetDir)NativeBinaries\x86" +if not exist "$(TargetDir)NativeBinaries\amd64" md "$(TargetDir)NativeBinaries\amd64" +xcopy /s /y /d "$(SolutionDir)packages\LibGit2Sharp.0.16.0.0\lib\net35\NativeBinaries\amd64\*.*" "$(TargetDir)NativeBinaries\amd64" + + + \ No newline at end of file diff --git a/AcceptanceTests/AcceptanceTests.v2.ncrunchproject b/AcceptanceTests/AcceptanceTests.v2.ncrunchproject new file mode 100644 index 0000000000..a434904f9c --- /dev/null +++ b/AcceptanceTests/AcceptanceTests.v2.ncrunchproject @@ -0,0 +1,28 @@ + + true + false + false + true + false + false + false + true + true + true + true + false + true + true + true + 60000 + + + + AutoDetect + STA + x86 + + + + ..\Packages\LibGit2Sharp.0.16.0.0\lib\net35\NativeBinaries\**.* + \ No newline at end of file diff --git a/AcceptanceTests/EmptyRepositorySpecification.cs b/AcceptanceTests/EmptyRepositorySpecification.cs new file mode 100644 index 0000000000..8e409360ed --- /dev/null +++ b/AcceptanceTests/EmptyRepositorySpecification.cs @@ -0,0 +1,44 @@ +using GitHubFlowVersion.AcceptanceTests.Helpers; +using Xunit; + +namespace GitHubFlowVersion.AcceptanceTests +{ + using System; + using TestStack.BDDfy; + + public class EmptyRepositorySpecification : IUseFixture + { + private ExecutionResults _result; + RepositoryFixture _data; + + public void GivenAnEmptyRepository() {} + + public void WhenGitHubFlowVersionIsExecuted() + { + _result = GitVersionHelper.ExecuteIn(_data.RepositoryPath); + } + + public void ThenANonZeroExitCodeShouldOccur() + { + Assert.NotEqual(0, _result.ExitCode); + } + + public void AndAnErrorAboutNotFindingMasterShouldBeShown() + { + Assert.Contains("No Tip found. Has repo been initialized?", _result.Output); + } + + [Fact] + public void RunSpecification() + { + // If we are actually running in teamcity, lets delete this environmental variable + Environment.SetEnvironmentVariable("TEAMCITY_VERSION", null); + this.BDDfy(); + } + + public void SetFixture(RepositoryFixture data) + { + _data = data; + } + } +} diff --git a/AcceptanceTests/ExecArgSpecification.cs b/AcceptanceTests/ExecArgSpecification.cs new file mode 100644 index 0000000000..a81f3e86a0 --- /dev/null +++ b/AcceptanceTests/ExecArgSpecification.cs @@ -0,0 +1,43 @@ +//using System.IO; +//using GitHubFlowVersion.AcceptanceTests.Helpers; +//using Xunit; + +//namespace GitHubFlowVersion.AcceptanceTests +//{ +// using global::AcceptanceTests.Properties; + +// public class ExecArgSpecification : RepositorySpecification +// { +// private ExecutionResults _result; +// private const string MsBuild = @"c:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe"; +// private const string TaggedVersion = "1.2.3"; + +// public void GivenARepositoryWithATaggedCommit() +// { +// Repository.MakeATaggedCommit(TaggedVersion); +// Repository.MakeACommit(); +// } + +// public void AndGivenThereIsANextVersionTxtFile() +// { +// Repository.AddNextVersionTxtFile(TaggedVersion); +// } + +// public void WhenGitHubFlowVersionIsExecutedWithExecOption() +// { +// var buildFile = Path.Combine(RepositoryPath, "TestBuildFile.proj"); +// File.WriteAllBytes(buildFile, Resources.TestBuildFile); +// _result = GitVersionHelper.ExecuteIn(RepositoryPath, exec: MsBuild, execArgs: "TestBuildFile.proj /target:OutputResults"); +// } + +// public void ThenProcessExitedWithoutError() +// { +// _result.AssertExitedSuccessfully(); +// } + +// public void AndThenVariablesShouldBeAvailableToProcess() +// { +// Assert.Contains("GitHubFlowVersion_FullSemVer: 1.2.4+001", _result.Output); +// } +// } +//} \ No newline at end of file diff --git a/AcceptanceTests/Helpers/ExecutionResults.cs b/AcceptanceTests/Helpers/ExecutionResults.cs new file mode 100644 index 0000000000..b2944adca4 --- /dev/null +++ b/AcceptanceTests/Helpers/ExecutionResults.cs @@ -0,0 +1,21 @@ +using Xunit; + +namespace GitHubFlowVersion.AcceptanceTests.Helpers +{ + public class ExecutionResults + { + public ExecutionResults(int exitCode, string output) + { + ExitCode = exitCode; + Output = output; + } + + public int ExitCode { get; private set; } + public string Output { get; private set; } + + public void AssertExitedSuccessfully() + { + Assert.Equal(0, ExitCode); + } + } +} \ No newline at end of file diff --git a/AcceptanceTests/Helpers/GitHelper.cs b/AcceptanceTests/Helpers/GitHelper.cs new file mode 100644 index 0000000000..7b2567fab0 --- /dev/null +++ b/AcceptanceTests/Helpers/GitHelper.cs @@ -0,0 +1,34 @@ +using System; +using System.IO; +using System.Linq; +using LibGit2Sharp; + +namespace GitHubFlowVersion.AcceptanceTests.Helpers +{ + public static class GitHelper + { + public static Commit MakeACommit(this IRepository repository) + { + var randomFile = Path.Combine(repository.Info.WorkingDirectory, Guid.NewGuid().ToString()); + File.WriteAllText(randomFile, string.Empty); + repository.Index.Stage(randomFile); + return repository.Commit("Test Commit", new Signature("Test User", "test@email.com", DateTimeOffset.UtcNow)); + } + + public static Commit[] MakeCommits(this IRepository repository, int numCommitsToMake) + { + return Enumerable.Range(1, numCommitsToMake) + .Select(x => repository.MakeACommit()) + .ToArray(); + } + + public static Tag MakeATaggedCommit(this IRepository repository, string tag) + { + var commit = repository.MakeACommit(); + var existingTag = repository.Tags.SingleOrDefault(t=>t.Name == tag); + if (existingTag != null) + return existingTag; + return repository.Tags.Add(tag, commit); + } + } +} diff --git a/AcceptanceTests/Helpers/GitVersionHelper.cs b/AcceptanceTests/Helpers/GitVersionHelper.cs new file mode 100644 index 0000000000..4b637b21c2 --- /dev/null +++ b/AcceptanceTests/Helpers/GitVersionHelper.cs @@ -0,0 +1,44 @@ +using System; +using System.IO; +using System.Text; +using LibGit2Sharp; + +namespace GitHubFlowVersion.AcceptanceTests.Helpers +{ + public static class GitVersionHelper + { + public static ExecutionResults ExecuteIn(string workingDirectory, string toFile = null, + string exec = null, string execArgs = null, string projectFile = null, string targets = null) + { + var gitHubFlowVersion = Path.Combine(PathHelper.GetCurrentDirectory(), "GitVersion.exe"); + var toFileArg = toFile == null ? null : string.Format(" /ToFile \"{0}\"", toFile); + var execArg = exec == null ? null : string.Format(" /Exec \"{0}\"", exec); + var execArgsArg = execArgs == null ? null : string.Format(" /ExecArgs \"{0}\"", execArgs); + var projectFileArg = projectFile == null ? null : string.Format(" /ProjectFile \"{0}\"", projectFile); + var targetsArg = targets == null ? null : string.Format(" /Targets \"{0}\"", targets); + var arguments = string.Format("\"{0}\"{1}{2}{3}{4}{5}", workingDirectory, toFileArg, execArg, execArgsArg, + projectFileArg, targetsArg); + + var output = new StringBuilder(); + + Console.WriteLine("Executing: {0} {1}", gitHubFlowVersion, arguments); + Console.WriteLine(); + var exitCode = ProcessHelper.Run(s => output.AppendLine(s), s => output.AppendLine(s), null, gitHubFlowVersion, arguments, workingDirectory); + + Console.WriteLine("Output from GitHubFlowVersion.exe"); + Console.WriteLine("-------------------------------------------------------"); + Console.WriteLine(output.ToString()); + Console.WriteLine(); + Console.WriteLine(); + Console.WriteLine("-------------------------------------------------------"); + + return new ExecutionResults(exitCode, output.ToString()); + } + + public static void AddNextVersionTxtFile(this IRepository repository, string version) + { + var nextVersionFile = Path.Combine(repository.Info.WorkingDirectory, "NextVersion.txt"); + File.WriteAllText(nextVersionFile, version); + } + } +} diff --git a/AcceptanceTests/Helpers/PathHelper.cs b/AcceptanceTests/Helpers/PathHelper.cs new file mode 100644 index 0000000000..9af6ac1c97 --- /dev/null +++ b/AcceptanceTests/Helpers/PathHelper.cs @@ -0,0 +1,19 @@ +using System; +using System.IO; +using System.Reflection; + +namespace GitHubFlowVersion.AcceptanceTests.Helpers +{ + public static class PathHelper + { + public static string GetCurrentDirectory() + { + return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + } + + public static string GetTempPath() + { + return Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); + } + } +} \ No newline at end of file diff --git a/AcceptanceTests/Helpers/ProcessHelper.cs b/AcceptanceTests/Helpers/ProcessHelper.cs new file mode 100644 index 0000000000..378ab88d36 --- /dev/null +++ b/AcceptanceTests/Helpers/ProcessHelper.cs @@ -0,0 +1,116 @@ +namespace GitHubFlowVersion.AcceptanceTests.Helpers +{ + using System; + using System.Diagnostics; + using System.IO; + using System.Runtime.InteropServices; + using System.Threading; + + public static class ProcessHelper + { + private static volatile object _lockObject = new object(); + + // http://social.msdn.microsoft.com/Forums/en/netfxbcl/thread/f6069441-4ab1-4299-ad6a-b8bb9ed36be3 + public static Process Start(ProcessStartInfo startInfo) + { + Process process; + + lock (_lockObject) + { + using (new ChangeErrorMode(ErrorModes.FailCriticalErrors | ErrorModes.NoGpFaultErrorBox)) + { + process = Process.Start(startInfo); + process.PriorityClass = ProcessPriorityClass.Idle; + } + } + + return process; + } + + // http://csharptest.net/532/using-processstart-to-capture-console-output/ + public static int Run(Action output, Action errorOutput, TextReader input, string exe, string args, string workingDirectory) + { + if (String.IsNullOrEmpty(exe)) + throw new FileNotFoundException(); + if (output == null) + throw new ArgumentNullException("output"); + + var psi = new ProcessStartInfo + { + UseShellExecute = false, + RedirectStandardError = true, + RedirectStandardOutput = true, + RedirectStandardInput = true, + WindowStyle = ProcessWindowStyle.Hidden, + CreateNoWindow = true, + ErrorDialog = false, + WorkingDirectory = workingDirectory ?? Environment.CurrentDirectory, + FileName = exe, + Arguments = args + }; + + using (var process = Process.Start(psi)) + using (var mreOut = new ManualResetEvent(false)) + using (var mreErr = new ManualResetEvent(false)) + { + process.EnableRaisingEvents = true; + process.OutputDataReceived += (o, e) => + { + // ReSharper disable once AccessToDisposedClosure + if (e.Data == null) + mreOut.Set(); + else + output(e.Data); + }; + process.BeginOutputReadLine(); + process.ErrorDataReceived += (o, e) => + { + // ReSharper disable once AccessToDisposedClosure + if (e.Data == null) + mreErr.Set(); + else + errorOutput(e.Data); + }; + process.BeginErrorReadLine(); + + string line; + while (input != null && null != (line = input.ReadLine())) + process.StandardInput.WriteLine(line); + + process.StandardInput.Close(); + process.WaitForExit(); + + mreOut.WaitOne(); + mreErr.WaitOne(); + + return process.ExitCode; + } + } + + [Flags] + public enum ErrorModes + { + Default = 0x0, + FailCriticalErrors = 0x1, + NoGpFaultErrorBox = 0x2, + NoAlignmentFaultExcept = 0x4, + NoOpenFileErrorBox = 0x8000 + } + + public struct ChangeErrorMode : IDisposable + { + private readonly int _oldMode; + + public ChangeErrorMode(ErrorModes mode) + { + _oldMode = SetErrorMode((int)mode); + } + + void IDisposable.Dispose() { SetErrorMode(_oldMode); } + + [DllImport("kernel32.dll")] + private static extern int SetErrorMode(int newMode); + } + } + +} \ No newline at end of file diff --git a/AcceptanceTests/Helpers/Scrubbers.cs b/AcceptanceTests/Helpers/Scrubbers.cs new file mode 100644 index 0000000000..b269c444fd --- /dev/null +++ b/AcceptanceTests/Helpers/Scrubbers.cs @@ -0,0 +1,9 @@ +using System.Text.RegularExpressions; + +public static class Scrubbers +{ + public static string GuidScrubber(string value) + { + return Regex.Replace(value, @"\b[a-f0-9]{40}\b", "000000000000000000000000000000000000000"); + } +} \ No newline at end of file diff --git a/AcceptanceTests/NoTagsInRepositorySpecification.RunSpecification.approved.txt b/AcceptanceTests/NoTagsInRepositorySpecification.RunSpecification.approved.txt new file mode 100644 index 0000000000..0a8927a666 --- /dev/null +++ b/AcceptanceTests/NoTagsInRepositorySpecification.RunSpecification.approved.txt @@ -0,0 +1,17 @@ +{ + "Major":0, + "Minor":1, + "Patch":0, + "Suffix":"", + "LongVersion":"0.1.0 Sha:'000000000000000000000000000000000000000'", + "NugetVersion":"0.1.0", + "ShortVersion":"0.1.0", + "BranchName":"master", + "BranchType":"Master", + "Sha":"000000000000000000000000000000000000000", + "MajorMinorPatch":"0.1.0", + "SemVer":"0.1.0+2", + "Version":"0.1.0+2", + "PreReleasePartTwo":2, + "Stability":"Final" +} diff --git a/AcceptanceTests/NoTagsInRepositorySpecification.RunSpecification.approved.txt.orig b/AcceptanceTests/NoTagsInRepositorySpecification.RunSpecification.approved.txt.orig new file mode 100644 index 0000000000..0706fc4ec5 --- /dev/null +++ b/AcceptanceTests/NoTagsInRepositorySpecification.RunSpecification.approved.txt.orig @@ -0,0 +1,17 @@ +{ + "Major":0, + "Minor":1, + "Patch":0, + "Suffix":"", + "LongVersion":"0.1.0 Sha:'000000000000000000000000000000000000000'", + "NugetVersion":"0.1.0", + "ShortVersion":"0.1.0", + "BranchName":"master", + "BranchType":"Master", + "Sha":"000000000000000000000000000000000000000", + "MajorMinorPatch":"0.1.0", + "SemVer":"0.1.0", + "Version":"0.1.0", + "PreReleasePartTwo":2, + "Stability":"Final" +} diff --git a/AcceptanceTests/NoTagsInRepositorySpecification.cs b/AcceptanceTests/NoTagsInRepositorySpecification.cs new file mode 100644 index 0000000000..5fabb9ee8d --- /dev/null +++ b/AcceptanceTests/NoTagsInRepositorySpecification.cs @@ -0,0 +1,50 @@ +using GitHubFlowVersion.AcceptanceTests.Helpers; +using Xunit; + +namespace GitHubFlowVersion.AcceptanceTests +{ + using System; + using ApprovalTests; + using TestStack.BDDfy; + + public class NoTagsInRepositorySpecification : IUseFixture + { + private ExecutionResults _result; + RepositoryFixture _data; + + public void GivenARepositoryWithCommitsButNoTags() + { + _data.Repository.MakeACommit(); + _data.Repository.MakeACommit(); + _data.Repository.MakeACommit(); + } + + public void WhenGitHubFlowVersionIsExecuted() + { + _result = GitVersionHelper.ExecuteIn(_data.RepositoryPath); + } + + public void ThenAZeroExitCodeShouldOccur() + { + Assert.Equal(0, _result.ExitCode); + } + + public void AndTheCorrectVersionShouldBeOutput() + { + Approvals.Verify(_result.Output, Scrubbers.GuidScrubber); + } + + [Fact] + public virtual void RunSpecification() + { + // If we are actually running in teamcity, lets delete this environmental variable + Environment.SetEnvironmentVariable("TEAMCITY_VERSION", null); + this.BDDfy(); + } + + public void SetFixture(RepositoryFixture data) + { + _data = data; + } + } +} diff --git a/AcceptanceTests/NoTagsInRepositoryWithNextVersionTxtSpecification.RunSpecification.approved.txt b/AcceptanceTests/NoTagsInRepositoryWithNextVersionTxtSpecification.RunSpecification.approved.txt new file mode 100644 index 0000000000..150ea8c7a0 --- /dev/null +++ b/AcceptanceTests/NoTagsInRepositoryWithNextVersionTxtSpecification.RunSpecification.approved.txt @@ -0,0 +1,17 @@ +{ + "Major":0, + "Minor":2, + "Patch":0, + "Suffix":"", + "LongVersion":"0.2.0 Sha:'000000000000000000000000000000000000000'", + "NugetVersion":"0.2.0", + "ShortVersion":"0.2.0", + "BranchName":"master", + "BranchType":"Master", + "Sha":"000000000000000000000000000000000000000", + "MajorMinorPatch":"0.2.0", + "SemVer":"0.2.0+2", + "Version":"0.2.0+2", + "PreReleasePartTwo":2, + "Stability":"Final" +} diff --git a/AcceptanceTests/NoTagsInRepositoryWithNextVersionTxtSpecification.RunSpecification.approved.txt.orig b/AcceptanceTests/NoTagsInRepositoryWithNextVersionTxtSpecification.RunSpecification.approved.txt.orig new file mode 100644 index 0000000000..cab87ab2db --- /dev/null +++ b/AcceptanceTests/NoTagsInRepositoryWithNextVersionTxtSpecification.RunSpecification.approved.txt.orig @@ -0,0 +1,17 @@ +{ + "Major":0, + "Minor":2, + "Patch":0, + "Suffix":"", + "LongVersion":"0.2.0 Sha:'000000000000000000000000000000000000000'", + "NugetVersion":"0.2.0", + "ShortVersion":"0.2.0", + "BranchName":"master", + "BranchType":"Master", + "Sha":"000000000000000000000000000000000000000", + "MajorMinorPatch":"0.2.0", + "SemVer":"0.2.0", + "Version":"0.2.0", + "PreReleasePartTwo":2, + "Stability":"Final" +} diff --git a/AcceptanceTests/NoTagsInRepositoryWithNextVersionTxtSpecification.cs b/AcceptanceTests/NoTagsInRepositoryWithNextVersionTxtSpecification.cs new file mode 100644 index 0000000000..7932469a55 --- /dev/null +++ b/AcceptanceTests/NoTagsInRepositoryWithNextVersionTxtSpecification.cs @@ -0,0 +1,56 @@ +using GitHubFlowVersion.AcceptanceTests.Helpers; +using Xunit; + +namespace GitHubFlowVersion.AcceptanceTests +{ + using System; + using ApprovalTests; + using TestStack.BDDfy; + + public class NoTagsInRepositoryWithNextVersionTxtSpecification : IUseFixture + { + private const string ExpectedNextVersion = "0.2.0"; + private ExecutionResults _result; + RepositoryFixture _data; + + public void GivenARepositoryWithCommitsButNoTags() + { + _data.Repository.MakeACommit(); + _data.Repository.MakeACommit(); + _data.Repository.MakeACommit(); + } + + public void AndGivenANextVersionTxtFile() + { + _data.Repository.AddNextVersionTxtFile(ExpectedNextVersion); + } + + public void WhenGitHubFlowVersionIsExecuted() + { + _result = GitVersionHelper.ExecuteIn(_data.RepositoryPath); + } + + public void ThenAZeroExitCodeShouldOccur() + { + Assert.Equal(0, _result.ExitCode); + } + + public void AndTheCorrectVersionShouldBeOutput() + { + Approvals.Verify(_result.Output, Scrubbers.GuidScrubber); + } + + [Fact] + public virtual void RunSpecification() + { + // If we are actually running in teamcity, lets delete this environmental variable + Environment.SetEnvironmentVariable("TEAMCITY_VERSION", null); + this.BDDfy(); + } + + public void SetFixture(RepositoryFixture data) + { + _data = data; + } + } +} \ No newline at end of file diff --git a/AcceptanceTests/ProjArgSpecification.cs b/AcceptanceTests/ProjArgSpecification.cs new file mode 100644 index 0000000000..bbfe59bf69 --- /dev/null +++ b/AcceptanceTests/ProjArgSpecification.cs @@ -0,0 +1,41 @@ +//using System.IO; +//using GitHubFlowVersion.AcceptanceTests.Helpers; +//using Xunit; + +//namespace GitHubFlowVersion.AcceptanceTests +//{ +// using global::AcceptanceTests.Properties; + +// public class ProjArgSpecification : RepositorySpecification +// { +// private ExecutionResults _result; +// private const string TaggedVersion = "1.2.3"; + +// public void GivenARepositoryWithATaggedCommit() +// { +// Repository.MakeATaggedCommit(TaggedVersion); +// } + +// public void AndGivenThereIsANextVersionTxtFile() +// { +// Repository.AddNextVersionTxtFile(TaggedVersion); +// } + +// public void WhenGitHubFlowVersionIsExecutedWithExecOption() +// { +// var buildFile = Path.Combine(RepositoryPath, "TestBuildFile.proj"); +// File.WriteAllBytes(buildFile, Resources.TestBuildFile); +// _result = GitVersionHelper.ExecuteIn(RepositoryPath, projectFile: "TestBuildFile.proj", targets: "OutputResults"); +// } + +// public void ThenProcessExitedWithoutError() +// { +// _result.AssertExitedSuccessfully(); +// } + +// public void AndThenVariablesShouldBeAvailableToProcess() +// { +// Assert.Contains("GitHubFlowVersion_FullSemVer: 1.2.4", _result.Output); +// } +// } +//} \ No newline at end of file diff --git a/AcceptanceTests/Properties/ApprovalTestsConfig.cs b/AcceptanceTests/Properties/ApprovalTestsConfig.cs new file mode 100644 index 0000000000..c2c72025a1 --- /dev/null +++ b/AcceptanceTests/Properties/ApprovalTestsConfig.cs @@ -0,0 +1,3 @@ +using ApprovalTests.Reporters; + +[assembly: UseReporter(typeof(DiffReporter), typeof(AllFailingTestsClipboardReporter))] \ No newline at end of file diff --git a/AcceptanceTests/Properties/AssemblyInfo.cs b/AcceptanceTests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..4e335b2199 --- /dev/null +++ b/AcceptanceTests/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("AcceptanceTests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("AcceptanceTests")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("2efaf5ee-00a9-494f-8668-81b30883b082")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/AcceptanceTests/Properties/Resources.Designer.cs b/AcceptanceTests/Properties/Resources.Designer.cs new file mode 100644 index 0000000000..34b2969e41 --- /dev/null +++ b/AcceptanceTests/Properties/Resources.Designer.cs @@ -0,0 +1,73 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.34011 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace AcceptanceTests.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AcceptanceTests.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized resource of type System.Byte[]. + /// + internal static byte[] TestBuildFile { + get { + object obj = ResourceManager.GetObject("TestBuildFile", resourceCulture); + return ((byte[])(obj)); + } + } + } +} diff --git a/AcceptanceTests/Properties/Resources.resx b/AcceptanceTests/Properties/Resources.resx new file mode 100644 index 0000000000..483c3ac9c4 --- /dev/null +++ b/AcceptanceTests/Properties/Resources.resx @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + ..\testbuildfile.proj;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/AcceptanceTests/PullRequestsFixture.cs b/AcceptanceTests/PullRequestsFixture.cs new file mode 100644 index 0000000000..d13eab24ed --- /dev/null +++ b/AcceptanceTests/PullRequestsFixture.cs @@ -0,0 +1,90 @@ +using System; +using GitHubFlowVersion.AcceptanceTests.Helpers; +using LibGit2Sharp; +using Xunit; + +namespace GitHubFlowVersion.AcceptanceTests +{ + public abstract class PullRequestsSpecification : RepositoryFixture + { + private ExecutionResults _result; + private const string TaggedVersion = "1.0.3"; + protected abstract string PullRequestBranchName(); + + public void GivenARemoteWithATagOnMaster() + { + RemoteRepositoryPath = PathHelper.GetTempPath(); + Repository.Init(RemoteRepositoryPath); + RemoteRepository = new Repository(RemoteRepositoryPath); + RemoteRepository.Config.Set("user.name", "Test"); + RemoteRepository.Config.Set("user.email", "test@email.com"); + RemoteReference = Repository.Network.Remotes.Add("origin", RemoteRepositoryPath); + Console.WriteLine("Created git repository at {0}", RemoteRepositoryPath); + RemoteRepository.MakeATaggedCommit(TaggedVersion); + } + + protected Remote RemoteReference { get; private set; } + protected Repository RemoteRepository { get; private set; } + protected string RemoteRepositoryPath { get; private set; } + protected string MergeCommitSha { get; private set; } + + public void AndGivenRunningInTeamCity() + { + Environment.SetEnvironmentVariable("TEAMCITY_VERSION", "8.0.4"); + } + + public void AndGivenARemoteFeatureBranchWithTwoCommits() + { + var branch = RemoteRepository.CreateBranch("FeatureBranch"); + RemoteRepository.Checkout(branch); + RemoteRepository.MakeCommits(2); + } + + public void AndGivenRemoteHasPullRefWithMergeCommit() + { + var pullRequestBranchName = PullRequestBranchName(); + RemoteRepository.Checkout(RemoteRepository.Head.Tip.Sha); + //Emulate merge commit + MergeCommitSha = RemoteRepository.MakeACommit().Sha; + RemoteRepository.Checkout("master"); // HEAD cannot be pointing at the merge commit + RemoteRepository.Refs.Add(pullRequestBranchName, new ObjectId(MergeCommitSha)); + } + + public void AndGivenTeamCityHasCheckedOutThePullMergeCommit() + { + Repository.Fetch("origin"); + Repository.Checkout(MergeCommitSha); + } + + public void WhenGitHubFlowVersionIsExecuted() + { + _result = GitVersionHelper.ExecuteIn(RepositoryPath); + } + + public void ThenItShouldExitWithoutError() + { + _result.AssertExitedSuccessfully(); + } + + public void AndTheCorrectVersionShouldBeOutput() + { + Assert.Contains("1.0.4-PullRequest5", _result.Output); + } + + public class StashPullRequests : PullRequestsSpecification + { + protected override string PullRequestBranchName() + { + return "refs/pull-requests/5/merge-clean"; + } + } + + public class GitHubPullRequests : PullRequestsSpecification + { + protected override string PullRequestBranchName() + { + return "refs/pull/5/merge"; + } + } + } +} \ No newline at end of file diff --git a/AcceptanceTests/RepositoryFixture.cs b/AcceptanceTests/RepositoryFixture.cs new file mode 100644 index 0000000000..1007758fb5 --- /dev/null +++ b/AcceptanceTests/RepositoryFixture.cs @@ -0,0 +1,37 @@ +using System; +using System.IO; +using GitHubFlowVersion.AcceptanceTests.Helpers; +using LibGit2Sharp; + +namespace GitHubFlowVersion.AcceptanceTests +{ + public class RepositoryFixture : IDisposable + { + public readonly string RepositoryPath; + public readonly Repository Repository; + + public RepositoryFixture() + { + RepositoryPath = PathHelper.GetTempPath(); + Repository.Init(RepositoryPath); + Console.WriteLine("Created git repository at {0}", RepositoryPath); + + Repository = new Repository(RepositoryPath); + Repository.Config.Set("user.name", "Test"); + Repository.Config.Set("user.email", "test@email.com"); + } + + public void Dispose() + { + Repository.Dispose(); + try + { + Directory.Delete(RepositoryPath, true); + } + catch (Exception e) + { + Console.WriteLine("Failed to clean up repository path at {0}. Received exception: {1}", RepositoryPath, e.Message); + } + } + } +} diff --git a/AcceptanceTests/RepositorySpecification.RunSpecification.approved.txt b/AcceptanceTests/RepositorySpecification.RunSpecification.approved.txt new file mode 100644 index 0000000000..0706fc4ec5 --- /dev/null +++ b/AcceptanceTests/RepositorySpecification.RunSpecification.approved.txt @@ -0,0 +1,17 @@ +{ + "Major":0, + "Minor":1, + "Patch":0, + "Suffix":"", + "LongVersion":"0.1.0 Sha:'000000000000000000000000000000000000000'", + "NugetVersion":"0.1.0", + "ShortVersion":"0.1.0", + "BranchName":"master", + "BranchType":"Master", + "Sha":"000000000000000000000000000000000000000", + "MajorMinorPatch":"0.1.0", + "SemVer":"0.1.0", + "Version":"0.1.0", + "PreReleasePartTwo":2, + "Stability":"Final" +} diff --git a/AcceptanceTests/RepositorySpecification.RunSpecification.approved.txt.orig b/AcceptanceTests/RepositorySpecification.RunSpecification.approved.txt.orig new file mode 100644 index 0000000000..ca1e70c05f --- /dev/null +++ b/AcceptanceTests/RepositorySpecification.RunSpecification.approved.txt.orig @@ -0,0 +1,17 @@ +{ + "Major":0, + "Minor":1, + "Patch":0, + "Suffix":"", + "LongVersion":"0.1.0 Sha:'5d8a17535e215be2b92f16d0da71d25c505b5543'", + "NugetVersion":"0.1.0", + "ShortVersion":"0.1.0", + "BranchName":"master", + "BranchType":"Master", + "Sha":"5d8a17535e215be2b92f16d0da71d25c505b5543", + "MajorMinorPatch":"0.1.0", + "SemVer":"0.1.0", + "Version":"0.1.0", + "PreReleasePartTwo":2, + "Stability":"Final" +} diff --git a/AcceptanceTests/TagFollowedByCommitsWithApplicableNextVersionTxtSpecification.ForOneCommit.approved.txt b/AcceptanceTests/TagFollowedByCommitsWithApplicableNextVersionTxtSpecification.ForOneCommit.approved.txt new file mode 100644 index 0000000000..310fa32545 --- /dev/null +++ b/AcceptanceTests/TagFollowedByCommitsWithApplicableNextVersionTxtSpecification.ForOneCommit.approved.txt @@ -0,0 +1,17 @@ +{ + "Major":1, + "Minor":1, + "Patch":0, + "Suffix":"", + "LongVersion":"1.1.0 Sha:'000000000000000000000000000000000000000'", + "NugetVersion":"1.1.0", + "ShortVersion":"1.1.0", + "BranchName":"master", + "BranchType":"Master", + "Sha":"000000000000000000000000000000000000000", + "MajorMinorPatch":"1.1.0", + "SemVer":"1.1.0+1", + "Version":"1.1.0+1", + "PreReleasePartTwo":1, + "Stability":"Final" +} diff --git a/AcceptanceTests/TagFollowedByCommitsWithApplicableNextVersionTxtSpecification.ForOneCommit.approved.txt.orig b/AcceptanceTests/TagFollowedByCommitsWithApplicableNextVersionTxtSpecification.ForOneCommit.approved.txt.orig new file mode 100644 index 0000000000..b2a4eae97c --- /dev/null +++ b/AcceptanceTests/TagFollowedByCommitsWithApplicableNextVersionTxtSpecification.ForOneCommit.approved.txt.orig @@ -0,0 +1,17 @@ +{ + "Major":1, + "Minor":1, + "Patch":0, + "Suffix":"", + "LongVersion":"1.1.0 Sha:'000000000000000000000000000000000000000'", + "NugetVersion":"1.1.0", + "ShortVersion":"1.1.0", + "BranchName":"master", + "BranchType":"Master", + "Sha":"000000000000000000000000000000000000000", + "MajorMinorPatch":"1.1.0", + "SemVer":"1.1.0", + "Version":"1.1.0", + "PreReleasePartTwo":1, + "Stability":"Final" +} diff --git a/AcceptanceTests/TagFollowedByCommitsWithApplicableNextVersionTxtSpecification.ForTenCommitsCommit.approved.txt b/AcceptanceTests/TagFollowedByCommitsWithApplicableNextVersionTxtSpecification.ForTenCommitsCommit.approved.txt new file mode 100644 index 0000000000..5eb0b6b16c --- /dev/null +++ b/AcceptanceTests/TagFollowedByCommitsWithApplicableNextVersionTxtSpecification.ForTenCommitsCommit.approved.txt @@ -0,0 +1,17 @@ +{ + "Major":1, + "Minor":1, + "Patch":0, + "Suffix":"", + "LongVersion":"1.1.0 Sha:'000000000000000000000000000000000000000'", + "NugetVersion":"1.1.0", + "ShortVersion":"1.1.0", + "BranchName":"master", + "BranchType":"Master", + "Sha":"000000000000000000000000000000000000000", + "MajorMinorPatch":"1.1.0", + "SemVer":"1.1.0+12", + "Version":"1.1.0+12", + "PreReleasePartTwo":12, + "Stability":"Final" +} diff --git a/AcceptanceTests/TagFollowedByCommitsWithApplicableNextVersionTxtSpecification.ForTenCommitsCommit.approved.txt.orig b/AcceptanceTests/TagFollowedByCommitsWithApplicableNextVersionTxtSpecification.ForTenCommitsCommit.approved.txt.orig new file mode 100644 index 0000000000..a0a5b1b051 --- /dev/null +++ b/AcceptanceTests/TagFollowedByCommitsWithApplicableNextVersionTxtSpecification.ForTenCommitsCommit.approved.txt.orig @@ -0,0 +1,17 @@ +{ + "Major":1, + "Minor":1, + "Patch":0, + "Suffix":"", + "LongVersion":"1.1.0 Sha:'000000000000000000000000000000000000000'", + "NugetVersion":"1.1.0", + "ShortVersion":"1.1.0", + "BranchName":"master", + "BranchType":"Master", + "Sha":"000000000000000000000000000000000000000", + "MajorMinorPatch":"1.1.0", + "SemVer":"1.1.0", + "Version":"1.1.0", + "PreReleasePartTwo":12, + "Stability":"Final" +} diff --git a/AcceptanceTests/TagFollowedByCommitsWithApplicableNextVersionTxtSpecification.Run.approved.txt b/AcceptanceTests/TagFollowedByCommitsWithApplicableNextVersionTxtSpecification.Run.approved.txt new file mode 100644 index 0000000000..2c75488404 --- /dev/null +++ b/AcceptanceTests/TagFollowedByCommitsWithApplicableNextVersionTxtSpecification.Run.approved.txt @@ -0,0 +1,17 @@ +{ + "Major":1, + "Minor":1, + "Patch":0, + "Suffix":"", + "LongVersion":"1.1.0 Sha:'000000000000000000000000000000000000000'", + "NugetVersion":"1.1.0", + "ShortVersion":"1.1.0", + "BranchName":"master", + "BranchType":"Master", + "Sha":"000000000000000000000000000000000000000", + "MajorMinorPatch":"1.1.0", + "SemVer":"1.1.0", + "Version":"1.1.0", + "PreReleasePartTwo":2, + "Stability":"Final" +} diff --git a/AcceptanceTests/TagFollowedByCommitsWithApplicableNextVersionTxtSpecification.Run.approved.txt.orig b/AcceptanceTests/TagFollowedByCommitsWithApplicableNextVersionTxtSpecification.Run.approved.txt.orig new file mode 100644 index 0000000000..19a76f130c --- /dev/null +++ b/AcceptanceTests/TagFollowedByCommitsWithApplicableNextVersionTxtSpecification.Run.approved.txt.orig @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/AcceptanceTests/TagFollowedByCommitsWithApplicableNextVersionTxtSpecification.cs b/AcceptanceTests/TagFollowedByCommitsWithApplicableNextVersionTxtSpecification.cs new file mode 100644 index 0000000000..83d878febe --- /dev/null +++ b/AcceptanceTests/TagFollowedByCommitsWithApplicableNextVersionTxtSpecification.cs @@ -0,0 +1,69 @@ +using System; +using GitHubFlowVersion.AcceptanceTests.Helpers; +using Xunit; +using TestStack.BDDfy; + +namespace GitHubFlowVersion.AcceptanceTests +{ + using ApprovalTests; + + public class TagFollowedByCommitsWithApplicableNextVersionTxtSpecification : IUseFixture + { + private ExecutionResults _result; + private const string TaggedVersion = "1.0.3"; + private int _numCommitsToMake; + RepositoryFixture _data; + private const string NextVersionTxtVersion = "1.1.0"; + + public void GivenARepositoryWithASingleTag() + { + _data.Repository.MakeATaggedCommit(TaggedVersion); + } + + public void AndGivenRepositoryHasAnotherXCommits() + { + _data.Repository.MakeCommits(_numCommitsToMake); + } + + public void AndGivenRepositoryHasARedundantNextVersionTxtFile() + { + _data.Repository.AddNextVersionTxtFile(NextVersionTxtVersion); + } + + public void WhenGitHubFlowVersionIsExecuted() + { + _result = GitVersionHelper.ExecuteIn(_data.RepositoryPath); + } + + public void ThenAZeroExitCodeShouldOccur() + { + Assert.Equal(0, _result.ExitCode); + } + + public void AndTheCorrectVersionShouldBeOutput() + { + Approvals.Verify(_result.Output, Scrubbers.GuidScrubber); + } + + [Fact] + public void ForOneCommit() + { + _numCommitsToMake = 1; + Environment.SetEnvironmentVariable("TEAMCITY_VERSION", null); + this.BDDfy(); + } + + [Fact] + public void ForTenCommitsCommit() + { + _numCommitsToMake = 10; + Environment.SetEnvironmentVariable("TEAMCITY_VERSION", null); + this.BDDfy(); + } + + public void SetFixture(RepositoryFixture data) + { + _data = data; + } + } +} diff --git a/AcceptanceTests/TagFollowedByCommitsWithNoNextVersionTxtSpecification.RunSpecification.approved.txt b/AcceptanceTests/TagFollowedByCommitsWithNoNextVersionTxtSpecification.RunSpecification.approved.txt new file mode 100644 index 0000000000..5822ad5c1a --- /dev/null +++ b/AcceptanceTests/TagFollowedByCommitsWithNoNextVersionTxtSpecification.RunSpecification.approved.txt @@ -0,0 +1,17 @@ +{ + "Major":0, + "Minor":1, + "Patch":1, + "Suffix":"", + "LongVersion":"0.1.1 Sha:'000000000000000000000000000000000000000'", + "NugetVersion":"0.1.1", + "ShortVersion":"0.1.1", + "BranchName":"master", + "BranchType":"Master", + "Sha":"000000000000000000000000000000000000000", + "MajorMinorPatch":"0.1.1", + "SemVer":"0.1.1+1", + "Version":"0.1.1+1", + "PreReleasePartTwo":1, + "Stability":"Final" +} diff --git a/AcceptanceTests/TagFollowedByCommitsWithNoNextVersionTxtSpecification.RunSpecification.approved.txt.orig b/AcceptanceTests/TagFollowedByCommitsWithNoNextVersionTxtSpecification.RunSpecification.approved.txt.orig new file mode 100644 index 0000000000..3f76166cc2 --- /dev/null +++ b/AcceptanceTests/TagFollowedByCommitsWithNoNextVersionTxtSpecification.RunSpecification.approved.txt.orig @@ -0,0 +1,17 @@ +{ + "Major":0, + "Minor":1, + "Patch":1, + "Suffix":"", + "LongVersion":"0.1.1 Sha:'000000000000000000000000000000000000000'", + "NugetVersion":"0.1.1", + "ShortVersion":"0.1.1", + "BranchName":"master", + "BranchType":"Master", + "Sha":"000000000000000000000000000000000000000", + "MajorMinorPatch":"0.1.1", + "SemVer":"0.1.1", + "Version":"0.1.1", + "PreReleasePartTwo":1, + "Stability":"Final" +} diff --git a/AcceptanceTests/TagFollowedByCommitsWithNoNextVersionTxtSpecification.cs b/AcceptanceTests/TagFollowedByCommitsWithNoNextVersionTxtSpecification.cs new file mode 100644 index 0000000000..e40f91c0a8 --- /dev/null +++ b/AcceptanceTests/TagFollowedByCommitsWithNoNextVersionTxtSpecification.cs @@ -0,0 +1,51 @@ +using GitHubFlowVersion.AcceptanceTests.Helpers; +using Xunit; + +namespace GitHubFlowVersion.AcceptanceTests +{ + using System; + using ApprovalTests; + using TestStack.BDDfy; + + public class TagFollowedByCommitsWithNoNextVersionTxtSpecification : IUseFixture + { + private ExecutionResults _result; + RepositoryFixture _data; + + public void GivenARepositoryWithASingleTagFollowedByCommits() + { + _data.Repository.MakeATaggedCommit("0.1.0"); + _data.Repository.MakeACommit(); + } + + public void AndGivenThereIsNoNextVersionTxtFile() {} + + public void WhenGitHubFlowVersionIsExecuted() + { + _result = GitVersionHelper.ExecuteIn(_data.RepositoryPath); + } + + public void ThenNoErrorShouldOccur() + { + _result.AssertExitedSuccessfully(); + } + + public void AndTheCorrectVersionShouldBeOutput() + { + Approvals.Verify(_result.Output, Scrubbers.GuidScrubber); + } + + [Fact] + public virtual void RunSpecification() + { + // If we are actually running in teamcity, lets delete this environmental variable + Environment.SetEnvironmentVariable("TEAMCITY_VERSION", null); + this.BDDfy(); + } + + public void SetFixture(RepositoryFixture data) + { + _data = data; + } + } +} diff --git a/AcceptanceTests/TagFollowedByCommitsWithRedundantNextVersionTxtSpecification.Run.approved.txt b/AcceptanceTests/TagFollowedByCommitsWithRedundantNextVersionTxtSpecification.Run.approved.txt new file mode 100644 index 0000000000..57289a4a7d --- /dev/null +++ b/AcceptanceTests/TagFollowedByCommitsWithRedundantNextVersionTxtSpecification.Run.approved.txt @@ -0,0 +1,17 @@ +{ + "Major":1, + "Minor":0, + "Patch":4, + "Suffix":"", + "LongVersion":"1.0.4 Sha:'000000000000000000000000000000000000000'", + "NugetVersion":"1.0.4", + "ShortVersion":"1.0.4", + "BranchName":"master", + "BranchType":"Master", + "Sha":"000000000000000000000000000000000000000", + "MajorMinorPatch":"1.0.4", + "SemVer":"1.0.4", + "Version":"1.0.4", + "PreReleasePartTwo":2, + "Stability":"Final" +} diff --git a/AcceptanceTests/TagFollowedByCommitsWithRedundantNextVersionTxtSpecification.Run.approved.txt.orig b/AcceptanceTests/TagFollowedByCommitsWithRedundantNextVersionTxtSpecification.Run.approved.txt.orig new file mode 100644 index 0000000000..19a76f130c --- /dev/null +++ b/AcceptanceTests/TagFollowedByCommitsWithRedundantNextVersionTxtSpecification.Run.approved.txt.orig @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/AcceptanceTests/TagFollowedByCommitsWithRedundantNextVersionTxtSpecification.WithOneCommit.approved.txt b/AcceptanceTests/TagFollowedByCommitsWithRedundantNextVersionTxtSpecification.WithOneCommit.approved.txt new file mode 100644 index 0000000000..36fa85e723 --- /dev/null +++ b/AcceptanceTests/TagFollowedByCommitsWithRedundantNextVersionTxtSpecification.WithOneCommit.approved.txt @@ -0,0 +1,17 @@ +{ + "Major":1, + "Minor":0, + "Patch":4, + "Suffix":"", + "LongVersion":"1.0.4 Sha:'000000000000000000000000000000000000000'", + "NugetVersion":"1.0.4", + "ShortVersion":"1.0.4", + "BranchName":"master", + "BranchType":"Master", + "Sha":"000000000000000000000000000000000000000", + "MajorMinorPatch":"1.0.4", + "SemVer":"1.0.4+1", + "Version":"1.0.4+1", + "PreReleasePartTwo":1, + "Stability":"Final" +} diff --git a/AcceptanceTests/TagFollowedByCommitsWithRedundantNextVersionTxtSpecification.WithOneCommit.approved.txt.orig b/AcceptanceTests/TagFollowedByCommitsWithRedundantNextVersionTxtSpecification.WithOneCommit.approved.txt.orig new file mode 100644 index 0000000000..1faf95cb7b --- /dev/null +++ b/AcceptanceTests/TagFollowedByCommitsWithRedundantNextVersionTxtSpecification.WithOneCommit.approved.txt.orig @@ -0,0 +1,17 @@ +{ + "Major":1, + "Minor":0, + "Patch":4, + "Suffix":"", + "LongVersion":"1.0.4 Sha:'000000000000000000000000000000000000000'", + "NugetVersion":"1.0.4", + "ShortVersion":"1.0.4", + "BranchName":"master", + "BranchType":"Master", + "Sha":"000000000000000000000000000000000000000", + "MajorMinorPatch":"1.0.4", + "SemVer":"1.0.4", + "Version":"1.0.4", + "PreReleasePartTwo":12, + "Stability":"Final" +} diff --git a/AcceptanceTests/TagFollowedByCommitsWithRedundantNextVersionTxtSpecification.WithTenCommit.approved.txt b/AcceptanceTests/TagFollowedByCommitsWithRedundantNextVersionTxtSpecification.WithTenCommit.approved.txt new file mode 100644 index 0000000000..bf638e446f --- /dev/null +++ b/AcceptanceTests/TagFollowedByCommitsWithRedundantNextVersionTxtSpecification.WithTenCommit.approved.txt @@ -0,0 +1,17 @@ +{ + "Major":1, + "Minor":0, + "Patch":4, + "Suffix":"", + "LongVersion":"1.0.4 Sha:'000000000000000000000000000000000000000'", + "NugetVersion":"1.0.4", + "ShortVersion":"1.0.4", + "BranchName":"master", + "BranchType":"Master", + "Sha":"000000000000000000000000000000000000000", + "MajorMinorPatch":"1.0.4", + "SemVer":"1.0.4+12", + "Version":"1.0.4+12", + "PreReleasePartTwo":12, + "Stability":"Final" +} diff --git a/AcceptanceTests/TagFollowedByCommitsWithRedundantNextVersionTxtSpecification.WithTenCommit.approved.txt.orig b/AcceptanceTests/TagFollowedByCommitsWithRedundantNextVersionTxtSpecification.WithTenCommit.approved.txt.orig new file mode 100644 index 0000000000..e3faace630 --- /dev/null +++ b/AcceptanceTests/TagFollowedByCommitsWithRedundantNextVersionTxtSpecification.WithTenCommit.approved.txt.orig @@ -0,0 +1,17 @@ +{ + "Major":1, + "Minor":0, + "Patch":4, + "Suffix":"", + "LongVersion":"1.0.4 Sha:'000000000000000000000000000000000000000'", + "NugetVersion":"1.0.4", + "ShortVersion":"1.0.4", + "BranchName":"master", + "BranchType":"Master", + "Sha":"000000000000000000000000000000000000000", + "MajorMinorPatch":"1.0.4", + "SemVer":"1.0.4", + "Version":"1.0.4", + "PreReleasePartTwo":10, + "Stability":"Final" +} diff --git a/AcceptanceTests/TagFollowedByCommitsWithRedundantNextVersionTxtSpecification.cs b/AcceptanceTests/TagFollowedByCommitsWithRedundantNextVersionTxtSpecification.cs new file mode 100644 index 0000000000..cf0f4a56ba --- /dev/null +++ b/AcceptanceTests/TagFollowedByCommitsWithRedundantNextVersionTxtSpecification.cs @@ -0,0 +1,66 @@ +using GitHubFlowVersion.AcceptanceTests.Helpers; +using TestStack.BDDfy; + +namespace GitHubFlowVersion.AcceptanceTests +{ + using ApprovalTests; + using Xunit; + + public class TagFollowedByCommitsWithRedundantNextVersionTxtSpecification : IUseFixture + { + private ExecutionResults _result; + private const string TaggedVersion = "1.0.3"; + private int _numCommitsToMake; + RepositoryFixture _data; + private const string NextVersionTxtVersion = "1.0.0"; + + public void GivenARepositoryWithASingleTag() + { + _data.Repository.MakeATaggedCommit(TaggedVersion); + } + + public void AndGivenRepositoryHasAnotherXCommits() + { + _data.Repository.MakeCommits(_numCommitsToMake); + } + + public void AndGivenRepositoryHasARedundantNextVersionTxtFile() + { + _data.Repository.AddNextVersionTxtFile(NextVersionTxtVersion); + } + + public void WhenGitHubFlowVersionIsExecuted() + { + _result = GitVersionHelper.ExecuteIn(_data.RepositoryPath); + } + + public void ThenAZeroExitCodeShouldOccur() + { + _result.AssertExitedSuccessfully(); + } + + public void AndTheCorrectVersionShouldBeOutput() + { + Approvals.Verify(_result.Output, Scrubbers.GuidScrubber); + } + + [Fact] + public void WithOneCommit() + { + _numCommitsToMake = 1; + this.BDDfy(); + } + + [Fact] + public void WithTenCommit() + { + _numCommitsToMake = 10; + this.BDDfy(); + } + + public void SetFixture(RepositoryFixture data) + { + _data = data; + } + } +} diff --git a/AcceptanceTests/TestBuildFile.proj b/AcceptanceTests/TestBuildFile.proj new file mode 100644 index 0000000000..7b8fc61a98 --- /dev/null +++ b/AcceptanceTests/TestBuildFile.proj @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/AcceptanceTests/packages.config b/AcceptanceTests/packages.config new file mode 100644 index 0000000000..277bedfae5 --- /dev/null +++ b/AcceptanceTests/packages.config @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/GitVersion.sln b/GitVersion.sln index bcee9fdfc5..464e2bc7b8 100644 --- a/GitVersion.sln +++ b/GitVersion.sln @@ -1,12 +1,16 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2012 +# Visual Studio 2013 +VisualStudioVersion = 12.0.30110.0 +MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitVersion", "GitVersion\GitVersion.csproj", "{C3578A7B-09A6-4444-9383-0DEAFA4958BD}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{5A86453B-96FB-4B6E-A283-225BB9F753D3}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitVersionTask", "GitVersionTask\GitVersionTask.csproj", "{F7AC0E71-3E9A-4F6D-B986-E004825A48E1}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AcceptanceTests", "AcceptanceTests\AcceptanceTests.csproj", "{BF905F84-382C-440D-92F5-C61108626D8D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -33,6 +37,12 @@ Global {F7AC0E71-3E9A-4F6D-B986-E004825A48E1}.Release|Any CPU.ActiveCfg = Release|Any CPU {F7AC0E71-3E9A-4F6D-B986-E004825A48E1}.Release|Any CPU.Build.0 = Release|Any CPU {F7AC0E71-3E9A-4F6D-B986-E004825A48E1}.Release|x86.ActiveCfg = Release|Any CPU + {BF905F84-382C-440D-92F5-C61108626D8D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BF905F84-382C-440D-92F5-C61108626D8D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BF905F84-382C-440D-92F5-C61108626D8D}.Debug|x86.ActiveCfg = Debug|Any CPU + {BF905F84-382C-440D-92F5-C61108626D8D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BF905F84-382C-440D-92F5-C61108626D8D}.Release|Any CPU.Build.0 = Release|Any CPU + {BF905F84-382C-440D-92F5-C61108626D8D}.Release|x86.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/GitVersion.sln.DotSettings b/GitVersion.sln.DotSettings index a400cfe4f2..1804fce399 100644 --- a/GitVersion.sln.DotSettings +++ b/GitVersion.sln.DotSettings @@ -383,6 +383,7 @@ II.2.12 <HandlesEvent /> <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> True True + False diff --git a/GitVersion/GitVersion.csproj b/GitVersion/GitVersion.csproj index d7bcdca3b2..72d2618d6a 100644 --- a/GitVersion/GitVersion.csproj +++ b/GitVersion/GitVersion.csproj @@ -74,7 +74,7 @@ - + @@ -83,7 +83,7 @@ - + @@ -91,7 +91,7 @@ - + @@ -105,7 +105,7 @@ - + diff --git a/GitVersion/GitFlow/VariableProvider.cs b/GitVersion/OutputVariables/VariableProvider.cs similarity index 100% rename from GitVersion/GitFlow/VariableProvider.cs rename to GitVersion/OutputVariables/VariableProvider.cs diff --git a/GitVersion/VersionBuilders/InformationalVersionBuilder.cs b/GitVersion/OutputVariables/VersionBuilders/InformationalVersionBuilder.cs similarity index 100% rename from GitVersion/VersionBuilders/InformationalVersionBuilder.cs rename to GitVersion/OutputVariables/VersionBuilders/InformationalVersionBuilder.cs diff --git a/GitVersion/VersionBuilders/NugetVersionBuilder.cs b/GitVersion/OutputVariables/VersionBuilders/NugetVersionBuilder.cs similarity index 100% rename from GitVersion/VersionBuilders/NugetVersionBuilder.cs rename to GitVersion/OutputVariables/VersionBuilders/NugetVersionBuilder.cs diff --git a/GitVersion/VersionBuilders/SemVerVersionBuilder.cs b/GitVersion/OutputVariables/VersionBuilders/SemVerVersionBuilder.cs similarity index 88% rename from GitVersion/VersionBuilders/SemVerVersionBuilder.cs rename to GitVersion/OutputVariables/VersionBuilders/SemVerVersionBuilder.cs index 048254f24e..f1a0e6c0b1 100644 --- a/GitVersion/VersionBuilders/SemVerVersionBuilder.cs +++ b/GitVersion/OutputVariables/VersionBuilders/SemVerVersionBuilder.cs @@ -43,7 +43,9 @@ public static string GenerateSemVer(this VersionAndBranch versionAndBranch) break; } } - return string.Format("{0}.{1}.{2}{3}", semVer.Major, semVer.Minor, semVer.Patch, prereleaseString); + return string.Format("{0}.{1}.{2}{3}{4}", + semVer.Major, semVer.Minor, semVer.Patch, prereleaseString, + semVer.PreReleasePartTwo == null ? null : "+" + semVer.PreReleasePartTwo); } } } diff --git a/GitVersion/VersionCache.cs b/GitVersion/VersionCache.cs index 82566ea6f1..7b04195f52 100644 --- a/GitVersion/VersionCache.cs +++ b/GitVersion/VersionCache.cs @@ -14,7 +14,7 @@ public static VersionAndBranchAndDate GetVersion(string gitDirectory) var branch = repo.Head; if (branch.Tip == null) { - throw new ErrorException("No Tip found. Has repo been initialize?"); + throw new ErrorException("No Tip found. Has repo been initialized?"); } var ticks = DirectoryDateFinder.GetLastDirectoryWrite(gitDirectory); var key = string.Format("{0}:{1}:{2}", repo.Head.CanonicalName, repo.Head.Tip.Sha, ticks); diff --git a/Packages/repositories.config b/Packages/repositories.config index 472f138dd6..e6895d8637 100644 --- a/Packages/repositories.config +++ b/Packages/repositories.config @@ -1,5 +1,6 @@  + diff --git a/Tests/InformationalVersionBuilderTests.cs b/Tests/OutputVariables/InformationalVersionBuilderTests.cs similarity index 100% rename from Tests/InformationalVersionBuilderTests.cs rename to Tests/OutputVariables/InformationalVersionBuilderTests.cs diff --git a/Tests/NugetVersionBuilderTests.cs b/Tests/OutputVariables/NugetVersionBuilderTests.cs similarity index 100% rename from Tests/NugetVersionBuilderTests.cs rename to Tests/OutputVariables/NugetVersionBuilderTests.cs diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 21816cff41..0c4e2201e5 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -117,7 +117,7 @@ - + @@ -132,7 +132,7 @@ - + @@ -168,7 +168,9 @@ - + + + diff --git a/Tests/Tests.v2.ncrunchproject b/Tests/Tests.v2.ncrunchproject index 3802e773cb..851fdba444 100644 --- a/Tests/Tests.v2.ncrunchproject +++ b/Tests/Tests.v2.ncrunchproject @@ -21,6 +21,6 @@ AutoDetect STA x86 - Resources\**.*;..\Packages\LibGit2Sharp.0.15.0.0\lib\net35\NativeBinaries\**.* + Resources\**.*;..\Packages\LibGit2Sharp.0.16.0.0\lib\net35\NativeBinaries\**.* CopyReferencedAssembliesToWorkspaceIsOn \ No newline at end of file