From dd901e849243cebc979f357de84e1ee06038b730 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Wed, 27 Apr 2016 17:02:39 +0200 Subject: [PATCH 01/36] Ignore Visual Studio Code folder --- .gitignore | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 178add35c0..fa9646b36e 100644 --- a/.gitignore +++ b/.gitignore @@ -94,4 +94,11 @@ site/ ################ .idea -*.sln.iml \ No newline at end of file +*.sln.iml + + +#################### +# Visual Studio Code +#################### + +.vscode \ No newline at end of file From 4b40dafa0e9ef4b3fc0e40855b4bc8492032c14a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Wed, 27 Apr 2016 17:19:23 +0200 Subject: [PATCH 02/36] Added missing solution files --- src/GitVersion.sln | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/GitVersion.sln b/src/GitVersion.sln index 21be8e6c7c..d9c3232212 100644 --- a/src/GitVersion.sln +++ b/src/GitVersion.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.24720.0 +VisualStudioVersion = 14.0.25123.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitVersionExe", "GitVersionExe\GitVersionExe.csproj", "{C3578A7B-09A6-4444-9383-0DEAFA4958BD}" EndProject @@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitVersionCore.Tests", "Git EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{3EFFC5D6-88D0-49D9-BB53-E1B7EB49DD45}" ProjectSection(SolutionItems) = preProject + ..\.gitattributes = ..\.gitattributes + ..\.gitignore = ..\.gitignore ..\.travis.yml = ..\.travis.yml ..\appveyor.yml = ..\appveyor.yml ..\BREAKING CHANGES.md = ..\BREAKING CHANGES.md From aae06d46a3ee002770e0eea8b6eca227e96ce986 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Wed, 27 Apr 2016 17:20:07 +0200 Subject: [PATCH 03/36] Use lowercase b in 'build' Use lowercase `b` in `build` for improved compatibility with case-sensitive file systems. --- src/GitVersionTask/GitVersionTask.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GitVersionTask/GitVersionTask.csproj b/src/GitVersionTask/GitVersionTask.csproj index 41c9f247c9..f73562bfb9 100644 --- a/src/GitVersionTask/GitVersionTask.csproj +++ b/src/GitVersionTask/GitVersionTask.csproj @@ -126,8 +126,8 @@ - - + + From 75459d1abab24223fc5816c0722f8f1d758ba3d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Thu, 28 Apr 2016 08:02:53 +0200 Subject: [PATCH 04/36] Less brittle current directory Base the current directory of the documentation tests on the location of the test assembly instead of `Environment.CurrentDirectory`. --- src/GitVersionCore.Tests/DocumentationTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GitVersionCore.Tests/DocumentationTests.cs b/src/GitVersionCore.Tests/DocumentationTests.cs index e28f1157ae..5e6b89e39e 100644 --- a/src/GitVersionCore.Tests/DocumentationTests.cs +++ b/src/GitVersionCore.Tests/DocumentationTests.cs @@ -57,7 +57,7 @@ public void VariableDocumentationIsUpToDate() static string ReadDocumentationFile(string relativeDocumentationFilePath) { - var currentDirectory = new DirectoryInfo(Environment.CurrentDirectory); + var currentDirectory = new FileInfo(typeof(DocumentationTests).Assembly.Location).Directory; while (currentDirectory != null) { var docsDirectory = currentDirectory From a0d38849063105b260ee864705c6cbaa8cca8659 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Thu, 28 Apr 2016 08:09:24 +0200 Subject: [PATCH 05/36] Fixed LibGit2Sharp obsolete warnings --- src/GitVersionCore.Tests/IntegrationTests/OtherScenarios.cs | 4 ++-- .../IntegrationTests/RemoteRepositoryScenarios.cs | 2 +- src/GitVersionExe.Tests/PullRequestInTeamCityTest.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/GitVersionCore.Tests/IntegrationTests/OtherScenarios.cs b/src/GitVersionCore.Tests/IntegrationTests/OtherScenarios.cs index 8d9cb539de..9c7ad0e311 100644 --- a/src/GitVersionCore.Tests/IntegrationTests/OtherScenarios.cs +++ b/src/GitVersionCore.Tests/IntegrationTests/OtherScenarios.cs @@ -22,7 +22,7 @@ public void DoNotBlowUpWhenMasterAndDevelopPointAtSameCommit() fixture.Repository.MakeACommit(); fixture.Repository.CreateBranch("develop"); - fixture.LocalRepositoryFixture.Repository.Network.Fetch(fixture.LocalRepositoryFixture.Repository.Network.Remotes.First()); + Commands.Fetch((Repository)fixture.LocalRepositoryFixture.Repository, fixture.LocalRepositoryFixture.Repository.Network.Remotes.First().Name, new string[0], new FetchOptions(), null); fixture.LocalRepositoryFixture.Repository.Checkout(fixture.Repository.Head.Tip); fixture.LocalRepositoryFixture.Repository.Branches.Remove("master"); fixture.InitialiseRepo(); @@ -81,7 +81,7 @@ public void DoNotBlowUpWhenDevelopAndFeatureBranchPointAtSameCommit() fixture.Repository.MakeACommit(); fixture.Repository.CreateBranch("feature/someFeature"); - fixture.LocalRepositoryFixture.Repository.Network.Fetch(fixture.LocalRepositoryFixture.Repository.Network.Remotes.First()); + Commands.Fetch((Repository)fixture.LocalRepositoryFixture.Repository, fixture.LocalRepositoryFixture.Repository.Network.Remotes.First().Name, new string[0], new FetchOptions(), null); fixture.LocalRepositoryFixture.Repository.Checkout(fixture.Repository.Head.Tip); fixture.LocalRepositoryFixture.Repository.Branches.Remove("master"); fixture.InitialiseRepo(); diff --git a/src/GitVersionCore.Tests/IntegrationTests/RemoteRepositoryScenarios.cs b/src/GitVersionCore.Tests/IntegrationTests/RemoteRepositoryScenarios.cs index 7a516ff60b..dfd3c35715 100644 --- a/src/GitVersionCore.Tests/IntegrationTests/RemoteRepositoryScenarios.cs +++ b/src/GitVersionCore.Tests/IntegrationTests/RemoteRepositoryScenarios.cs @@ -57,7 +57,7 @@ public void GivenARemoteGitRepositoryAheadOfLocalRepository_ThenChangesShouldPul fixture.AssertFullSemver("0.1.0+5"); fixture.AssertFullSemver("0.1.0+4", fixture.LocalRepositoryFixture.Repository); var buildSignature = fixture.LocalRepositoryFixture.Repository.Config.BuildSignature(new DateTimeOffset(DateTime.Now)); - fixture.LocalRepositoryFixture.Repository.Network.Pull(buildSignature, new PullOptions()); + Commands.Pull((Repository) fixture.LocalRepositoryFixture.Repository, buildSignature, new PullOptions()); fixture.AssertFullSemver("0.1.0+5", fixture.LocalRepositoryFixture.Repository); } } diff --git a/src/GitVersionExe.Tests/PullRequestInTeamCityTest.cs b/src/GitVersionExe.Tests/PullRequestInTeamCityTest.cs index e9d2eb128b..2a8ee24d23 100644 --- a/src/GitVersionExe.Tests/PullRequestInTeamCityTest.cs +++ b/src/GitVersionExe.Tests/PullRequestInTeamCityTest.cs @@ -35,7 +35,7 @@ public void GivenARemoteWithATagOnMaster_AndAPullRequestWithTwoCommits_AndBuildI remoteRepository.Refs.Add(pullRequestRef, new ObjectId(mergeCommitSha)); // Checkout PR commit - fixture.Repository.Fetch("origin"); + Commands.Fetch((Repository)fixture.Repository, "origin", new string[0], new FetchOptions(), null); fixture.Repository.Checkout(mergeCommitSha); } From 2755fb744ced640038fa30973968a84169f35cfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Thu, 28 Apr 2016 08:27:41 +0200 Subject: [PATCH 06/36] Don't run 'NoMono' tests on Mono --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 161938fd53..a6db03268c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,4 +7,4 @@ install: - nuget install NUnit.Runners -Version 3.2.1 -OutputDirectory ./src/packages script: - xbuild "./src/GitVersion.sln" /property:Configuration="Debug" /verbosity:detailed - - mono --debug --runtime=v4.0.30319 ./src/packages/NUnit.ConsoleRunner.3.2.1/tools/nunit3-console.exe ./src/GitVersionTask.Tests/bin/Debug/GitVersionTask.Tests.dll ./src/GitVersionCore.Tests/bin/Debug/GitVersionCore.Tests.dll ./src/GitVersionTask.Tests/bin/Debug/GitVersionTask.Tests.dll ./src/GitVersionExe.Tests/bin/Debug/GitVersionExe.Tests.dll + - mono --debug --runtime=v4.0.30319 ./src/packages/NUnit.ConsoleRunner.3.2.1/tools/nunit3-console.exe ./src/GitVersionTask.Tests/bin/Debug/GitVersionTask.Tests.dll ./src/GitVersionCore.Tests/bin/Debug/GitVersionCore.Tests.dll ./src/GitVersionTask.Tests/bin/Debug/GitVersionTask.Tests.dll ./src/GitVersionExe.Tests/bin/Debug/GitVersionExe.Tests.dll -where "cat != NoMono" From 3a67f5e625bce42790244e8de9e20ae91b548596 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Thu, 28 Apr 2016 08:30:15 +0200 Subject: [PATCH 07/36] Add NoMono category to tests Add 'NoMono' category to AssemblyInfoBuilder tests since source information is not available to `ShouldMatchApproved()` on Mono. --- .../AssemblyInfoBuilderTests.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.cs b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.cs index f82f335a47..40352406b9 100644 --- a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.cs +++ b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.cs @@ -61,6 +61,8 @@ public Compilation Compile(string assemblyInfoText) }; [Test] + [NUnit.Framework.Category("NoMono")] + [NUnit.Framework.Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")] public void VerifyCreatedCode([ValueSource("compilers")]ICompiler compiler) { var semanticVersion = new SemanticVersion @@ -94,6 +96,8 @@ public void VerifyCreatedCode([ValueSource("compilers")]ICompiler compiler) } [Test] + [NUnit.Framework.Category("NoMono")] + [NUnit.Framework.Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")] public void VerifyCreatedCode_NoNamespaceConflict([ValueSource("compilers")]ICompiler compiler) { var semanticVersion = new SemanticVersion @@ -120,6 +124,8 @@ public void VerifyCreatedCode_NoNamespaceConflict([ValueSource("compilers")]ICom [Test] [MethodImpl(MethodImplOptions.NoInlining)] + [NUnit.Framework.Category("NoMono")] + [NUnit.Framework.Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")] public void VerifyAssemblyVersion_Major([ValueSource("compilers")]ICompiler compiler) { VerifyAssemblyVersion(compiler, AssemblyVersioningScheme.Major); @@ -127,6 +133,8 @@ public void VerifyAssemblyVersion_Major([ValueSource("compilers")]ICompiler comp [Test] [MethodImpl(MethodImplOptions.NoInlining)] + [NUnit.Framework.Category("NoMono")] + [NUnit.Framework.Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")] public void VerifyAssemblyVersion_MajorMinor([ValueSource("compilers")]ICompiler compiler) { VerifyAssemblyVersion(compiler, AssemblyVersioningScheme.MajorMinor); @@ -134,6 +142,8 @@ public void VerifyAssemblyVersion_MajorMinor([ValueSource("compilers")]ICompiler [Test] [MethodImpl(MethodImplOptions.NoInlining)] + [NUnit.Framework.Category("NoMono")] + [NUnit.Framework.Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")] public void VerifyAssemblyVersion_MajorMinorPatch([ValueSource("compilers")]ICompiler compiler) { VerifyAssemblyVersion(compiler, AssemblyVersioningScheme.MajorMinorPatch); @@ -141,6 +151,8 @@ public void VerifyAssemblyVersion_MajorMinorPatch([ValueSource("compilers")]ICom [Test] [MethodImpl(MethodImplOptions.NoInlining)] + [NUnit.Framework.Category("NoMono")] + [NUnit.Framework.Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")] public void VerifyAssemblyVersion_MajorMinorPatchTag([ValueSource("compilers")]ICompiler compiler) { VerifyAssemblyVersion(compiler, AssemblyVersioningScheme.MajorMinorPatchTag); @@ -148,6 +160,8 @@ public void VerifyAssemblyVersion_MajorMinorPatchTag([ValueSource("compilers")]I [Test] [MethodImpl(MethodImplOptions.NoInlining)] + [NUnit.Framework.Category("NoMono")] + [NUnit.Framework.Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")] public void VerifyAssemblyVersion_Major_InvalidInformationalValue([ValueSource("compilers")]ICompiler compiler) { var exception = Assert.Throws(() => VerifyAssemblyVersion(compiler, AssemblyVersioningScheme.Major, "{ThisVariableDoesntExist}")); @@ -156,6 +170,8 @@ public void VerifyAssemblyVersion_Major_InvalidInformationalValue([ValueSource(" [Test] [MethodImpl(MethodImplOptions.NoInlining)] + [NUnit.Framework.Category("NoMono")] + [NUnit.Framework.Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")] public void VerifyAssemblyVersion_Major_NugetAssemblyInfo([ValueSource("compilers")]ICompiler compiler) { VerifyAssemblyVersion(compiler, AssemblyVersioningScheme.Major, "{NugetVersion}"); @@ -163,6 +179,7 @@ public void VerifyAssemblyVersion_Major_NugetAssemblyInfo([ValueSource("compiler [Test] [MethodImpl(MethodImplOptions.NoInlining)] + [NUnit.Framework.Category("NoMono")] public void VerifyAssemblyVersion_MajorMinor_NugetAssemblyInfoWithMultipleVariables([ValueSource("compilers")]ICompiler compiler) { VerifyAssemblyVersion(compiler, AssemblyVersioningScheme.MajorMinor, "{BranchName}-{Major}.{Minor}.{Patch}-{Sha}"); @@ -170,6 +187,8 @@ public void VerifyAssemblyVersion_MajorMinor_NugetAssemblyInfoWithMultipleVariab [Test] [MethodImpl(MethodImplOptions.NoInlining)] + [NUnit.Framework.Category("NoMono")] + [NUnit.Framework.Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")] public void VerifyAssemblyVersion_MajorMinor_NugetAssemblyInfo([ValueSource("compilers")]ICompiler compiler) { VerifyAssemblyVersion(compiler, AssemblyVersioningScheme.MajorMinor, "{NugetVersion}"); @@ -177,6 +196,8 @@ public void VerifyAssemblyVersion_MajorMinor_NugetAssemblyInfo([ValueSource("com [Test] [MethodImpl(MethodImplOptions.NoInlining)] + [NUnit.Framework.Category("NoMono")] + [NUnit.Framework.Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")] public void VerifyAssemblyVersion_MajorMinorPatch_NugetAssemblyInfo([ValueSource("compilers")]ICompiler compiler) { VerifyAssemblyVersion(compiler, AssemblyVersioningScheme.MajorMinorPatch, "{NugetVersion}"); @@ -184,6 +205,8 @@ public void VerifyAssemblyVersion_MajorMinorPatch_NugetAssemblyInfo([ValueSource [Test] [MethodImpl(MethodImplOptions.NoInlining)] + [NUnit.Framework.Category("NoMono")] + [NUnit.Framework.Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")] public void VerifyAssemblyVersion_MajorMinorPatchTag_NugetAssemblyInfo([ValueSource("compilers")]ICompiler compiler) { VerifyAssemblyVersion(compiler, AssemblyVersioningScheme.MajorMinorPatchTag, "{NugetVersion}"); From 5532f9b09e0074db06bbdc6ba1b82cc69a8ca39b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Thu, 28 Apr 2016 09:37:48 +0200 Subject: [PATCH 08/36] Deleted meaningless test Deleted test that effectively only tested the ProcessHelper; not GitVersion.exe, as it appeared to. --- src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs b/src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs index a212705166..3820242765 100644 --- a/src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs +++ b/src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs @@ -1,7 +1,6 @@ using System.IO; using GitTools.Testing; using NUnit.Framework; - using Shouldly; [TestFixture] @@ -52,17 +51,10 @@ public void InvalidArgumentsExitCodeShouldNotBeZero() "; File.WriteAllText(buildFile, buildFileContent); - var result = GitVersionHelper.ExecuteIn(fixture.RepositoryPath, arguments : " /invalid-argument"); + var result = GitVersionHelper.ExecuteIn(fixture.RepositoryPath, arguments: " /invalid-argument"); result.ExitCode.ShouldBe(1); result.Output.ShouldContain("Failed to parse arguments"); } } - - [Test] - public void InvalidWorkingDirectoryCrashesWithInformativeMessage() - { - var results = GitVersionHelper.ExecuteIn("InvalidDirectory", null, isTeamCity : false, logToFile : false); - results.Output.ShouldContain("InvalidDirectory"); - } } \ No newline at end of file From ca52c389b5a1e49cb73ec2c4f27e5cc2f2f9a94d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Thu, 28 Apr 2016 09:50:45 +0200 Subject: [PATCH 09/36] Deleted ProcessHelper Deleted ProcessHelper and replaced usage with the one from GitTools.Core. --- src/GitVersionCore/GitVersionCore.csproj | 1 - src/GitVersionCore/Helpers/ProcessHelper.cs | 154 ------------------- src/GitVersionExe.Tests/GitVersionHelper.cs | 24 ++- src/GitVersionExe/SpecifiedArgumentRunner.cs | 4 +- 4 files changed, 20 insertions(+), 163 deletions(-) delete mode 100644 src/GitVersionCore/Helpers/ProcessHelper.cs diff --git a/src/GitVersionCore/GitVersionCore.csproj b/src/GitVersionCore/GitVersionCore.csproj index 599be843c9..9401a443bf 100644 --- a/src/GitVersionCore/GitVersionCore.csproj +++ b/src/GitVersionCore/GitVersionCore.csproj @@ -119,7 +119,6 @@ - diff --git a/src/GitVersionCore/Helpers/ProcessHelper.cs b/src/GitVersionCore/Helpers/ProcessHelper.cs deleted file mode 100644 index 6b131470d1..0000000000 --- a/src/GitVersionCore/Helpers/ProcessHelper.cs +++ /dev/null @@ -1,154 +0,0 @@ -namespace GitVersion.Helpers -{ - using System; - using System.Collections.Generic; - using System.ComponentModel; - using System.Diagnostics; - using System.IO; - using System.Runtime.InteropServices; - using System.Threading; - - public static class ProcessHelper - { - 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)) - { - try - { - process = Process.Start(startInfo); - } - catch (Win32Exception exception) - { - // NOTE: https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396 @asbjornu - if (exception.NativeErrorCode == 2) - { - throw new FileNotFoundException(string.Format("The executable file '{0}' could not be found.", - startInfo.FileName), - startInfo.FileName, - exception); - } - - throw; - } - } - } - - 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, params KeyValuePair[] environmentalVariables) - { - if (string.IsNullOrEmpty(exe)) - throw new ArgumentNullException("exe"); - - if (output == null) - throw new ArgumentNullException("output"); - - workingDirectory = workingDirectory ?? Environment.CurrentDirectory; - - if (!Directory.Exists(workingDirectory)) - { - errorOutput(string.Format("The directory {0} doesn't exist.", workingDirectory)); - return 1; - } - - var psi = new ProcessStartInfo - { - UseShellExecute = false, - RedirectStandardError = true, - RedirectStandardOutput = true, - RedirectStandardInput = true, - WindowStyle = ProcessWindowStyle.Hidden, - CreateNoWindow = true, - ErrorDialog = false, - WorkingDirectory = workingDirectory, - FileName = exe, - Arguments = args - }; - foreach (var environmentalVariable in environmentalVariables) - { - if (psi.EnvironmentVariables.ContainsKey(environmentalVariable.Key)) - { - psi.EnvironmentVariables[environmentalVariable.Key] = environmentalVariable.Value; - } - else - { - psi.EnvironmentVariables.Add(environmentalVariable.Key, environmentalVariable.Value); - } - if (psi.EnvironmentVariables.ContainsKey(environmentalVariable.Key) && environmentalVariable.Value == null) - psi.EnvironmentVariables.Remove(environmentalVariable.Key); - } - - using (var 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 - { - int oldMode; - - public ChangeErrorMode(ErrorModes mode) - { - oldMode = SetErrorMode((int)mode); - } - - void IDisposable.Dispose() { SetErrorMode(oldMode); } - - [DllImport("kernel32.dll")] - static extern int SetErrorMode(int newMode); - } - } -} \ No newline at end of file diff --git a/src/GitVersionExe.Tests/GitVersionHelper.cs b/src/GitVersionExe.Tests/GitVersionHelper.cs index d9b55c78f4..0230813db5 100644 --- a/src/GitVersionExe.Tests/GitVersionHelper.cs +++ b/src/GitVersionExe.Tests/GitVersionHelper.cs @@ -2,8 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Text; - -using GitVersion.Helpers; +using GitTools; public static class GitVersionHelper { @@ -41,10 +40,23 @@ static ExecutionResults ExecuteIn(ArgumentBuilder arguments) new KeyValuePair("APPVEYOR", null) }; - var exitCode = ProcessHelper.Run( - s => output.AppendLine(s), s => output.AppendLine(s), null, - gitVersion, arguments.ToString(), arguments.WorkingDirectory, - environmentalVariables); + var exitCode = -1; + + try + { + exitCode = ProcessHelper.Run( + s => output.AppendLine(s), s => output.AppendLine(s), null, + gitVersion, arguments.ToString(), arguments.WorkingDirectory, + environmentalVariables); + } + catch (Exception exception) + { + // NOTE: It's the exit code and output from the process we want to test, + // not the internals of the ProcessHelper. That's why we're catching + // any exceptions here, because problems in the process being executed + // should be visible in the output or exit code. @asbjornu + Console.WriteLine(exception); + } Console.WriteLine("Output from GitVersion.exe"); Console.WriteLine("-------------------------------------------------------"); diff --git a/src/GitVersionExe/SpecifiedArgumentRunner.cs b/src/GitVersionExe/SpecifiedArgumentRunner.cs index ecffed2884..ea810816d7 100644 --- a/src/GitVersionExe/SpecifiedArgumentRunner.cs +++ b/src/GitVersionExe/SpecifiedArgumentRunner.cs @@ -2,10 +2,10 @@ namespace GitVersion { using System; using System.Collections.Generic; - using System.ComponentModel; using System.Linq; - + using GitTools; using GitVersion.Helpers; + using WarningException = System.ComponentModel.WarningException; class SpecifiedArgumentRunner { From 4b809b259f3645a14863d8f27d09c2ef7e137ee7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Thu, 28 Apr 2016 11:09:06 +0200 Subject: [PATCH 10/36] Avoid multiple enumerations of assembly info files --- src/GitVersionExe/AssemblyInfoFileUpdate.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GitVersionExe/AssemblyInfoFileUpdate.cs b/src/GitVersionExe/AssemblyInfoFileUpdate.cs index 604e286c87..d5a60c3d1e 100644 --- a/src/GitVersionExe/AssemblyInfoFileUpdate.cs +++ b/src/GitVersionExe/AssemblyInfoFileUpdate.cs @@ -20,8 +20,8 @@ public AssemblyInfoFileUpdate(Arguments args, string workingDirectory, VersionVa if (args.Output != OutputType.Json) Logger.WriteInfo("Updating assembly info files"); - var assemblyInfoFiles = GetAssemblyInfoFiles(workingDirectory, args, fileSystem); - Logger.WriteInfo(string.Format("Found {0} files", assemblyInfoFiles.Count())); + var assemblyInfoFiles = GetAssemblyInfoFiles(workingDirectory, args, fileSystem).ToList(); + Logger.WriteInfo(string.Format("Found {0} files", assemblyInfoFiles.Count)); var assemblyVersion = variables.AssemblySemVer; var assemblyVersionRegex = new Regex(@"AssemblyVersion\(""[^""]*""\)"); From 552c0300f1794e2a107a50ba2151537935830497 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Thu, 28 Apr 2016 11:48:59 +0200 Subject: [PATCH 11/36] Improved exception on missing source files in TestFileSystem.Copy() --- src/GitVersionCore.Tests/TestFileSystem.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/GitVersionCore.Tests/TestFileSystem.cs b/src/GitVersionCore.Tests/TestFileSystem.cs index 7420b3d448..2828223d03 100644 --- a/src/GitVersionCore.Tests/TestFileSystem.cs +++ b/src/GitVersionCore.Tests/TestFileSystem.cs @@ -18,7 +18,12 @@ public void Copy(string @from, string to, bool overwrite) else throw new IOException("File already exists"); } - fileSystem.Add(to, fileSystem[from]); + + string source; + if (!fileSystem.TryGetValue(from, out source)) + throw new FileNotFoundException(string.Format("The source file '{0}' was not found", from), from); + + fileSystem.Add(to, source); } public void Move(string @from, string to) From da811f6c55e14659c46487c5f8d8b8158a1dd2e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Thu, 28 Apr 2016 11:55:30 +0200 Subject: [PATCH 12/36] Unix and Mono proofed AssemblyInfoFileUpdate tests --- .../AssemblyInfoFileUpdateTests.cs | 215 ++++++++++-------- 1 file changed, 123 insertions(+), 92 deletions(-) diff --git a/src/GitVersionExe.Tests/AssemblyInfoFileUpdateTests.cs b/src/GitVersionExe.Tests/AssemblyInfoFileUpdateTests.cs index e51d319d1b..6d73271b1c 100644 --- a/src/GitVersionExe.Tests/AssemblyInfoFileUpdateTests.cs +++ b/src/GitVersionExe.Tests/AssemblyInfoFileUpdateTests.cs @@ -10,6 +10,7 @@ using System; using System.IO; using Shouldly; +using System.Text; [TestFixture] public class AssemblyInfoFileUpdateTests @@ -21,10 +22,12 @@ public void SetLoggers() } [Test] + [Category("NoMono")] + [Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")] public void ShouldCreateCSharpAssemblyInfoFileWhenNotExistsAndEnsureAssemblyInfo() { var fileSystem = new TestFileSystem(); - const string workingDir = "C:\\Testing"; + var workingDir = Path.GetTempPath(); ISet assemblyInfoFile = new HashSet { "VersionAssemblyInfo.cs" }; var fullPath = Path.Combine(workingDir, assemblyInfoFile.First()); @@ -36,11 +39,13 @@ public void ShouldCreateCSharpAssemblyInfoFileWhenNotExistsAndEnsureAssemblyInfo } [Test] + [Category("NoMono")] + [Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")] public void ShouldCreateCSharpAssemblyInfoFileAtPathWhenNotExistsAndEnsureAssemblyInfo() { var fileSystem = new TestFileSystem(); - const string workingDir = "C:\\Testing"; - ISet assemblyInfoFile = new HashSet { @"src\Project\Properties\VersionAssemblyInfo.cs" }; + var workingDir = Path.GetTempPath(); + ISet assemblyInfoFile = new HashSet { Path.Combine("src", "Project", "Properties", "VersionAssemblyInfo.cs") }; var fullPath = Path.Combine(workingDir, assemblyInfoFile.First()); var variables = VariableProvider.GetVariablesFor(SemanticVersion.Parse("1.0.0", "v"), new TestEffectiveConfiguration(), false); @@ -51,11 +56,13 @@ public void ShouldCreateCSharpAssemblyInfoFileAtPathWhenNotExistsAndEnsureAssemb } [Test] + [Category("NoMono")] + [Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")] public void ShouldCreateCSharpAssemblyInfoFilesAtPathWhenNotExistsAndEnsureAssemblyInfo() { var fileSystem = new TestFileSystem(); - const string workingDir = "C:\\Testing"; - ISet assemblyInfoFile = new HashSet { "AssemblyInfo.cs", @"src\Project\Properties\VersionAssemblyInfo.cs" }; + var workingDir = Path.GetTempPath(); + ISet assemblyInfoFile = new HashSet { "AssemblyInfo.cs", Path.Combine("src", "Project", "Properties", "VersionAssemblyInfo.cs") }; var variables = VariableProvider.GetVariablesFor(SemanticVersion.Parse("1.0.0", "v"), new TestEffectiveConfiguration(), false); using (new AssemblyInfoFileUpdate(new Arguments { EnsureAssemblyInfo = true, UpdateAssemblyInfo = true, UpdateAssemblyInfoFileName = assemblyInfoFile }, workingDir, variables, fileSystem)) @@ -63,8 +70,8 @@ public void ShouldCreateCSharpAssemblyInfoFilesAtPathWhenNotExistsAndEnsureAssem foreach (var item in assemblyInfoFile) { var fullPath = Path.Combine(workingDir, item); - // ReSharper disable once AccessToForEachVariableInClosure - fileSystem.ReadAllText(fullPath).ShouldMatchApproved(c => c.WithDescriminator(item.Replace("\\", string.Empty).Replace(".", string.Empty))); + var fileDescriminator = item.Replace(Path.DirectorySeparatorChar.ToString(), string.Empty).Replace(".", string.Empty); + fileSystem.ReadAllText(fullPath).ShouldMatchApproved(c => c.WithDescriminator(fileDescriminator)); } } } @@ -73,7 +80,7 @@ public void ShouldCreateCSharpAssemblyInfoFilesAtPathWhenNotExistsAndEnsureAssem public void ShouldNotCreateCSharpAssemblyInfoFileWhenNotExistsAndNotEnsureAssemblyInfo() { var fileSystem = new TestFileSystem(); - const string workingDir = "C:\\Testing"; + var workingDir = Path.GetTempPath(); ISet assemblyInfoFile = new HashSet { "VersionAssemblyInfo.cs" }; var fullPath = Path.Combine(workingDir, assemblyInfoFile.First()); @@ -88,7 +95,7 @@ public void ShouldNotCreateCSharpAssemblyInfoFileWhenNotExistsAndNotEnsureAssemb public void ShouldNotCreateFSharpAssemblyInfoFileWhenNotExistsAndNotEnsureAssemblyInfo() { var fileSystem = Substitute.For(); - const string workingDir = "C:\\Testing"; + var workingDir = Path.GetTempPath(); ISet assemblyInfoFile = new HashSet { "VersionAssemblyInfo.fs" }; var fullPath = Path.Combine(workingDir, assemblyInfoFile.First()); @@ -104,7 +111,7 @@ public void ShouldNotCreateFSharpAssemblyInfoFileWhenNotExistsAndNotEnsureAssemb public void ShouldNotCreateVisualBasicAssemblyInfoFileWhenNotExistsAndNotEnsureAssemblyInfo() { var fileSystem = Substitute.For(); - const string workingDir = "C:\\Testing"; + var workingDir = Path.GetTempPath(); ISet assemblyInfoFile = new HashSet { "VersionAssemblyInfo.vb" }; var fullPath = Path.Combine(workingDir, assemblyInfoFile.First()); @@ -121,7 +128,7 @@ public void ShouldNotCreateVisualBasicAssemblyInfoFileWhenNotExistsAndNotEnsureA public void ShouldCreateVisualBasicAssemblyInfoFileWhenNotExistsAndEnsureAssemblyInfo() { var fileSystem = Substitute.For(); - const string workingDir = "C:\\Testing"; + var workingDir = Path.GetTempPath(); ISet assemblyInfoFile = new HashSet { "VersionAssemblyInfo.vb" }; var fullPath = Path.Combine(workingDir, assemblyInfoFile.First()); @@ -137,7 +144,7 @@ public void ShouldCreateVisualBasicAssemblyInfoFileWhenNotExistsAndEnsureAssembl public void ShouldCreateFSharpAssemblyInfoFileWhenNotExistsAndEnsureAssemblyInfo() { var fileSystem = Substitute.For(); - const string workingDir = "C:\\Testing"; + var workingDir = Path.GetTempPath(); ISet assemblyInfoFile = new HashSet { "VersionAssemblyInfo.fs" }; var fullPath = Path.Combine(workingDir, assemblyInfoFile.First()); @@ -153,7 +160,7 @@ public void ShouldCreateFSharpAssemblyInfoFileWhenNotExistsAndEnsureAssemblyInfo public void ShouldNotCreateAssemblyInfoFileForUnknownSourceCodeAndEnsureAssemblyInfo() { var fileSystem = Substitute.For(); - const string workingDir = "C:\\Testing"; + var workingDir = Path.GetTempPath(); ISet assemblyInfoFile = new HashSet { "VersionAssemblyInfo.js" }; var fullPath = Path.Combine(workingDir, assemblyInfoFile.First()); @@ -168,7 +175,7 @@ public void ShouldNotCreateAssemblyInfoFileForUnknownSourceCodeAndEnsureAssembly public void ShouldStartSearchFromWorkingDirectory() { var fileSystem = Substitute.For(); - const string workingDir = "C:\\Testing"; + var workingDir = Path.GetTempPath(); var config = new TestEffectiveConfiguration(); var variables = VariableProvider.GetVariablesFor(SemanticVersion.Parse("1.0.0", "v"), config, false); @@ -190,13 +197,14 @@ public void ShouldReplaceAssemblyVersion() Patch = 1 }; - const string workingDir = "C:\\Testing"; - const string assemblyInfoFile = @"AssemblyVersion(""1.0.0.0""); -AssemblyInformationalVersion(""1.0.0.0""); -AssemblyFileVersion(""1.0.0.0"");"; + var workingDir = Path.GetTempPath(); + string assemblyInfoFile = Join(@"AssemblyVersion(""1.0.0.0"");", + @"AssemblyInformationalVersion(""1.0.0.0"");", + @"AssemblyFileVersion(""1.0.0.0"");"); - fileSystem.Exists("C:\\Testing\\AssemblyInfo.cs").Returns(true); - fileSystem.ReadAllText("C:\\Testing\\AssemblyInfo.cs").Returns(assemblyInfoFile); + var fileName = Path.Combine(workingDir, "AssemblyInfo.cs"); + fileSystem.Exists(fileName).Returns(true); + fileSystem.ReadAllText(fileName).Returns(assemblyInfoFile); var config = new TestEffectiveConfiguration(assemblyVersioningScheme: AssemblyVersioningScheme.MajorMinor); @@ -208,10 +216,10 @@ public void ShouldReplaceAssemblyVersion() }; using (new AssemblyInfoFileUpdate(args, workingDir, variable, fileSystem)) { - const string expected = @"AssemblyVersion(""2.3.0.0""); -AssemblyInformationalVersion(""2.3.1+3.Branch.foo.Sha.hash""); -AssemblyFileVersion(""2.3.1.0"");"; - fileSystem.Received().WriteAllText("C:\\Testing\\AssemblyInfo.cs", expected); + string expected = Join(@"AssemblyVersion(""2.3.0.0"");", + @"AssemblyInformationalVersion(""2.3.1+3.Branch.foo.Sha.hash"");", + @"AssemblyFileVersion(""2.3.1.0"");"); + fileSystem.Received().WriteAllText(fileName, expected); } } @@ -227,13 +235,14 @@ public void ShouldReplaceAssemblyVersionInRelativePath() Patch = 1 }; - const string workingDir = "C:\\Testing"; - const string assemblyInfoFile = @"AssemblyVersion(""1.0.0.0""); -AssemblyInformationalVersion(""1.0.0.0""); -AssemblyFileVersion(""1.0.0.0"");"; + var workingDir = Path.GetTempPath(); + string assemblyInfoFile = Join(@"AssemblyVersion(""1.0.0.0"");", + @"AssemblyInformationalVersion(""1.0.0.0"");", + @"AssemblyFileVersion(""1.0.0.0"");"); - fileSystem.Exists("C:\\Testing\\Project\\src\\Properties\\AssemblyInfo.cs").Returns(true); - fileSystem.ReadAllText("C:\\Testing\\Project\\src\\Properties\\AssemblyInfo.cs").Returns(assemblyInfoFile); + var fileName = Path.Combine(workingDir, "Project", "src", "Properties", "AssemblyInfo.cs"); + fileSystem.Exists(fileName).Returns(true); + fileSystem.ReadAllText(fileName).Returns(assemblyInfoFile); var config = new TestEffectiveConfiguration(assemblyVersioningScheme: AssemblyVersioningScheme.MajorMinor); @@ -241,14 +250,14 @@ public void ShouldReplaceAssemblyVersionInRelativePath() var args = new Arguments { UpdateAssemblyInfo = true, - UpdateAssemblyInfoFileName = new HashSet { @"Project\src\Properties\AssemblyInfo.cs" } + UpdateAssemblyInfoFileName = new HashSet { Path.Combine("Project", "src", "Properties", "AssemblyInfo.cs") } }; using (new AssemblyInfoFileUpdate(args, workingDir, variable, fileSystem)) { - const string expected = @"AssemblyVersion(""2.3.0.0""); -AssemblyInformationalVersion(""2.3.1+3.Branch.foo.Sha.hash""); -AssemblyFileVersion(""2.3.1.0"");"; - fileSystem.Received().WriteAllText("C:\\Testing\\Project\\src\\Properties\\AssemblyInfo.cs", expected); + string expected = Join(@"AssemblyVersion(""2.3.0.0"");", + @"AssemblyInformationalVersion(""2.3.1+3.Branch.foo.Sha.hash"");", + @"AssemblyFileVersion(""2.3.1.0"");"); + fileSystem.Received().WriteAllText(fileName, expected); } } @@ -264,13 +273,14 @@ public void ShouldReplaceAssemblyVersionWithStar() Patch = 1 }; - const string workingDir = "C:\\Testing"; - const string assemblyInfoFile = @"AssemblyVersion(""1.0.0.*""); -AssemblyInformationalVersion(""1.0.0.*""); -AssemblyFileVersion(""1.0.0.*"");"; + var workingDir = Path.GetTempPath(); + string assemblyInfoFile = Join(@"AssemblyVersion(""1.0.0.*"");", + @"AssemblyInformationalVersion(""1.0.0.*"");", + @"AssemblyFileVersion(""1.0.0.*"");"); - fileSystem.Exists("C:\\Testing\\AssemblyInfo.cs").Returns(true); - fileSystem.ReadAllText("C:\\Testing\\AssemblyInfo.cs").Returns(assemblyInfoFile); + var fileName = Path.Combine(workingDir, "AssemblyInfo.cs"); + fileSystem.Exists(fileName).Returns(true); + fileSystem.ReadAllText(fileName).Returns(assemblyInfoFile); var config = new TestEffectiveConfiguration(assemblyVersioningScheme: AssemblyVersioningScheme.MajorMinor); var variable = VariableProvider.GetVariablesFor(version, config, false); @@ -281,10 +291,10 @@ public void ShouldReplaceAssemblyVersionWithStar() }; using (new AssemblyInfoFileUpdate(args, workingDir, variable, fileSystem)) { - const string expected = @"AssemblyVersion(""2.3.0.0""); -AssemblyInformationalVersion(""2.3.1+3.Branch.foo.Sha.hash""); -AssemblyFileVersion(""2.3.1.0"");"; - fileSystem.Received().WriteAllText("C:\\Testing\\AssemblyInfo.cs", expected); + string expected = Join(@"AssemblyVersion(""2.3.0.0"");", + @"AssemblyInformationalVersion(""2.3.1+3.Branch.foo.Sha.hash"");", + @"AssemblyFileVersion(""2.3.1.0"");"); + fileSystem.Received().WriteAllText(fileName, expected); } } @@ -300,11 +310,12 @@ public void ShouldAddAssemblyVersionIfMissingFromInfoFile() Patch = 1 }; - const string workingDir = "C:\\Testing"; - const string assemblyInfoFileContent = @""; + var workingDir = Path.GetTempPath(); + const string assemblyInfoFileContent = ""; - fileSystem.Exists("C:\\Testing\\AssemblyInfo.cs").Returns(true); - fileSystem.ReadAllText("C:\\Testing\\AssemblyInfo.cs").Returns(assemblyInfoFileContent); + var fileName = Path.Combine(workingDir, "AssemblyInfo.cs"); + fileSystem.Exists(fileName).Returns(true); + fileSystem.ReadAllText(fileName).Returns(assemblyInfoFileContent); var config = new TestEffectiveConfiguration(assemblyVersioningScheme: AssemblyVersioningScheme.MajorMinor); @@ -317,11 +328,10 @@ public void ShouldAddAssemblyVersionIfMissingFromInfoFile() using (new AssemblyInfoFileUpdate(args, workingDir, variable, fileSystem)) { - const string expected = @" -[assembly: AssemblyVersion(""2.3.0.0"")] -[assembly: AssemblyInformationalVersion(""2.3.1+3.Branch.foo.Sha.hash"")] -[assembly: AssemblyFileVersion(""2.3.1.0"")]"; - fileSystem.Received().WriteAllText("C:\\Testing\\AssemblyInfo.cs", expected); + string expected = Join("", @"[assembly: AssemblyVersion(""2.3.0.0"")]", + @"[assembly: AssemblyInformationalVersion(""2.3.1+3.Branch.foo.Sha.hash"")]", + @"[assembly: AssemblyFileVersion(""2.3.1.0"")]"); + fileSystem.Received().WriteAllText(fileName, expected); } } @@ -336,13 +346,14 @@ [Test] public void ShouldReplaceAlreadySubstitutedValues() Patch = 1 }; - const string workingDir = "C:\\Testing"; - const string assemblyInfoFile = @"AssemblyVersion(""2.2.0.0""); -AssemblyInformationalVersion(""2.2.0+5.Branch.foo.Sha.hash""); -AssemblyFileVersion(""2.2.0.0"");"; + var workingDir = Path.GetTempPath(); + string assemblyInfoFile = Join(@"AssemblyVersion(""2.2.0.0"");", + @"AssemblyInformationalVersion(""2.2.0+5.Branch.foo.Sha.hash"");", + @"AssemblyFileVersion(""2.2.0.0"");"); - fileSystem.Exists("C:\\Testing\\AssemblyInfo.cs").Returns(true); - fileSystem.ReadAllText("C:\\Testing\\AssemblyInfo.cs").Returns(assemblyInfoFile); + var fileName = Path.Combine(workingDir, "AssemblyInfo.cs"); + fileSystem.Exists(fileName).Returns(true); + fileSystem.ReadAllText(fileName).Returns(assemblyInfoFile); var config = new TestEffectiveConfiguration(assemblyVersioningScheme: AssemblyVersioningScheme.MajorMinor); var variable = VariableProvider.GetVariablesFor(version, config, false); @@ -353,10 +364,10 @@ [Test] public void ShouldReplaceAlreadySubstitutedValues() }; using (new AssemblyInfoFileUpdate(args, workingDir, variable, fileSystem)) { - const string expected = @"AssemblyVersion(""2.3.0.0""); -AssemblyInformationalVersion(""2.3.1+3.Branch.foo.Sha.hash""); -AssemblyFileVersion(""2.3.1.0"");"; - fileSystem.Received().WriteAllText("C:\\Testing\\AssemblyInfo.cs", expected); + string expected = Join(@"AssemblyVersion(""2.3.0.0"");", + @"AssemblyInformationalVersion(""2.3.1+3.Branch.foo.Sha.hash"");", + @"AssemblyFileVersion(""2.3.1.0"");"); + fileSystem.Received().WriteAllText(fileName, expected); } } @@ -373,12 +384,13 @@ public void ShouldReplaceAssemblyVersionWhenCreatingCSharpAssemblyVersionFileAnd Patch = 1 }; - const string workingDir = "C:\\Testing"; - const string assemblyInfoFile = @"AssemblyVersion(""1.0.0.0""); -AssemblyInformationalVersion(""1.0.0.0""); -AssemblyFileVersion(""1.0.0.0"");"; + var workingDir = Path.GetTempPath(); + string assemblyInfoFile = Join(@"AssemblyVersion(""1.0.0.0"");", + @"AssemblyInformationalVersion(""1.0.0.0"");", + @"AssemblyFileVersion(""1.0.0.0"");"); - fileSystem.WriteAllText("C:\\Testing\\AssemblyInfo.cs", assemblyInfoFile); + var fileName = Path.Combine(workingDir, "AssemblyInfo.cs"); + fileSystem.WriteAllText(fileName, assemblyInfoFile); var variable = VariableProvider.GetVariablesFor(version, new TestEffectiveConfiguration(), false); var args = new Arguments { @@ -388,10 +400,10 @@ public void ShouldReplaceAssemblyVersionWhenCreatingCSharpAssemblyVersionFileAnd }; using (new AssemblyInfoFileUpdate(args, workingDir, variable, fileSystem)) { - const string expected = @"AssemblyVersion(""2.3.1.0""); -AssemblyInformationalVersion(""2.3.1+3.Branch.foo.Sha.hash""); -AssemblyFileVersion(""2.3.1.0"");"; - fileSystem.ReadAllText("C:\\Testing\\AssemblyInfo.cs").ShouldBe(expected); + string expected = Join(@"AssemblyVersion(""2.3.1.0"");", + @"AssemblyInformationalVersion(""2.3.1+3.Branch.foo.Sha.hash"");", + @"AssemblyFileVersion(""2.3.1.0"");"); + fileSystem.ReadAllText(fileName).ShouldBe(expected); } } @@ -407,12 +419,13 @@ public void ShouldReplaceAssemblyVersionWhenCreatingFSharpAssemblyVersionFileAnd Patch = 1 }; - const string workingDir = "C:\\Testing"; - const string assemblyInfoFile = @"AssemblyVersion(""1.0.0.0""); -AssemblyInformationalVersion(""1.0.0.0""); -AssemblyFileVersion(""1.0.0.0"");"; + var workingDir = Path.GetTempPath(); + string assemblyInfoFile = Join(@"AssemblyVersion(""1.0.0.0"");", + @"AssemblyInformationalVersion(""1.0.0.0"");", + @"AssemblyFileVersion(""1.0.0.0"");"); - fileSystem.WriteAllText("C:\\Testing\\AssemblyInfo.fs", assemblyInfoFile); + var fileName = Path.Combine(workingDir, "AssemblyInfo.fs"); + fileSystem.WriteAllText(fileName, assemblyInfoFile); var variable = VariableProvider.GetVariablesFor(version, new TestEffectiveConfiguration(), false); var args = new Arguments { @@ -422,10 +435,10 @@ public void ShouldReplaceAssemblyVersionWhenCreatingFSharpAssemblyVersionFileAnd }; using (new AssemblyInfoFileUpdate(args, workingDir, variable, fileSystem)) { - const string expected = @"AssemblyVersion(""2.3.1.0""); -AssemblyInformationalVersion(""2.3.1+3.Branch.foo.Sha.hash""); -AssemblyFileVersion(""2.3.1.0"");"; - fileSystem.ReadAllText("C:\\Testing\\AssemblyInfo.fs").ShouldBe(expected); + string expected = Join(@"AssemblyVersion(""2.3.1.0"");", + @"AssemblyInformationalVersion(""2.3.1+3.Branch.foo.Sha.hash"");", + @"AssemblyFileVersion(""2.3.1.0"");"); + fileSystem.ReadAllText(fileName).ShouldBe(expected); } } @@ -441,12 +454,13 @@ public void ShouldReplaceAssemblyVersionWhenCreatingVisualBasicAssemblyVersionFi Patch = 1 }; - const string workingDir = "C:\\Testing"; - const string assemblyInfoFile = @"AssemblyVersion(""1.0.0.0""); -AssemblyInformationalVersion(""1.0.0.0""); -AssemblyFileVersion(""1.0.0.0"");"; - - fileSystem.WriteAllText("C:\\Testing\\AssemblyInfo.vb", assemblyInfoFile); + var workingDir = Path.GetTempPath(); + string assemblyInfoFile = Join(@"AssemblyVersion(""1.0.0.0"");", + @"AssemblyInformationalVersion(""1.0.0.0"");", + @"AssemblyFileVersion(""1.0.0.0"");"); + + var fileName = Path.Combine(workingDir, "AssemblyInfo.vb"); + fileSystem.WriteAllText(fileName, assemblyInfoFile); var variable = VariableProvider.GetVariablesFor(version, new TestEffectiveConfiguration(), false); var args = new Arguments { @@ -456,10 +470,27 @@ public void ShouldReplaceAssemblyVersionWhenCreatingVisualBasicAssemblyVersionFi }; using (new AssemblyInfoFileUpdate(args, workingDir, variable, fileSystem)) { - const string expected = @"AssemblyVersion(""2.3.1.0""); -AssemblyInformationalVersion(""2.3.1+3.Branch.foo.Sha.hash""); -AssemblyFileVersion(""2.3.1.0"");"; - fileSystem.ReadAllText("C:\\Testing\\AssemblyInfo.vb").ShouldBe(expected); + string expected = Join(@"AssemblyVersion(""2.3.1.0"");", + @"AssemblyInformationalVersion(""2.3.1+3.Branch.foo.Sha.hash"");", + @"AssemblyFileVersion(""2.3.1.0"");"); + fileSystem.ReadAllText(fileName).ShouldBe(expected); + } + } + + + private static string Join(params string[] lines) + { + var sb = new StringBuilder(); + for (int i = 0; i < lines.Length; i++) + { + var line = lines[i]; + sb.Append(line); + + var lastLine = i == lines.Length - 1; + if (!lastLine) + sb.AppendLine(); } + + return sb.ToString(); } } From 96a8c98f6173f43c89fa55f57d5d1b691c3dd789 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Thu, 28 Apr 2016 12:28:59 +0200 Subject: [PATCH 13/36] Added NoMono category to tests failing on Mono --- src/GitVersionCore.Tests/ConfigProviderTests.cs | 2 ++ src/GitVersionCore.Tests/Init/InitScenarios.cs | 2 ++ src/GitVersionCore.Tests/JsonVersionBuilderTests.cs | 2 ++ src/GitVersionCore.Tests/VariableProviderTests.cs | 12 ++++++++++++ 4 files changed, 18 insertions(+) diff --git a/src/GitVersionCore.Tests/ConfigProviderTests.cs b/src/GitVersionCore.Tests/ConfigProviderTests.cs index 1d8c47616e..a9136a2bc7 100644 --- a/src/GitVersionCore.Tests/ConfigProviderTests.cs +++ b/src/GitVersionCore.Tests/ConfigProviderTests.cs @@ -147,6 +147,8 @@ public void NextVersionCanHavePatch() } [Test] + [Category("NoMono")] + [Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")] [MethodImpl(MethodImplOptions.NoInlining)] public void CanWriteOutEffectiveConfiguration() { diff --git a/src/GitVersionCore.Tests/Init/InitScenarios.cs b/src/GitVersionCore.Tests/Init/InitScenarios.cs index 737a2b92cf..9584dc49cc 100644 --- a/src/GitVersionCore.Tests/Init/InitScenarios.cs +++ b/src/GitVersionCore.Tests/Init/InitScenarios.cs @@ -12,6 +12,8 @@ public class InitScenarios { [Test] + [Category("NoMono")] + [Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")] public void CanSetNextVersion() { var testFileSystem = new TestFileSystem(); diff --git a/src/GitVersionCore.Tests/JsonVersionBuilderTests.cs b/src/GitVersionCore.Tests/JsonVersionBuilderTests.cs index 150c046464..601b25d89c 100644 --- a/src/GitVersionCore.Tests/JsonVersionBuilderTests.cs +++ b/src/GitVersionCore.Tests/JsonVersionBuilderTests.cs @@ -8,6 +8,8 @@ public class JsonVersionBuilderTests { [Test] + [Category("NoMono")] + [Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")] public void Json() { var semanticVersion = new SemanticVersion diff --git a/src/GitVersionCore.Tests/VariableProviderTests.cs b/src/GitVersionCore.Tests/VariableProviderTests.cs index eddd0ada61..cbb6ba9473 100644 --- a/src/GitVersionCore.Tests/VariableProviderTests.cs +++ b/src/GitVersionCore.Tests/VariableProviderTests.cs @@ -8,6 +8,8 @@ public class VariableProviderTests { [Test] + [Category("NoMono")] + [Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")] public void ProvidesVariablesInContinuousDeliveryModeForPreRelease() { var semVer = new SemanticVersion @@ -31,6 +33,8 @@ public void ProvidesVariablesInContinuousDeliveryModeForPreRelease() } [Test] + [Category("NoMono")] + [Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")] public void ProvidesVariablesInContinuousDeliveryModeForPreReleaseWithPadding() { var semVer = new SemanticVersion @@ -54,6 +58,8 @@ public void ProvidesVariablesInContinuousDeliveryModeForPreReleaseWithPadding() } [Test] + [Category("NoMono")] + [Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")] public void ProvidesVariablesInContinuousDeploymentModeForPreRelease() { var semVer = new SemanticVersion @@ -76,6 +82,8 @@ public void ProvidesVariablesInContinuousDeploymentModeForPreRelease() } [Test] + [Category("NoMono")] + [Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")] public void ProvidesVariablesInContinuousDeliveryModeForStable() { var semVer = new SemanticVersion @@ -97,6 +105,8 @@ public void ProvidesVariablesInContinuousDeliveryModeForStable() } [Test] + [Category("NoMono")] + [Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")] public void ProvidesVariablesInContinuousDeploymentModeForStable() { var semVer = new SemanticVersion @@ -118,6 +128,8 @@ public void ProvidesVariablesInContinuousDeploymentModeForStable() } [Test] + [Category("NoMono")] + [Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")] public void ProvidesVariablesInContinuousDeploymentModeForStableWhenCurrentCommitIsTagged() { var semVer = new SemanticVersion From 0f275de9d2c381a67e80ae87b2702fe01c0215e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Thu, 28 Apr 2016 13:00:12 +0200 Subject: [PATCH 14/36] Output nuget version number --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index a6db03268c..84e77898ef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: csharp solution: src/GitVersion.sln sudo: true install: + - nuget help - sudo nuget update -self - nuget restore src/GitVersion.sln - nuget install NUnit.Runners -Version 3.2.1 -OutputDirectory ./src/packages From dcb75f825aed0c61015000f122c8a221e8d4c1ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Thu, 28 Apr 2016 13:07:06 +0200 Subject: [PATCH 15/36] Ignore compiler warning CS0414 --- src/GitVersionTask.Tests/GitVersionTask.Tests.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/GitVersionTask.Tests/GitVersionTask.Tests.csproj b/src/GitVersionTask.Tests/GitVersionTask.Tests.csproj index dd5485232d..cd18a03860 100644 --- a/src/GitVersionTask.Tests/GitVersionTask.Tests.csproj +++ b/src/GitVersionTask.Tests/GitVersionTask.Tests.csproj @@ -27,6 +27,7 @@ prompt 4 false + 414 full From 032caa9a96214a39eb5b93e8c66068f8e680b90b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Thu, 28 Apr 2016 13:43:59 +0200 Subject: [PATCH 16/36] Send output to the Console for easier debugging --- src/GitVersionCore.Tests/ExecuteCoreTests.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/GitVersionCore.Tests/ExecuteCoreTests.cs b/src/GitVersionCore.Tests/ExecuteCoreTests.cs index 528c75cf82..c4fe65020e 100644 --- a/src/GitVersionCore.Tests/ExecuteCoreTests.cs +++ b/src/GitVersionCore.Tests/ExecuteCoreTests.cs @@ -4,9 +4,7 @@ using GitTools.Testing; using GitVersion; using GitVersion.Helpers; - using NUnit.Framework; - using Shouldly; [TestFixture] @@ -107,7 +105,7 @@ public void ConfigChangeInvalidatesCache() fileSystem.WriteAllText(vv.FileName, versionCacheFileContent); vv = versionAndBranchFinder.ExecuteGitVersion(null, null, null, null, false, fixture.RepositoryPath, null); vv.AssemblySemVer.ShouldBe("4.10.3.0"); - + var configPath = Path.Combine(fixture.RepositoryPath, "GitVersionConfig.yaml"); fileSystem.WriteAllText(configPath, "next-version: 5.0"); @@ -121,10 +119,14 @@ string RepositoryScope(ExecuteCore executeCore = null, Action infoLogger = s => { infoBuilder.AppendLine(s); }; + Action infoLogger = s => + { + infoBuilder.AppendLine(s); + Console.WriteLine(s); + }; executeCore = executeCore ?? new ExecuteCore(fileSystem); - Logger.SetLoggers(infoLogger, s => { }, s => { }); + Logger.SetLoggers(infoLogger, Console.WriteLine, Console.WriteLine); using (var fixture = new EmptyRepositoryFixture()) { From 5a8519d6ca85a9c68edcef7ead500786577b10d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Thu, 28 Apr 2016 13:44:35 +0200 Subject: [PATCH 17/36] Use Path.DirectorySeparatorChar instead of backslash --- src/GitVersionCore/LibGitExtensions.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GitVersionCore/LibGitExtensions.cs b/src/GitVersionCore/LibGitExtensions.cs index 5d459a0a96..aaddd582a9 100644 --- a/src/GitVersionCore/LibGitExtensions.cs +++ b/src/GitVersionCore/LibGitExtensions.cs @@ -187,12 +187,12 @@ public static string GetRepositoryDirectory(this IRepository repository, bool om { var gitDirectory = repository.Info.Path; - gitDirectory = gitDirectory.TrimEnd('\\'); + gitDirectory = gitDirectory.TrimEnd(Path.DirectorySeparatorChar); if (omitGitPostFix && gitDirectory.EndsWith(".git")) { gitDirectory = gitDirectory.Substring(0, gitDirectory.Length - ".git".Length); - gitDirectory = gitDirectory.TrimEnd('\\'); + gitDirectory = gitDirectory.TrimEnd(Path.DirectorySeparatorChar); } return gitDirectory; From cbb3d1b6084256046389194834d97ef43c68bd5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Thu, 28 Apr 2016 14:35:44 +0200 Subject: [PATCH 18/36] Reduced test to the bare minimum --- src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs b/src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs index 3820242765..0b1b865642 100644 --- a/src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs +++ b/src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs @@ -39,22 +39,10 @@ public void InvalidArgumentsExitCodeShouldNotBeZero() { using (var fixture = new EmptyRepositoryFixture()) { - fixture.MakeATaggedCommit("1.2.3"); - fixture.MakeACommit(); - - var buildFile = Path.Combine(fixture.RepositoryPath, "RunExecViaCommandLine.proj"); - File.Delete(buildFile); - const string buildFileContent = @" - - - - -"; - File.WriteAllText(buildFile, buildFileContent); var result = GitVersionHelper.ExecuteIn(fixture.RepositoryPath, arguments: " /invalid-argument"); result.ExitCode.ShouldBe(1); - result.Output.ShouldContain("Failed to parse arguments"); + result.Output.ShouldContain("Could not parse command line parameter '/invalid-argument'"); } } } \ No newline at end of file From 0bf16729d2ff3ba9f0a45cd98d8179b82adf05e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Thu, 28 Apr 2016 17:01:45 +0200 Subject: [PATCH 19/36] More informative exceptions from Logger --- src/GitVersionCore/Logger.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/GitVersionCore/Logger.cs b/src/GitVersionCore/Logger.cs index 573fedfb17..f3a1eddd3f 100644 --- a/src/GitVersionCore/Logger.cs +++ b/src/GitVersionCore/Logger.cs @@ -59,9 +59,9 @@ static Action LogMessage(Action logAction, string level) public static void Reset() { - WriteInfo = s => { throw new Exception("Logger not defined."); }; - WriteWarning = s => { throw new Exception("Logger not defined."); }; - WriteError = s => { throw new Exception("Logger not defined."); }; + WriteInfo = s => { throw new Exception("Info logger not defined. Attempted to log: " + s); }; + WriteWarning = s => { throw new Exception("Warning logger not defined. Attempted to log: " + s); }; + WriteError = s => { throw new Exception("Error logger not defined. Attempted to log: " + s); }; } class ActionDisposable : IDisposable From 8df7cf8b442380f0f46311fc640fcbbb1cdd6a2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Thu, 28 Apr 2016 17:05:05 +0200 Subject: [PATCH 20/36] Don't write to the error log before it's configured. --- src/GitVersionExe/Program.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/GitVersionExe/Program.cs b/src/GitVersionExe/Program.cs index 56b15f31f0..e9198d827f 100644 --- a/src/GitVersionExe/Program.cs +++ b/src/GitVersionExe/Program.cs @@ -127,6 +127,7 @@ static void ConfigureLogging(Arguments arguments) writeActions.Add(Console.WriteLine); } + Exception exception = null; if (arguments.LogFilePath != null && arguments.LogFilePath != "console") { try @@ -148,7 +149,7 @@ static void ConfigureLogging(Arguments arguments) } catch (Exception ex) { - Logger.WriteError(String.Format("Failed to configure logging for '{0}': {1}", arguments.LogFilePath, ex.Message)); + exception = ex; } } @@ -156,6 +157,9 @@ static void ConfigureLogging(Arguments arguments) s => writeActions.ForEach(a => a(s)), s => writeActions.ForEach(a => a(s)), s => writeActions.ForEach(a => a(s))); + + if (exception != null) + Logger.WriteError(string.Format("Failed to configure logging for '{0}': {1}", arguments.LogFilePath, exception.Message)); } static void WriteLogEntry(Arguments arguments, string s) From 87495e3272f38b765a4ea581352ec1c3fe2f154e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Thu, 28 Apr 2016 17:08:59 +0200 Subject: [PATCH 21/36] Added support for forward slashes (unix paths) in command line arguments --- .../ArgumentParserTests.cs | 7 ++++++ .../ExecCmdLineArgumentTest.cs | 15 +++++++++++ src/GitVersionExe/ArgumentParser.cs | 25 ++++++++++++++++--- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/GitVersionExe.Tests/ArgumentParserTests.cs b/src/GitVersionExe.Tests/ArgumentParserTests.cs index 41ff0ac875..6e8b277668 100644 --- a/src/GitVersionExe.Tests/ArgumentParserTests.cs +++ b/src/GitVersionExe.Tests/ArgumentParserTests.cs @@ -284,4 +284,11 @@ public void other_arguments_can_be_parsed_after_nofetch() arguments.NoFetch = true; arguments.Proj = "foo.sln"; } + + [Test] + public void log_path_can_contain_forward_slash() + { + var arguments = ArgumentParser.ParseArguments("-l /some/path"); + arguments.LogFilePath.ShouldBe("/some/path"); + } } \ No newline at end of file diff --git a/src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs b/src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs index 0b1b865642..835c349fea 100644 --- a/src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs +++ b/src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs @@ -45,4 +45,19 @@ public void InvalidArgumentsExitCodeShouldNotBeZero() result.Output.ShouldContain("Could not parse command line parameter '/invalid-argument'"); } } + + [Test] + public void LogPathContainsForwardSlash() + { + using (var fixture = new EmptyRepositoryFixture()) + { + fixture.MakeATaggedCommit("1.2.3"); + fixture.MakeACommit(); + + var result = GitVersionHelper.ExecuteIn(fixture.RepositoryPath, arguments: @" /l ""/some/path""", logToFile: false); + + result.ExitCode.ShouldBe(0); + result.Output.ShouldContain(@"""MajorMinorPatch"":""1.2.4"""); + } + } } \ No newline at end of file diff --git a/src/GitVersionExe/ArgumentParser.cs b/src/GitVersionExe/ArgumentParser.cs index e2e5061142..ff3fced2af 100644 --- a/src/GitVersionExe/ArgumentParser.cs +++ b/src/GitVersionExe/ArgumentParser.cs @@ -316,13 +316,15 @@ static NameValueCollection CollectSwitchesAndValuesFromArguments(List na var args = new NameValueCollection(); string currentKey = null; + var isBooleanArgument = true; for (var index = 0; index < namedArguments.Count; index = index + 1) { var arg = namedArguments[index]; - //If this is a switch, create new name/value entry for it, with a null value. - if (IsSwitchArgument(arg)) + // If the current (previous) argument doesn't require a parameter and this is a switch, create new name/value entry for it, with a null value. + if (isBooleanArgument && IsSwitchArgument(arg)) { currentKey = arg; + isBooleanArgument = IsBooleanArgument(arg); args.Add(currentKey, null); } //If this is a value (not a switch) @@ -338,6 +340,9 @@ static NameValueCollection CollectSwitchesAndValuesFromArguments(List na { args.Add(currentKey, arg); } + + // Reset the boolean argument flag so the next argument won't be ignored. + isBooleanArgument = true; } } return args; @@ -345,7 +350,8 @@ static NameValueCollection CollectSwitchesAndValuesFromArguments(List na static bool IsSwitchArgument(string value) { - return value != null && (value.StartsWith("-") || value.StartsWith("/")) + return value != null + && (value.StartsWith("-") || value.StartsWith("/")) && !Regex.Match(value, @"/\w+:").Success; //Exclude msbuild & project parameters in form /blah:, which should be parsed as values, not switch names. } @@ -376,5 +382,18 @@ static bool IsHelp(string singleArgument) IsSwitch("help", singleArgument) || IsSwitch("?", singleArgument); } + + static bool IsBooleanArgument(string switchName) + { + var booleanArguments = new[] + { + "init", + "updateassemblyinfo", + "ensureassemblyinfo", + "nofetch" + }; + + return booleanArguments.Contains(switchName, StringComparer.OrdinalIgnoreCase); + } } } \ No newline at end of file From 2422660d185c10da9c27427d75c41f3d1fe9a07b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Thu, 28 Apr 2016 17:35:35 +0200 Subject: [PATCH 22/36] Add runtime switch between MSBuild and xbuild --- src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs | 6 ++---- src/GitVersionExe/SpecifiedArgumentRunner.cs | 11 +++++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs b/src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs index 835c349fea..ff28697d63 100644 --- a/src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs +++ b/src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs @@ -1,14 +1,12 @@ using System.IO; using GitTools.Testing; +using GitVersion; using NUnit.Framework; using Shouldly; [TestFixture] public class ExecCmdLineArgumentTest { - const string MsBuild = @"c:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe"; - - [Test] public void RunExecViaCommandLine() { @@ -26,7 +24,7 @@ public void RunExecViaCommandLine() "; File.WriteAllText(buildFile, buildFileContent); - var result = GitVersionHelper.ExecuteIn(fixture.RepositoryPath, MsBuild, "RunExecViaCommandLine.proj /target:OutputResults"); + var result = GitVersionHelper.ExecuteIn(fixture.RepositoryPath, SpecifiedArgumentRunner.BuildTool, "RunExecViaCommandLine.proj /target:OutputResults"); result.ExitCode.ShouldBe(0); result.Log.ShouldContain("GitVersion_FullSemVer: 1.2.4+1"); diff --git a/src/GitVersionExe/SpecifiedArgumentRunner.cs b/src/GitVersionExe/SpecifiedArgumentRunner.cs index ea810816d7..ce966a56fb 100644 --- a/src/GitVersionExe/SpecifiedArgumentRunner.cs +++ b/src/GitVersionExe/SpecifiedArgumentRunner.cs @@ -9,10 +9,13 @@ namespace GitVersion class SpecifiedArgumentRunner { - const string MsBuild = @"c:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe"; + private static readonly bool runningOnMono = Type.GetType("Mono.Runtime") != null; + public static readonly string BuildTool = runningOnMono? "xbuild" : @"c:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe"; public static void Run(Arguments arguments, IFileSystem fileSystem) { + Logger.WriteInfo(string.Format("Running on {0}.", runningOnMono ? "Mono" : "Windows")); + var noFetch = arguments.NoFetch; var authentication = arguments.Authentication; var targetPath = arguments.TargetPath; @@ -74,14 +77,14 @@ static bool RunMsBuildIfNeeded(Arguments args, string workingDirectory, VersionV { if (string.IsNullOrEmpty(args.Proj)) return false; - Logger.WriteInfo(string.Format("Launching {0} \"{1}\" {2}", MsBuild, args.Proj, args.ProjArgs)); + Logger.WriteInfo(string.Format("Launching build tool {0} \"{1}\" {2}", BuildTool, args.Proj, args.ProjArgs)); var results = ProcessHelper.Run( Logger.WriteInfo, Logger.WriteError, - null, MsBuild, string.Format("\"{0}\" {1}", args.Proj, args.ProjArgs), workingDirectory, + null, BuildTool, string.Format("\"{0}\" {1}", args.Proj, args.ProjArgs), workingDirectory, GetEnvironmentalVariables(variables)); if (results != 0) - throw new WarningException("MsBuild execution failed, non-zero return code"); + throw new WarningException(string.Format("{0} execution failed, non-zero return code", runningOnMono ? "XBuild" : "MSBuild")); return true; } From c2794d0662f02da61c3fa95f924cd33e889d99db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Thu, 28 Apr 2016 17:43:01 +0200 Subject: [PATCH 23/36] Move the test step to after_script --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 84e77898ef..cebacc2d80 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,4 +8,5 @@ install: - nuget install NUnit.Runners -Version 3.2.1 -OutputDirectory ./src/packages script: - xbuild "./src/GitVersion.sln" /property:Configuration="Debug" /verbosity:detailed +after_script: - mono --debug --runtime=v4.0.30319 ./src/packages/NUnit.ConsoleRunner.3.2.1/tools/nunit3-console.exe ./src/GitVersionTask.Tests/bin/Debug/GitVersionTask.Tests.dll ./src/GitVersionCore.Tests/bin/Debug/GitVersionCore.Tests.dll ./src/GitVersionTask.Tests/bin/Debug/GitVersionTask.Tests.dll ./src/GitVersionExe.Tests/bin/Debug/GitVersionExe.Tests.dll -where "cat != NoMono" From 5c16c0873f97891074d302ec68e26d9b809da4f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Thu, 28 Apr 2016 17:50:08 +0200 Subject: [PATCH 24/36] Let's try without sudo again. --- .travis.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index cebacc2d80..8aaa44811a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,8 @@ language: csharp solution: src/GitVersion.sln -sudo: true +sudo: false install: - - nuget help - - sudo nuget update -self + - nuget ? - nuget restore src/GitVersion.sln - nuget install NUnit.Runners -Version 3.2.1 -OutputDirectory ./src/packages script: From 897925e8e00668ac4787379310be0897a77585bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Thu, 28 Apr 2016 17:57:49 +0200 Subject: [PATCH 25/36] Remove System.* as NuGet references --- src/GitVersionTask.Tests/packages.config | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/GitVersionTask.Tests/packages.config b/src/GitVersionTask.Tests/packages.config index 62ed7e0001..6b0c979b5d 100644 --- a/src/GitVersionTask.Tests/packages.config +++ b/src/GitVersionTask.Tests/packages.config @@ -18,21 +18,4 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file From 4d6ea92af60cc42506462748a470075fa7726dbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Thu, 28 Apr 2016 18:07:06 +0200 Subject: [PATCH 26/36] Upgrade Microsoft.CodeAnalysis.* from v1.0.0 to v1.2.1 and with that, reintroduce the NuGet dependencies to System.* --- .../GitVersionTask.Tests.csproj | 23 +++++++++++-------- src/GitVersionTask.Tests/packages.config | 18 +++++++++++---- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/GitVersionTask.Tests/GitVersionTask.Tests.csproj b/src/GitVersionTask.Tests/GitVersionTask.Tests.csproj index cd18a03860..43bbe69bbf 100644 --- a/src/GitVersionTask.Tests/GitVersionTask.Tests.csproj +++ b/src/GitVersionTask.Tests/GitVersionTask.Tests.csproj @@ -66,16 +66,16 @@ - - ..\packages\Microsoft.CodeAnalysis.Common.1.0.0\lib\net45\Microsoft.CodeAnalysis.dll + + ..\packages\Microsoft.CodeAnalysis.Common.1.2.1\lib\net45\Microsoft.CodeAnalysis.dll True - - ..\packages\Microsoft.CodeAnalysis.CSharp.1.0.0\lib\net45\Microsoft.CodeAnalysis.CSharp.dll + + ..\packages\Microsoft.CodeAnalysis.CSharp.1.2.1\lib\net45\Microsoft.CodeAnalysis.CSharp.dll True - - ..\packages\Microsoft.CodeAnalysis.VisualBasic.1.0.0\lib\net45\Microsoft.CodeAnalysis.VisualBasic.dll + + ..\packages\Microsoft.CodeAnalysis.VisualBasic.1.2.1\lib\net45\Microsoft.CodeAnalysis.VisualBasic.dll True @@ -117,12 +117,12 @@ - ..\packages\System.Collections.Immutable.1.1.37\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll + ..\packages\System.Collections.Immutable.1.1.37\lib\dotnet\System.Collections.Immutable.dll True - - ..\packages\System.Reflection.Metadata.1.0.22\lib\portable-net45+win8\System.Reflection.Metadata.dll + + ..\packages\System.Reflection.Metadata.1.2.0\lib\portable-net45+win8\System.Reflection.Metadata.dll True @@ -180,7 +180,10 @@ - + + + + diff --git a/src/GitVersionTask.Tests/packages.config b/src/GitVersionTask.Tests/packages.config index 6b0c979b5d..296e4c0e55 100644 --- a/src/GitVersionTask.Tests/packages.config +++ b/src/GitVersionTask.Tests/packages.config @@ -7,10 +7,10 @@ - - - - + + + + @@ -18,4 +18,14 @@ + + + + + + + + + + \ No newline at end of file From d9b1cfbacd3f422845dcd4faa0596dc297eabe67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Thu, 28 Apr 2016 18:08:07 +0200 Subject: [PATCH 27/36] Bring back sudo and nuget self update --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8aaa44811a..bf4291a5b2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ language: csharp solution: src/GitVersion.sln -sudo: false +sudo: true install: - - nuget ? + - sudo nuget update -self - nuget restore src/GitVersion.sln - nuget install NUnit.Runners -Version 3.2.1 -OutputDirectory ./src/packages script: From 6e975479dda064c2800bb45b8acc07deba37ce29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Thu, 28 Apr 2016 18:21:26 +0200 Subject: [PATCH 28/36] Kill sudo after updating nuget --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index bf4291a5b2..edd3889785 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ solution: src/GitVersion.sln sudo: true install: - sudo nuget update -self + - sudo -k - nuget restore src/GitVersion.sln - nuget install NUnit.Runners -Version 3.2.1 -OutputDirectory ./src/packages script: From 370047c1c8a9c5f3931f660da2f73412d524548a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Thu, 28 Apr 2016 18:25:17 +0200 Subject: [PATCH 29/36] Let's try to sudo nuget restore, then. --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index edd3889785..8bbd366de5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,7 @@ solution: src/GitVersion.sln sudo: true install: - sudo nuget update -self - - sudo -k - - nuget restore src/GitVersion.sln + - sudo nuget restore src/GitVersion.sln - nuget install NUnit.Runners -Version 3.2.1 -OutputDirectory ./src/packages script: - xbuild "./src/GitVersion.sln" /property:Configuration="Debug" /verbosity:detailed From eb979f6f6689170184973e494e9c8bab4cbbf654 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Thu, 28 Apr 2016 18:37:32 +0200 Subject: [PATCH 30/36] More verbosity, please. --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8bbd366de5..ec91ce8305 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,11 @@ language: csharp solution: src/GitVersion.sln sudo: true +before_install: + - nuget install: - sudo nuget update -self - - sudo nuget restore src/GitVersion.sln + - sudo nuget restore src/GitVersion.sln -SolutionDirectory src -Verbosity detailed - nuget install NUnit.Runners -Version 3.2.1 -OutputDirectory ./src/packages script: - xbuild "./src/GitVersion.sln" /property:Configuration="Debug" /verbosity:detailed From d0c711f2f030e93b119587e3154c497f1c8a182c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Fri, 29 Apr 2016 13:08:09 +0200 Subject: [PATCH 31/36] Define nuget version 3.4.3 as an addon --- .travis.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index ec91ce8305..33986e9e7a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,12 @@ language: csharp solution: src/GitVersion.sln -sudo: true +sudo: false +addons: + nuget: 3.4.3 before_install: - nuget install: - - sudo nuget update -self - - sudo nuget restore src/GitVersion.sln -SolutionDirectory src -Verbosity detailed + - nuget restore src/GitVersion.sln -SolutionDirectory src -Verbosity detailed - nuget install NUnit.Runners -Version 3.2.1 -OutputDirectory ./src/packages script: - xbuild "./src/GitVersion.sln" /property:Configuration="Debug" /verbosity:detailed From 2bd45c14cf31f7182edeed21497eec75bf59b818 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Fri, 29 Apr 2016 13:25:28 +0200 Subject: [PATCH 32/36] Removed SolutionDirectory parameter for nuget restore --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 33986e9e7a..a222d6c246 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ addons: before_install: - nuget install: - - nuget restore src/GitVersion.sln -SolutionDirectory src -Verbosity detailed + - nuget restore src/GitVersion.sln -Verbosity detailed - nuget install NUnit.Runners -Version 3.2.1 -OutputDirectory ./src/packages script: - xbuild "./src/GitVersion.sln" /property:Configuration="Debug" /verbosity:detailed From bbadec9e52d7289736f334cd50458043cbf197cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Fri, 29 Apr 2016 13:29:16 +0200 Subject: [PATCH 33/36] Be explicit about the nuget addon source --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a222d6c246..ca3af07a96 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,9 @@ language: csharp solution: src/GitVersion.sln sudo: false addons: - nuget: 3.4.3 + apt: + packages: + - nuget: 3.4.3 before_install: - nuget install: From 3b25ad64e0f664578b36960b938a17f90f462770 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Fri, 29 Apr 2016 13:37:20 +0200 Subject: [PATCH 34/36] Download custom nuget.exe and use that --- .travis.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index ca3af07a96..2edbc57a38 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,14 @@ language: csharp solution: src/GitVersion.sln sudo: false -addons: - apt: - packages: - - nuget: 3.4.3 before_install: - - nuget + - mkdir -p .nuget + - wget -O .nuget/nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe + - chmod +x .nuget/nuget.exe + - .nuget/nuget.exe install: - - nuget restore src/GitVersion.sln -Verbosity detailed - - nuget install NUnit.Runners -Version 3.2.1 -OutputDirectory ./src/packages + - .nuget/nuget.exe restore src/GitVersion.sln -Verbosity detailed + - .nuget/nuget.exe install NUnit.Runners -Version 3.2.1 -OutputDirectory ./src/packages script: - xbuild "./src/GitVersion.sln" /property:Configuration="Debug" /verbosity:detailed after_script: From 6ad0eace41394d0e9860d1542d913cd4ebb9830b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Fri, 29 Apr 2016 13:47:13 +0200 Subject: [PATCH 35/36] Need to exeucte .exe files with Mono, of course --- .travis.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2edbc57a38..2801a7cd30 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,11 +4,10 @@ sudo: false before_install: - mkdir -p .nuget - wget -O .nuget/nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe - - chmod +x .nuget/nuget.exe - - .nuget/nuget.exe + - mono .nuget/nuget.exe install: - - .nuget/nuget.exe restore src/GitVersion.sln -Verbosity detailed - - .nuget/nuget.exe install NUnit.Runners -Version 3.2.1 -OutputDirectory ./src/packages + - mono .nuget/nuget.exe restore src/GitVersion.sln -Verbosity detailed + - mono .nuget/nuget.exe install NUnit.Runners -Version 3.2.1 -OutputDirectory ./src/packages script: - xbuild "./src/GitVersion.sln" /property:Configuration="Debug" /verbosity:detailed after_script: From 991aaca29fbcd26d67ff53a474c4012871afea1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Fri, 29 Apr 2016 13:59:13 +0200 Subject: [PATCH 36/36] Added comment regarding the odd nuget.exe download --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 2801a7cd30..eafa63b00d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: csharp solution: src/GitVersion.sln sudo: false -before_install: +before_install: # We need to download nuget.exe due to: https://github.com/travis-ci/travis-ci/issues/5932 - mkdir -p .nuget - wget -O .nuget/nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe - mono .nuget/nuget.exe