From 4c8c8eb5c152353e83fd254d7cee6a8269eadef1 Mon Sep 17 00:00:00 2001 From: Artur Stolear Date: Tue, 12 Feb 2019 12:44:23 +0000 Subject: [PATCH] Removed GitTools.Core dependency Included only the classes/methods from GitTools.Core --- src/Directory.Build.props | 2 +- .../AssemblyInfoFileUpdaterTests.cs | 5 +- src/GitVersionCore.Tests/CommitDateTests.cs | 4 +- .../ConfigProviderTests.cs | 1 - .../GitRepoMetadataProviderTests.cs | 5 +- .../GitToolsTestingExtensions.cs | 5 +- .../GitVersionCore.Tests.csproj | 3 +- .../GitVersionInformationGeneratorTests.cs | 6 +- .../IntegrationTests/DocumentationSamples.cs | 6 +- .../IntegrationTests/PullRequestScenarios.cs | 4 +- .../RemoteRepositoryScenarios.cs | 7 +- .../NextVersionCalculatorTests.cs | 5 +- src/GitVersionCore/Authentication.cs | 2 +- src/GitVersionCore/AuthenticationInfo.cs | 27 ++ src/GitVersionCore/Configuration/Config.cs | 5 +- .../Configuration/ConfigurationProvider.cs | 1 - .../Configuration/LegacyConfig.cs | 1 - .../Configuration/TypeHelper.cs | 30 -- src/GitVersionCore/Exceptions/BugException.cs | 11 + .../Exceptions/GitToolsException.cs | 18 ++ .../{ => Exceptions}/GitVersionException.cs | 6 +- .../Exceptions/WarningException.cs | 13 + src/GitVersionCore/ExecuteCore.cs | 9 +- .../Extensions/ExtensionMethods.cs | 2 +- src/GitVersionCore/GitPreparer.cs | 7 +- src/GitVersionCore/GitVersionCache.cs | 1 - src/GitVersionCore/GitVersionCore.csproj | 6 +- src/GitVersionCore/GitVersionFinder.cs | 5 +- src/GitVersionCore/Helpers/DeleteHelper.cs | 4 +- .../Helpers/GitRepositoryHelper.cs | 306 ++++++++++++++++++ src/GitVersionCore/Helpers/ProcessHelper.cs | 212 ++++++++++++ src/GitVersionCore/Helpers/ThreadSleep.cs | 2 +- src/GitVersionCore/LibGitExtensions.cs | 57 +++- src/GitVersionCore/Logger.cs | 9 +- src/GitVersionCore/LoggerWrapper.cs | 84 ----- src/GitVersionCore/MergeMessage.cs | 3 +- .../OutputVariables/VariableProvider.cs | 5 +- .../OutputVariables/VersionVariables.cs | 3 +- src/GitVersionCore/SemanticVersion.cs | 6 +- .../DevelopVersionStrategy.cs | 3 +- .../ArgumentParserTests.cs | 3 +- .../ExecCmdLineArgumentTest.cs | 6 +- .../GitVersionExe.Tests.csproj | 3 +- src/GitVersionExe.Tests/GitVersionHelper.cs | 2 +- src/GitVersionExe/ArgumentParser.cs | 3 +- src/GitVersionExe/GitVersionExe.csproj | 1 - src/GitVersionExe/Program.cs | 5 +- src/GitVersionExe/SpecifiedArgumentRunner.cs | 4 +- .../GitVersionTask.Tests.csproj | 1 - .../InvalidFileCheckerTests.cs | 6 +- src/GitVersionTask.Tests/packages.config | 31 -- .../GenerateGitVersionInformation.cs | 8 +- src/GitVersionTask/GetVersion.cs | 6 +- src/GitVersionTask/GitVersionTask.csproj | 7 +- src/GitVersionTask/InvalidFileChecker.cs | 4 +- .../NugetAssets/GitVersionTask.nuspec | 2 +- src/GitVersionTask/UpdateAssemblyInfo.cs | 6 +- .../WriteVersionInfoToBuildLog.cs | 5 +- 58 files changed, 719 insertions(+), 275 deletions(-) create mode 100644 src/GitVersionCore/AuthenticationInfo.cs delete mode 100644 src/GitVersionCore/Configuration/TypeHelper.cs create mode 100644 src/GitVersionCore/Exceptions/BugException.cs create mode 100644 src/GitVersionCore/Exceptions/GitToolsException.cs rename src/GitVersionCore/{ => Exceptions}/GitVersionException.cs (88%) create mode 100644 src/GitVersionCore/Exceptions/WarningException.cs create mode 100644 src/GitVersionCore/Helpers/GitRepositoryHelper.cs create mode 100644 src/GitVersionCore/Helpers/ProcessHelper.cs delete mode 100644 src/GitVersionCore/LoggerWrapper.cs delete mode 100644 src/GitVersionTask.Tests/packages.config diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 61f3c79f0a..a3f93b1514 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -14,7 +14,7 @@ - 1.3.1 + 0.25.0-preview-0033 [1.0.185] 2018.3.0 5.3.0 diff --git a/src/GitVersionCore.Tests/AssemblyInfoFileUpdaterTests.cs b/src/GitVersionCore.Tests/AssemblyInfoFileUpdaterTests.cs index 06158160ce..f78515c563 100644 --- a/src/GitVersionCore.Tests/AssemblyInfoFileUpdaterTests.cs +++ b/src/GitVersionCore.Tests/AssemblyInfoFileUpdaterTests.cs @@ -1,7 +1,6 @@ -using System; +using System; using System.Collections.Generic; using System.IO; -using System.Linq; using GitVersion; using GitVersion.Helpers; using GitVersionCore.Tests; @@ -482,4 +481,4 @@ public void ShouldNotAddAssemblyInformationalVersionWhenUpdatingAssemblyVersionF verify(fileSystem, variables); } -} \ No newline at end of file +} diff --git a/src/GitVersionCore.Tests/CommitDateTests.cs b/src/GitVersionCore.Tests/CommitDateTests.cs index c5db74ff53..541b362903 100644 --- a/src/GitVersionCore.Tests/CommitDateTests.cs +++ b/src/GitVersionCore.Tests/CommitDateTests.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections; -using System.Collections.Generic; +using System; using System.Linq; using GitVersion; using GitVersion.VersionFilters; diff --git a/src/GitVersionCore.Tests/ConfigProviderTests.cs b/src/GitVersionCore.Tests/ConfigProviderTests.cs index 035d4d15b6..576fcef00e 100644 --- a/src/GitVersionCore.Tests/ConfigProviderTests.cs +++ b/src/GitVersionCore.Tests/ConfigProviderTests.cs @@ -1,4 +1,3 @@ -using GitTools; using GitVersion; using GitVersion.Helpers; using GitVersionCore.Tests; diff --git a/src/GitVersionCore.Tests/GitRepoMetadataProviderTests.cs b/src/GitVersionCore.Tests/GitRepoMetadataProviderTests.cs index aa247383f0..0b18a30918 100644 --- a/src/GitVersionCore.Tests/GitRepoMetadataProviderTests.cs +++ b/src/GitVersionCore.Tests/GitRepoMetadataProviderTests.cs @@ -1,7 +1,6 @@ -namespace GitVersionCore.Tests +namespace GitVersionCore.Tests { using System; - using GitTools; using GitTools.Testing; using GitVersion; using NUnit.Framework; @@ -197,4 +196,4 @@ public void FindsCorrectMergeBaseForMultipleForwardMerges() } } } -} \ No newline at end of file +} diff --git a/src/GitVersionCore.Tests/GitToolsTestingExtensions.cs b/src/GitVersionCore.Tests/GitToolsTestingExtensions.cs index 930f71d9c9..dba18257e1 100644 --- a/src/GitVersionCore.Tests/GitToolsTestingExtensions.cs +++ b/src/GitVersionCore.Tests/GitToolsTestingExtensions.cs @@ -1,7 +1,6 @@ -namespace GitVersionCore.Tests +namespace GitVersionCore.Tests { using System; - using GitTools; using GitTools.Testing; using GitVersion; using LibGit2Sharp; @@ -77,4 +76,4 @@ public static void InitialiseRepo(this RemoteRepositoryFixture fixture) new GitPreparer(null, null, new Authentication(), false, fixture.LocalRepositoryFixture.RepositoryPath).Initialise(true, null); } } -} \ No newline at end of file +} diff --git a/src/GitVersionCore.Tests/GitVersionCore.Tests.csproj b/src/GitVersionCore.Tests/GitVersionCore.Tests.csproj index e2d49e5155..07f2b9c921 100644 --- a/src/GitVersionCore.Tests/GitVersionCore.Tests.csproj +++ b/src/GitVersionCore.Tests/GitVersionCore.Tests.csproj @@ -1,4 +1,4 @@ - + net461 @@ -13,7 +13,6 @@ - diff --git a/src/GitVersionCore.Tests/GitVersionInformationGeneratorTests.cs b/src/GitVersionCore.Tests/GitVersionInformationGeneratorTests.cs index fb1bc3b66a..a534e0b0c6 100644 --- a/src/GitVersionCore.Tests/GitVersionInformationGeneratorTests.cs +++ b/src/GitVersionCore.Tests/GitVersionInformationGeneratorTests.cs @@ -1,9 +1,5 @@ -using System; -using System.Collections.Generic; +using System; using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using GitVersion; using NUnit.Framework; using Shouldly; diff --git a/src/GitVersionCore.Tests/IntegrationTests/DocumentationSamples.cs b/src/GitVersionCore.Tests/IntegrationTests/DocumentationSamples.cs index ed834cbd8d..2b8dbc90f7 100644 --- a/src/GitVersionCore.Tests/IntegrationTests/DocumentationSamples.cs +++ b/src/GitVersionCore.Tests/IntegrationTests/DocumentationSamples.cs @@ -1,6 +1,6 @@ -using System; -using GitTools; +using System; using GitTools.Testing; +using GitVersion; using GitVersionCore.Tests; using NUnit.Framework; using Shouldly; @@ -423,4 +423,4 @@ public void GitHubFlowMajorRelease() fixture.AssertFullSemver("2.0.1+1"); } } -} \ No newline at end of file +} diff --git a/src/GitVersionCore.Tests/IntegrationTests/PullRequestScenarios.cs b/src/GitVersionCore.Tests/IntegrationTests/PullRequestScenarios.cs index 558233eed3..6bfd403a15 100644 --- a/src/GitVersionCore.Tests/IntegrationTests/PullRequestScenarios.cs +++ b/src/GitVersionCore.Tests/IntegrationTests/PullRequestScenarios.cs @@ -1,5 +1,5 @@ -using GitTools; using GitTools.Testing; +using GitVersion; using GitVersionCore.Tests; using LibGit2Sharp; using NUnit.Framework; @@ -109,4 +109,4 @@ public void CalculatesCorrectVersionAfterReleaseBranchMergedToMaster() fixture.AssertFullSemver("2.0.0-PullRequest0002.0"); } } -} \ No newline at end of file +} diff --git a/src/GitVersionCore.Tests/IntegrationTests/RemoteRepositoryScenarios.cs b/src/GitVersionCore.Tests/IntegrationTests/RemoteRepositoryScenarios.cs index 1812a8a475..3aeca901d4 100644 --- a/src/GitVersionCore.Tests/IntegrationTests/RemoteRepositoryScenarios.cs +++ b/src/GitVersionCore.Tests/IntegrationTests/RemoteRepositoryScenarios.cs @@ -1,11 +1,10 @@ -using System; -using GitTools.Git; +using System; using GitTools.Testing; +using GitVersion; using GitVersionCore.Tests; using LibGit2Sharp; using NUnit.Framework; using Shouldly; -using GitTools; [TestFixture] public class RemoteRepositoryScenarios : TestBase @@ -87,4 +86,4 @@ public void GivenARemoteGitRepositoryWhenCheckingOutDetachedhead_UsingTrackingBr fixture.AssertFullSemver("0.1.0+4", fixture.LocalRepositoryFixture.Repository); } } -} \ No newline at end of file +} diff --git a/src/GitVersionCore.Tests/VersionCalculation/NextVersionCalculatorTests.cs b/src/GitVersionCore.Tests/VersionCalculation/NextVersionCalculatorTests.cs index ec567f32d9..ffdcd5308b 100644 --- a/src/GitVersionCore.Tests/VersionCalculation/NextVersionCalculatorTests.cs +++ b/src/GitVersionCore.Tests/VersionCalculation/NextVersionCalculatorTests.cs @@ -1,8 +1,7 @@ -namespace GitVersionCore.Tests.VersionCalculation +namespace GitVersionCore.Tests.VersionCalculation { using System; using System.Collections.Generic; - using GitTools; using GitTools.Testing; using GitVersion; using GitVersion.VersionCalculation; @@ -152,4 +151,4 @@ public void PreReleaseNumberShouldBeScopeToPreReleaseLabelInContinuousDelivery() } } } -} \ No newline at end of file +} diff --git a/src/GitVersionCore/Authentication.cs b/src/GitVersionCore/Authentication.cs index df366489de..b8d7d4d7ba 100644 --- a/src/GitVersionCore/Authentication.cs +++ b/src/GitVersionCore/Authentication.cs @@ -12,4 +12,4 @@ public Authentication() public string Username; public string Password; } -} \ No newline at end of file +} diff --git a/src/GitVersionCore/AuthenticationInfo.cs b/src/GitVersionCore/AuthenticationInfo.cs new file mode 100644 index 0000000000..634dfa991e --- /dev/null +++ b/src/GitVersionCore/AuthenticationInfo.cs @@ -0,0 +1,27 @@ +namespace GitVersion +{ + using LibGit2Sharp; + + public class AuthenticationInfo + { + public string Username { get; set; } + public string Password { get; set; } + public string Token { get; set; } + + public FetchOptions ToFetchOptions() + { + var fetchOptions = new FetchOptions(); + + if (!string.IsNullOrEmpty(Username)) + { + fetchOptions.CredentialsProvider = (url, user, types) => new UsernamePasswordCredentials + { + Username = Username, + Password = Password + }; + } + + return fetchOptions; + } + } +} \ No newline at end of file diff --git a/src/GitVersionCore/Configuration/Config.cs b/src/GitVersionCore/Configuration/Config.cs index 8225df969f..ba2481d5d6 100644 --- a/src/GitVersionCore/Configuration/Config.cs +++ b/src/GitVersionCore/Configuration/Config.cs @@ -1,10 +1,9 @@ -namespace GitVersion +namespace GitVersion { using System; using System.Collections.Generic; using System.Globalization; using System.Linq; - using System.Reflection; using System.Text.RegularExpressions; using YamlDotNet.Serialization; @@ -145,4 +144,4 @@ T MergeObjects(T target, T source) [YamlMember(Alias = "commit-date-format")] public string CommitDateFormat { get; set; } } -} \ No newline at end of file +} diff --git a/src/GitVersionCore/Configuration/ConfigurationProvider.cs b/src/GitVersionCore/Configuration/ConfigurationProvider.cs index d0fc3b8d96..796ecc9424 100644 --- a/src/GitVersionCore/Configuration/ConfigurationProvider.cs +++ b/src/GitVersionCore/Configuration/ConfigurationProvider.cs @@ -6,7 +6,6 @@ namespace GitVersion using System.IO; using System.Linq; using System.Text; - using WarningException = GitTools.WarningException; public class ConfigurationProvider { diff --git a/src/GitVersionCore/Configuration/LegacyConfig.cs b/src/GitVersionCore/Configuration/LegacyConfig.cs index abc46debd3..d6cde67898 100644 --- a/src/GitVersionCore/Configuration/LegacyConfig.cs +++ b/src/GitVersionCore/Configuration/LegacyConfig.cs @@ -3,7 +3,6 @@ namespace GitVersion using System.Collections.Generic; using System.Linq; using YamlDotNet.Serialization; - using System.Reflection; /// /// Obsolete properties are added to this, so we can check to see if they are used and provide good error messages for migration diff --git a/src/GitVersionCore/Configuration/TypeHelper.cs b/src/GitVersionCore/Configuration/TypeHelper.cs deleted file mode 100644 index b94e68f8b0..0000000000 --- a/src/GitVersionCore/Configuration/TypeHelper.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Reflection; - -//public static class TypeHelper -//{ -//#if NETDESKTOP -// public static Type GetType() -// { -// return GetType(); -// } -//#else -// public static TypeInfo GetType() -// { -// return GetType(); -// } -//#endif - -//#if NETDESKTOP -// public static IEnumerable GetConstructorsForType() -// { -// return GetType().GetConstructors(); -// } -//#else -// public static IEnumerable GetConstructorsForType() -// { -// return GetType().DeclaredConstructors; -// } -//#endif -//} diff --git a/src/GitVersionCore/Exceptions/BugException.cs b/src/GitVersionCore/Exceptions/BugException.cs new file mode 100644 index 0000000000..46651fa053 --- /dev/null +++ b/src/GitVersionCore/Exceptions/BugException.cs @@ -0,0 +1,11 @@ +namespace GitVersion +{ + using System; + + public class BugException : Exception + { + public BugException(string message) : base(message) + { + } + } +} \ No newline at end of file diff --git a/src/GitVersionCore/Exceptions/GitToolsException.cs b/src/GitVersionCore/Exceptions/GitToolsException.cs new file mode 100644 index 0000000000..5f563b5246 --- /dev/null +++ b/src/GitVersionCore/Exceptions/GitToolsException.cs @@ -0,0 +1,18 @@ +namespace GitVersion +{ + using System; + + [Serializable] + public class GitToolsException : Exception + { + public GitToolsException(string messageFormat, params object[] args) + : base(string.Format(messageFormat, args)) + { + } + + public GitToolsException(string message, Exception innerException) + : base(message, innerException) + { + } + } +} \ No newline at end of file diff --git a/src/GitVersionCore/GitVersionException.cs b/src/GitVersionCore/Exceptions/GitVersionException.cs similarity index 88% rename from src/GitVersionCore/GitVersionException.cs rename to src/GitVersionCore/Exceptions/GitVersionException.cs index b6afb92952..dfbd50332c 100644 --- a/src/GitVersionCore/GitVersionException.cs +++ b/src/GitVersionCore/Exceptions/GitVersionException.cs @@ -1,9 +1,7 @@ -namespace GitVersion +namespace GitVersion { using System; - using GitTools; - [Serializable] public class GitVersionException : GitToolsException { @@ -18,4 +16,4 @@ public GitVersionException(string message, Exception innerException) { } } -} \ No newline at end of file +} diff --git a/src/GitVersionCore/Exceptions/WarningException.cs b/src/GitVersionCore/Exceptions/WarningException.cs new file mode 100644 index 0000000000..362ef336b4 --- /dev/null +++ b/src/GitVersionCore/Exceptions/WarningException.cs @@ -0,0 +1,13 @@ +namespace GitVersion +{ + using System; + + [Serializable] + public class WarningException : Exception + { + public WarningException(string message) + : base(message) + { + } + } +} \ No newline at end of file diff --git a/src/GitVersionCore/ExecuteCore.cs b/src/GitVersionCore/ExecuteCore.cs index 1080721420..9610798196 100644 --- a/src/GitVersionCore/ExecuteCore.cs +++ b/src/GitVersionCore/ExecuteCore.cs @@ -1,12 +1,9 @@ namespace GitVersion { - using GitTools; using GitVersion.Helpers; using LibGit2Sharp; using System; - using System.ComponentModel; using System.Linq; - using System.Threading.Tasks; public class ExecuteCore { @@ -126,7 +123,7 @@ IRepository GetRepository(string gitDirectory) var branch = repository.Head; if (branch.Tip == null) { - throw new GitTools.WarningException("No Tip found. Has repo been initialized?"); + throw new WarningException("No Tip found. Has repo been initialized?"); } return repository; } @@ -134,10 +131,10 @@ IRepository GetRepository(string gitDirectory) { if (exception.Message.Contains("LibGit2Sharp.Core.NativeMethods") || exception.Message.Contains("FilePathMarshaler")) { - throw new GitTools.WarningException("Restart of the process may be required to load an updated version of LibGit2Sharp."); + throw new WarningException("Restart of the process may be required to load an updated version of LibGit2Sharp."); } throw; } } } -} \ No newline at end of file +} diff --git a/src/GitVersionCore/Extensions/ExtensionMethods.cs b/src/GitVersionCore/Extensions/ExtensionMethods.cs index 8e09abf928..db4d4942e8 100644 --- a/src/GitVersionCore/Extensions/ExtensionMethods.cs +++ b/src/GitVersionCore/Extensions/ExtensionMethods.cs @@ -39,4 +39,4 @@ public static T OnlyOrDefault(this IEnumerable source) return default(T); } } -} \ No newline at end of file +} diff --git a/src/GitVersionCore/GitPreparer.cs b/src/GitVersionCore/GitPreparer.cs index 919340889f..4e17ed644e 100644 --- a/src/GitVersionCore/GitPreparer.cs +++ b/src/GitVersionCore/GitPreparer.cs @@ -3,8 +3,6 @@ namespace GitVersion using System; using System.IO; using System.Linq; - using GitTools.Git; - using GitTools.Logging; using LibGit2Sharp; public class GitPreparer @@ -31,9 +29,6 @@ public GitPreparer(string targetUrl, string dynamicRepositoryLocation, Authentic }; this.noFetch = noFetch; this.targetPath = targetPath.TrimEnd('/', '\\'); - - // GitTools has its own logging. So that it actually outputs something, it needs to be initialized. - LogProvider.SetCurrentLogProvider(new LoggerWrapper()); } public string TargetUrl @@ -266,4 +261,4 @@ static void CloneRepository(string repositoryUrl, string gitDirectory, Authentic } } } -} \ No newline at end of file +} diff --git a/src/GitVersionCore/GitVersionCache.cs b/src/GitVersionCore/GitVersionCache.cs index d7d1783a37..e2b16dc871 100644 --- a/src/GitVersionCore/GitVersionCache.cs +++ b/src/GitVersionCore/GitVersionCache.cs @@ -5,7 +5,6 @@ namespace GitVersion using System.Collections.Generic; using System.IO; using System.Linq; - using System.Threading.Tasks; using YamlDotNet.Serialization; public class GitVersionCache diff --git a/src/GitVersionCore/GitVersionCore.csproj b/src/GitVersionCore/GitVersionCore.csproj index 73e13b5ef7..b7b2d3f3c3 100644 --- a/src/GitVersionCore/GitVersionCore.csproj +++ b/src/GitVersionCore/GitVersionCore.csproj @@ -1,4 +1,4 @@ - + net461;netstandard2.0 @@ -19,10 +19,10 @@ - + + - diff --git a/src/GitVersionCore/GitVersionFinder.cs b/src/GitVersionCore/GitVersionFinder.cs index 4cf9d37170..053f8abf1c 100644 --- a/src/GitVersionCore/GitVersionFinder.cs +++ b/src/GitVersionCore/GitVersionFinder.cs @@ -2,7 +2,6 @@ namespace GitVersion { using System.IO; using GitVersion.VersionCalculation; - using GitTools; public class GitVersionFinder { @@ -22,7 +21,7 @@ public SemanticVersion FindVersion(GitVersionContext context) var filePath = Path.Combine(context.Repository.GetRepositoryDirectory(), "NextVersion.txt"); if (File.Exists(filePath)) { - throw new GitTools.WarningException("NextVersion.txt has been deprecated. See http://gitversion.readthedocs.org/en/latest/configuration/ for replacement"); + throw new WarningException("NextVersion.txt has been deprecated. See http://gitversion.readthedocs.org/en/latest/configuration/ for replacement"); } return new NextVersionCalculator().FindVersion(context); @@ -47,4 +46,4 @@ void EnsureHeadIsNotDetached(GitVersionContext context) throw new WarningException(message); } } -} \ No newline at end of file +} diff --git a/src/GitVersionCore/Helpers/DeleteHelper.cs b/src/GitVersionCore/Helpers/DeleteHelper.cs index 37888943d4..79312e2443 100644 --- a/src/GitVersionCore/Helpers/DeleteHelper.cs +++ b/src/GitVersionCore/Helpers/DeleteHelper.cs @@ -1,4 +1,4 @@ -namespace GitVersion +namespace GitVersion { using System.IO; @@ -24,4 +24,4 @@ public static void DeleteGitRepository(string directory) Directory.Delete(directory, true); } } -} \ No newline at end of file +} diff --git a/src/GitVersionCore/Helpers/GitRepositoryHelper.cs b/src/GitVersionCore/Helpers/GitRepositoryHelper.cs new file mode 100644 index 0000000000..137a767bde --- /dev/null +++ b/src/GitVersionCore/Helpers/GitRepositoryHelper.cs @@ -0,0 +1,306 @@ +namespace GitVersion +{ + using System; + using System.Collections.Generic; + using System.Linq; + using LibGit2Sharp; + + public static class GitRepositoryHelper + { + /// + /// Normalisation of a git directory turns all remote branches into local branches, turns pull request refs into a real branch and a few other things. This is designed to be run *only on the build server* which checks out repositories in different ways. + /// It is not recommended to run normalisation against a local repository + /// + public static void NormalizeGitDirectory(string gitDirectory, AuthenticationInfo authentication, bool noFetch, string currentBranch) + { + using (var repo = new Repository(gitDirectory)) + { + // Need to unsure the HEAD does not move, this is essentially a BugCheck + var expectedSha = repo.Head.Tip.Sha; + try + { + var remote = EnsureOnlyOneRemoteIsDefined(repo); + + AddMissingRefSpecs(repo, remote); + + //If noFetch is enabled, then GitVersion will assume that the git repository is normalized before execution, so that fetching from remotes is not required. + if (noFetch) + { + Logger.WriteInfo("Skipping fetching, if GitVersion does not calculate your version as expected you might need to allow fetching or use dynamic repositories"); + } + else + { + Fetch(authentication, remote, repo); + } + + EnsureLocalBranchExistsForCurrentBranch(repo, remote, currentBranch); + CreateOrUpdateLocalBranchesFromRemoteTrackingOnes(repo, remote.Name); + + var headSha = repo.Refs.Head.TargetIdentifier; + + if (!repo.Info.IsHeadDetached) + { + Logger.WriteInfo(string.Format("HEAD points at branch '{0}'.", headSha)); + return; + } + + Logger.WriteInfo(string.Format("HEAD is detached and points at commit '{0}'.", headSha)); + Logger.WriteInfo(string.Format("Local Refs:\r\n" + string.Join(Environment.NewLine, repo.Refs.FromGlob("*").Select(r => string.Format("{0} ({1})", r.CanonicalName, r.TargetIdentifier))))); + + // In order to decide whether a fake branch is required or not, first check to see if any local branches have the same commit SHA of the head SHA. + // If they do, go ahead and checkout that branch + // If no, go ahead and check out a new branch, using the known commit SHA as the pointer + var localBranchesWhereCommitShaIsHead = repo.Branches.Where(b => !b.IsRemote && b.Tip.Sha == headSha).ToList(); + + var matchingCurrentBranch = !string.IsNullOrEmpty(currentBranch) + ? localBranchesWhereCommitShaIsHead.SingleOrDefault(b => b.CanonicalName.Replace("/heads/", "/") == currentBranch.Replace("/heads/", "/")) + : null; + if (matchingCurrentBranch != null) + { + Logger.WriteInfo(string.Format("Checking out local branch '{0}'.", currentBranch)); + Commands.Checkout(repo, matchingCurrentBranch); + } + else if (localBranchesWhereCommitShaIsHead.Count > 1) + { + var branchNames = localBranchesWhereCommitShaIsHead.Select(r => r.CanonicalName); + var csvNames = string.Join(", ", branchNames); + const string moveBranchMsg = "Move one of the branches along a commit to remove warning"; + + Logger.WriteWarning(string.Format("Found more than one local branch pointing at the commit '{0}' ({1}).", headSha, csvNames)); + var master = localBranchesWhereCommitShaIsHead.SingleOrDefault(n => n.FriendlyName == "master"); + if (master != null) + { + Logger.WriteWarning("Because one of the branches is 'master', will build master." + moveBranchMsg); + Commands.Checkout(repo, master); + } + else + { + var branchesWithoutSeparators = localBranchesWhereCommitShaIsHead.Where(b => !b.FriendlyName.Contains('/') && !b.FriendlyName.Contains('-')).ToList(); + if (branchesWithoutSeparators.Count == 1) + { + var branchWithoutSeparator = branchesWithoutSeparators[0]; + Logger.WriteWarning(string.Format("Choosing {0} as it is the only branch without / or - in it. " + moveBranchMsg, branchWithoutSeparator.CanonicalName)); + Commands.Checkout(repo, branchWithoutSeparator); + } + else + { + throw new WarningException("Failed to try and guess branch to use. " + moveBranchMsg); + } + } + } + else if (localBranchesWhereCommitShaIsHead.Count == 0) + { + Logger.WriteInfo(string.Format("No local branch pointing at the commit '{0}'. Fake branch needs to be created.", headSha)); + CreateFakeBranchPointingAtThePullRequestTip(repo, authentication); + } + else + { + Logger.WriteInfo(string.Format("Checking out local branch 'refs/heads/{0}'.", localBranchesWhereCommitShaIsHead[0].FriendlyName)); + Commands.Checkout(repo, repo.Branches[localBranchesWhereCommitShaIsHead[0].FriendlyName]); + } + } + finally + { + if (repo.Head.Tip.Sha != expectedSha) + { + if (Environment.GetEnvironmentVariable("IGNORE_NORMALISATION_GIT_HEAD_MOVE") != "1") + { + // Whoa, HEAD has moved, it shouldn't have. We need to blow up because there is a bug in normalisation + throw new BugException(string.Format(@"GitVersion has a bug, your HEAD has moved after repo normalisation. + +To disable this error set an environmental variable called IGNORE_NORMALISATION_GIT_HEAD_MOVE to 1 + +Please run `git {0}` and submit it along with your build log (with personal info removed) in a new issue at https://github.com/GitTools/GitVersion", + CreateGitLogArgs(100))); + } + } + } + } + } + + public static string CreateGitLogArgs(int? maxCommits) + { + return @"log --graph --format=""%h %cr %d"" --decorate --date=relative --all --remotes=*" + (maxCommits != null ? string.Format(" -n {0}", maxCommits) : null); + } + + public static void Fetch(AuthenticationInfo authentication, Remote remote, Repository repo) + { + Logger.WriteInfo(string.Format("Fetching from remote '{0}' using the following refspecs: {1}.", + remote.Name, string.Join(", ", remote.FetchRefSpecs.Select(r => r.Specification)))); + Commands.Fetch(repo, remote.Name, new string[0], authentication.ToFetchOptions(), null); + } + + static void EnsureLocalBranchExistsForCurrentBranch(Repository repo, Remote remote, string currentBranch) + { + if (string.IsNullOrEmpty(currentBranch)) return; + + var isRef = currentBranch.Contains("refs"); + var isBranch = currentBranch.Contains("refs/heads"); + var localCanonicalName = !isRef ? "refs/heads/" + currentBranch : isBranch ? currentBranch : currentBranch.Replace("refs/", "refs/heads/"); + + var repoTip = repo.Head.Tip; + + // We currently have the rep.Head of the *default* branch, now we need to look up the right one + var originCanonicalName = string.Format("{0}/{1}", remote.Name, currentBranch); + var originBranch = repo.Branches[originCanonicalName]; + if (originBranch != null) + { + repoTip = originBranch.Tip; + } + + var repoTipId = repoTip.Id; + + if (repo.Branches.All(b => b.CanonicalName != localCanonicalName)) + { + Logger.WriteInfo(isBranch ? + string.Format("Creating local branch {0}", localCanonicalName) : + string.Format("Creating local branch {0} pointing at {1}", localCanonicalName, repoTipId)); + repo.Refs.Add(localCanonicalName, repoTipId); + } + else + { + Logger.WriteInfo(isBranch ? + string.Format("Updating local branch {0} to point at {1}", localCanonicalName, repoTip.Sha) : + string.Format("Updating local branch {0} to match ref {1}", localCanonicalName, currentBranch)); + repo.Refs.UpdateTarget(repo.Refs[localCanonicalName], repoTipId); + } + + Commands.Checkout(repo, localCanonicalName); + } + + static void AddMissingRefSpecs(Repository repo, Remote remote) + { + if (remote.FetchRefSpecs.Any(r => r.Source == "refs/heads/*")) + return; + + var allBranchesFetchRefSpec = string.Format("+refs/heads/*:refs/remotes/{0}/*", remote.Name); + + Logger.WriteInfo(string.Format("Adding refspec: {0}", allBranchesFetchRefSpec)); + + repo.Network.Remotes.Update(remote.Name, + r => r.FetchRefSpecs.Add(allBranchesFetchRefSpec)); + } + + static void CreateFakeBranchPointingAtThePullRequestTip(Repository repo, AuthenticationInfo authentication) + { + var remote = repo.Network.Remotes.Single(); + + Logger.WriteInfo("Fetching remote refs to see if there is a pull request ref"); + var remoteTips = (string.IsNullOrEmpty(authentication.Username) ? + GetRemoteTipsForAnonymousUser(repo, remote) : + GetRemoteTipsUsingUsernamePasswordCredentials(repo, remote, authentication.Username, authentication.Password)) + .ToList(); + + Logger.WriteInfo("Remote Refs:\r\n" + string.Join(Environment.NewLine, remoteTips.Select(r => r.CanonicalName))); + + var headTipSha = repo.Head.Tip.Sha; + + var refs = remoteTips.Where(r => r.TargetIdentifier == headTipSha).ToList(); + + if (refs.Count == 0) + { + var message = string.Format("Couldn't find any remote tips from remote '{0}' pointing at the commit '{1}'.", remote.Url, headTipSha); + throw new WarningException(message); + } + + if (refs.Count > 1) + { + var names = string.Join(", ", refs.Select(r => r.CanonicalName)); + var message = string.Format("Found more than one remote tip from remote '{0}' pointing at the commit '{1}'. Unable to determine which one to use ({2}).", remote.Url, headTipSha, names); + throw new WarningException(message); + } + + var reference = refs[0]; + var canonicalName = reference.CanonicalName; + Logger.WriteInfo(string.Format("Found remote tip '{0}' pointing at the commit '{1}'.", canonicalName, headTipSha)); + + if (canonicalName.StartsWith("refs/tags")) + { + Logger.WriteInfo(string.Format("Checking out tag '{0}'", canonicalName)); + Commands.Checkout(repo, reference.Target.Sha); + return; + } + + if (!canonicalName.StartsWith("refs/pull/") && !canonicalName.StartsWith("refs/pull-requests/")) + { + var message = string.Format("Remote tip '{0}' from remote '{1}' doesn't look like a valid pull request.", canonicalName, remote.Url); + throw new WarningException(message); + } + + var fakeBranchName = canonicalName.Replace("refs/pull/", "refs/heads/pull/").Replace("refs/pull-requests/", "refs/heads/pull-requests/"); + + Logger.WriteInfo(string.Format("Creating fake local branch '{0}'.", fakeBranchName)); + repo.Refs.Add(fakeBranchName, new ObjectId(headTipSha)); + + Logger.WriteInfo(string.Format("Checking local branch '{0}' out.", fakeBranchName)); + Commands.Checkout(repo, fakeBranchName); + } + + static IEnumerable GetRemoteTipsUsingUsernamePasswordCredentials(Repository repo, Remote remote, string username, string password) + { + return repo.Network.ListReferences(remote, (url, fromUrl, types) => new UsernamePasswordCredentials + { + Username = username, + Password = password + }).Select(r => r.ResolveToDirectReference()); + } + + static IEnumerable GetRemoteTipsForAnonymousUser(Repository repo, Remote remote) + { + return repo.Network.ListReferences(remote).Select(r => r.ResolveToDirectReference()); + } + + static void CreateOrUpdateLocalBranchesFromRemoteTrackingOnes(Repository repo, string remoteName) + { + var prefix = string.Format("refs/remotes/{0}/", remoteName); + var remoteHeadCanonicalName = string.Format("{0}{1}", prefix, "HEAD"); + + foreach (var remoteTrackingReference in repo.Refs.FromGlob(prefix + "*").Where(r => r.CanonicalName != remoteHeadCanonicalName)) + { + var remoteTrackingReferenceName = remoteTrackingReference.CanonicalName; + var branchName = remoteTrackingReferenceName.Substring(prefix.Length); + var localCanonicalName = "refs/heads/" + branchName; + + // We do not want to touch our current branch + if (branchName == repo.Head.FriendlyName) continue; + + if (repo.Refs.Any(x => x.CanonicalName == localCanonicalName)) + { + var localRef = repo.Refs[localCanonicalName]; + var remotedirectReference = remoteTrackingReference.ResolveToDirectReference(); + if (localRef.ResolveToDirectReference().TargetIdentifier == remotedirectReference.TargetIdentifier) + { + Logger.WriteInfo(string.Format("Skipping update of '{0}' as it already matches the remote ref.", remoteTrackingReference.CanonicalName)); + continue; + } + var remoteRefTipId = remotedirectReference.Target.Id; + Logger.WriteInfo(string.Format("Updating local ref '{0}' to point at {1}.", localRef.CanonicalName, remoteRefTipId)); + repo.Refs.UpdateTarget(localRef, remoteRefTipId); + continue; + } + + Logger.WriteInfo(string.Format("Creating local branch from remote tracking '{0}'.", remoteTrackingReference.CanonicalName)); + repo.Refs.Add(localCanonicalName, new ObjectId(remoteTrackingReference.ResolveToDirectReference().TargetIdentifier), true); + + var branch = repo.Branches[branchName]; + repo.Branches.Update(branch, b => b.TrackedBranch = remoteTrackingReferenceName); + } + } + + public static Remote EnsureOnlyOneRemoteIsDefined(IRepository repo) + { + var remotes = repo.Network.Remotes; + var howMany = remotes.Count(); + + if (howMany == 1) + { + var remote = remotes.Single(); + Logger.WriteInfo(string.Format("One remote found ({0} -> '{1}').", remote.Name, remote.Url)); + return remote; + } + + var message = string.Format("{0} remote(s) have been detected. When being run on a build server, the Git repository is expected to bear one (and no more than one) remote.", howMany); + throw new WarningException(message); + } + } +} diff --git a/src/GitVersionCore/Helpers/ProcessHelper.cs b/src/GitVersionCore/Helpers/ProcessHelper.cs new file mode 100644 index 0000000000..005323b664 --- /dev/null +++ b/src/GitVersionCore/Helpers/ProcessHelper.cs @@ -0,0 +1,212 @@ +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) + { + switch ((NativeErrorCode)exception.NativeErrorCode) + { + case NativeErrorCode.Success: + // Success is not a failure. + break; + + case NativeErrorCode.FileNotFound: + throw new FileNotFoundException(string.Format("The executable file '{0}' could not be found.", + startInfo.FileName), + startInfo.FileName, + exception); + + case NativeErrorCode.PathNotFound: + throw new DirectoryNotFoundException(string.Format("The path to the executable file '{0}' could not be found.", + startInfo.FileName), + exception); + } + + throw; + } + + try + { + if (process != null) + { + process.PriorityClass = ProcessPriorityClass.Idle; + } + } + catch + { + // NOTE: It seems like in some situations, setting the priority class will throw a Win32Exception + // with the error code set to "Success", which I think we can safely interpret as a success and + // not an exception. + // + // See: https://travis-ci.org/GitTools/GitVersion/jobs/171288284#L2026 + // And: https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382.aspx + // + // There's also the case where the process might be killed before we try to adjust its priority + // class, in which case it will throw an InvalidOperationException. What we ideally should do + // is start the process in a "suspended" state, adjust the priority class, then resume it, but + // that's not possible in pure .NET. + // + // See: https://travis-ci.org/GitTools/GitVersion/jobs/166709203#L2278 + // And: http://www.codeproject.com/Articles/230005/Launch-a-process-suspended + // + // -- @asbjornu + } + } + } + + 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; + + 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; + } + } + + /// + /// System error codes. + /// See: https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382.aspx + /// + private enum NativeErrorCode + { + Success = 0x0, + FileNotFound = 0x2, + PathNotFound = 0x3 + } + + [Flags] + public enum ErrorModes + { + Default = 0x0, + FailCriticalErrors = 0x1, + NoGpFaultErrorBox = 0x2, + NoAlignmentFaultExcept = 0x4, + NoOpenFileErrorBox = 0x8000 + } + + public struct ChangeErrorMode : IDisposable + { + readonly int oldMode; + + public ChangeErrorMode(ErrorModes mode) + { + try + { + oldMode = SetErrorMode((int)mode); + } + catch (EntryPointNotFoundException) + { + oldMode = (int)mode; + } + } + + + void IDisposable.Dispose() + { + try + { + SetErrorMode(oldMode); + } + catch (EntryPointNotFoundException) + { + // NOTE: Mono doesn't support DllImport("kernel32.dll") and its SetErrorMode method, obviously. @asbjornu + } + } + + [DllImport("kernel32.dll")] + static extern int SetErrorMode(int newMode); + } + } +} \ No newline at end of file diff --git a/src/GitVersionCore/Helpers/ThreadSleep.cs b/src/GitVersionCore/Helpers/ThreadSleep.cs index 78bb4a66cf..6143521ad0 100644 --- a/src/GitVersionCore/Helpers/ThreadSleep.cs +++ b/src/GitVersionCore/Helpers/ThreadSleep.cs @@ -1,4 +1,4 @@ -namespace GitVersion.Helpers +namespace GitVersion.Helpers { using System.Threading.Tasks; diff --git a/src/GitVersionCore/LibGitExtensions.cs b/src/GitVersionCore/LibGitExtensions.cs index 8e339a43c1..711787d6af 100644 --- a/src/GitVersionCore/LibGitExtensions.cs +++ b/src/GitVersionCore/LibGitExtensions.cs @@ -4,10 +4,11 @@ namespace GitVersion using System.Collections.Generic; using System.IO; using System.Linq; - + using System.Text; + using GitVersion.Helpers; using LibGit2Sharp; - static class LibGitExtensions + public static class LibGitExtensions { public static DateTimeOffset When(this Commit commit) { @@ -127,5 +128,57 @@ public static void CheckoutFilesIfExist(this IRepository repository, params stri } } } + + public static Branch FindBranch(this IRepository repository, string branchName) + { + var exact = repository.Branches.FirstOrDefault(x => x.FriendlyName == branchName); + if (exact != null) + { + return exact; + } + + return repository.Branches.FirstOrDefault(x => x.FriendlyName == "origin/" + branchName); + } + + public static void DumpGraph(this IRepository repository, Action writer = null, int? maxCommits = null) + { + DumpGraph(repository.Info.Path, writer, maxCommits); + } + + + public static void DumpGraph(string workingDirectory, Action writer = null, int? maxCommits = null) + { + var output = new StringBuilder(); + + try + { + ProcessHelper.Run( + o => output.AppendLine(o), + e => output.AppendLineFormat("ERROR: {0}", e), + null, + "git", + GitRepositoryHelper.CreateGitLogArgs(maxCommits), + workingDirectory); + } + catch (FileNotFoundException exception) + { + if (exception.FileName != "git") + { + throw; + } + + output.AppendLine("Could not execute 'git log' due to the following error:"); + output.AppendLine(exception.ToString()); + } + + if (writer != null) + { + writer(output.ToString()); + } + else + { + Console.Write(output.ToString()); + } + } } } diff --git a/src/GitVersionCore/Logger.cs b/src/GitVersionCore/Logger.cs index 89c23d3804..3b4a99843e 100644 --- a/src/GitVersionCore/Logger.cs +++ b/src/GitVersionCore/Logger.cs @@ -33,12 +33,13 @@ public static IDisposable IndentLog(string operationDescription) static Action ObscurePassword(Action info) { - Action logAction = s => + void LogAction(string s) { s = ObscurePasswordRegex.Replace(s, "$1$2:*******@"); info(s); - }; - return logAction; + } + + return LogAction; } public static void SetLoggers(Action debug, Action info, Action warn, Action error) @@ -115,4 +116,4 @@ public void Dispose() } } } -} \ No newline at end of file +} diff --git a/src/GitVersionCore/LoggerWrapper.cs b/src/GitVersionCore/LoggerWrapper.cs deleted file mode 100644 index 5c4489dc26..0000000000 --- a/src/GitVersionCore/LoggerWrapper.cs +++ /dev/null @@ -1,84 +0,0 @@ -namespace GitVersion -{ - using System; - using GitTools.Logging; - - /// - /// Wraps the for use by GitTools. - /// - public class LoggerWrapper : ILogProvider - { - public GitTools.Logging.Logger GetLogger(string name) - { - return Log; - } - - public IDisposable OpenNestedContext(string message) - { - throw new NotImplementedException(); - } - - public IDisposable OpenMappedContext(string key, string value) - { - throw new NotImplementedException(); - } - - private static bool Log(LogLevel loglevel, Func messagefunc, Exception exception, object[] formatparameters) - { - // Create the main message. Careful of string format errors. - string message; - if (messagefunc == null) - { - message = null; - } - else - { - if (formatparameters == null || formatparameters.Length == 0) - { - message = messagefunc(); - } - else - { - try - { - message = string.Format(messagefunc(), formatparameters); - } - catch (FormatException) - { - message = messagefunc(); - Logger.WriteError(string.Format("LoggerWrapper.Log(): Incorrectly formatted string: message: '{0}'; formatparameters: {1}", message, string.Join(";", formatparameters))); - } - } - } - - if (exception != null) - { - // Append the exception to the end of the message. - message = string.IsNullOrEmpty(message) ? exception.ToString() : string.Format("{0}\n{1}", message, exception); - } - - if (!string.IsNullOrEmpty(message)) - { - switch (loglevel) - { - case LogLevel.Trace: - case LogLevel.Debug: - Logger.WriteDebug(message); - break; - case LogLevel.Info: - Logger.WriteInfo(message); - break; - case LogLevel.Warn: - Logger.WriteWarning(message); - break; - case LogLevel.Error: - case LogLevel.Fatal: - Logger.WriteError(message); - break; - } - } - - return true; - } - } -} \ No newline at end of file diff --git a/src/GitVersionCore/MergeMessage.cs b/src/GitVersionCore/MergeMessage.cs index 8fb597da84..d3fb58cfed 100644 --- a/src/GitVersionCore/MergeMessage.cs +++ b/src/GitVersionCore/MergeMessage.cs @@ -1,5 +1,4 @@ -using System; -using System.Linq; +using System; using System.Text.RegularExpressions; namespace GitVersion diff --git a/src/GitVersionCore/OutputVariables/VariableProvider.cs b/src/GitVersionCore/OutputVariables/VariableProvider.cs index df46792fa2..05a45a2a1e 100644 --- a/src/GitVersionCore/OutputVariables/VariableProvider.cs +++ b/src/GitVersionCore/OutputVariables/VariableProvider.cs @@ -1,9 +1,8 @@ -namespace GitVersion +namespace GitVersion { using System; using System.Text.RegularExpressions; using GitVersion.VersionCalculation; - using WarningException = GitTools.WarningException; public static class VariableProvider { @@ -116,4 +115,4 @@ static string CheckAndFormatString(string formatString, T source, string def return formattedString; } } -} \ No newline at end of file +} diff --git a/src/GitVersionCore/OutputVariables/VersionVariables.cs b/src/GitVersionCore/OutputVariables/VersionVariables.cs index dc06bbf214..3f528988d1 100644 --- a/src/GitVersionCore/OutputVariables/VersionVariables.cs +++ b/src/GitVersionCore/OutputVariables/VersionVariables.cs @@ -1,4 +1,4 @@ -namespace GitVersion +namespace GitVersion { using System; using System.Collections; @@ -6,7 +6,6 @@ using System.IO; using System.Linq; using GitVersion.Helpers; - using System.Reflection; using YamlDotNet.Serialization; diff --git a/src/GitVersionCore/SemanticVersion.cs b/src/GitVersionCore/SemanticVersion.cs index 51927ee959..ee9005db7a 100644 --- a/src/GitVersionCore/SemanticVersion.cs +++ b/src/GitVersionCore/SemanticVersion.cs @@ -1,8 +1,6 @@ namespace GitVersion { - using GitTools; using System; - using System.ComponentModel; using System.Text.RegularExpressions; public class SemanticVersion : IFormattable, IComparable @@ -142,7 +140,7 @@ public static SemanticVersion Parse(string version, string tagPrefixRegex) { SemanticVersion semanticVersion; if (!TryParse(version, tagPrefixRegex, out semanticVersion)) - throw new GitTools.WarningException(string.Format("Failed to parse {0} into a Semantic Version", version)); + throw new WarningException(string.Format("Failed to parse {0} into a Semantic Version", version)); return semanticVersion; } @@ -334,4 +332,4 @@ public enum VersionField Minor, Major } -} \ No newline at end of file +} diff --git a/src/GitVersionCore/VersionCalculation/DevelopVersionStrategy.cs b/src/GitVersionCore/VersionCalculation/DevelopVersionStrategy.cs index 8295c91721..9333863f9d 100644 --- a/src/GitVersionCore/VersionCalculation/DevelopVersionStrategy.cs +++ b/src/GitVersionCore/VersionCalculation/DevelopVersionStrategy.cs @@ -4,7 +4,6 @@ namespace GitVersion.VersionCalculation using System.Linq; using System.Text.RegularExpressions; using BaseVersionCalculators; - using GitTools; using LibGit2Sharp; /// @@ -96,4 +95,4 @@ IEnumerable GetReleaseVersion(GitVersionContext context, Branch rel .Select(b => new BaseVersion(context, b.Source, true, b.SemanticVersion, baseSource, b.BranchNameOverride)); } } -} \ No newline at end of file +} diff --git a/src/GitVersionExe.Tests/ArgumentParserTests.cs b/src/GitVersionExe.Tests/ArgumentParserTests.cs index 29c4417fda..195a856e72 100644 --- a/src/GitVersionExe.Tests/ArgumentParserTests.cs +++ b/src/GitVersionExe.Tests/ArgumentParserTests.cs @@ -3,7 +3,6 @@ using Shouldly; using System; using System.Collections.Generic; -using System.ComponentModel; [TestFixture] public class ArgumentParserTests @@ -358,4 +357,4 @@ public void Check_verbosity_parsing(string command, bool shouldThrow, VerbosityL arguments.Verbosity.ShouldBe(expectedVerbosity); } } -} \ No newline at end of file +} diff --git a/src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs b/src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs index 3f19cb05a7..28f2f33fc7 100644 --- a/src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs +++ b/src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs @@ -1,9 +1,9 @@ -using System; +using System; using System.IO; using System.Text; -using GitTools; using GitTools.Testing; using GitVersion; +using GitVersion.Helpers; using NUnit.Framework; using Shouldly; @@ -107,4 +107,4 @@ public void WorkingDirectoryDoesNotExistCrashesWithInformativeMessage() var outputString = output.ToString(); outputString.ShouldContain(string.Format("The working directory '{0}' does not exist.", workingDirectory), () => outputString); } -} \ No newline at end of file +} diff --git a/src/GitVersionExe.Tests/GitVersionExe.Tests.csproj b/src/GitVersionExe.Tests/GitVersionExe.Tests.csproj index 6b200fb5a4..d64bb8cf8c 100644 --- a/src/GitVersionExe.Tests/GitVersionExe.Tests.csproj +++ b/src/GitVersionExe.Tests/GitVersionExe.Tests.csproj @@ -1,4 +1,4 @@ - + net461 false @@ -6,7 +6,6 @@ - diff --git a/src/GitVersionExe.Tests/GitVersionHelper.cs b/src/GitVersionExe.Tests/GitVersionHelper.cs index 5710b89a65..954dab93ce 100644 --- a/src/GitVersionExe.Tests/GitVersionHelper.cs +++ b/src/GitVersionExe.Tests/GitVersionHelper.cs @@ -2,8 +2,8 @@ using System.Collections.Generic; using System.IO; using System.Text; -using GitTools; using GitVersion; +using GitVersion.Helpers; public static class GitVersionHelper { diff --git a/src/GitVersionExe/ArgumentParser.cs b/src/GitVersionExe/ArgumentParser.cs index 978a9f9c6f..afafc0af8c 100644 --- a/src/GitVersionExe/ArgumentParser.cs +++ b/src/GitVersionExe/ArgumentParser.cs @@ -3,7 +3,6 @@ namespace GitVersion using System; using System.Collections.Generic; using System.Collections.Specialized; - using System.ComponentModel; using System.IO; using System.Linq; @@ -419,4 +418,4 @@ static NameValueCollection CollectSwitchesAndValuesFromArguments(IList n return switchesAndValues; } } -} \ No newline at end of file +} diff --git a/src/GitVersionExe/GitVersionExe.csproj b/src/GitVersionExe/GitVersionExe.csproj index 0674d2e960..a601b1649a 100644 --- a/src/GitVersionExe/GitVersionExe.csproj +++ b/src/GitVersionExe/GitVersionExe.csproj @@ -17,7 +17,6 @@ - diff --git a/src/GitVersionExe/Program.cs b/src/GitVersionExe/Program.cs index f9ee36cdf4..e605eb3dd7 100644 --- a/src/GitVersionExe/Program.cs +++ b/src/GitVersionExe/Program.cs @@ -3,7 +3,6 @@ namespace GitVersion using GitVersion.Helpers; using System; using System.Collections.Generic; - using System.ComponentModel; using System.Diagnostics; using System.IO; using System.Linq; @@ -82,7 +81,7 @@ static int VerifyArgumentsAndRun() if (arguments.Diag) { Logger.WriteInfo("Dumping commit graph: "); - GitTools.LibGitExtensions.DumpGraph(arguments.TargetPath, Logger.WriteInfo, 100); + LibGitExtensions.DumpGraph(arguments.TargetPath, Logger.WriteInfo, 100); } #endif if (!Directory.Exists(arguments.TargetPath)) @@ -133,7 +132,7 @@ static int VerifyArgumentsAndRun() try { #if NETDESKTOP - GitTools.LibGitExtensions.DumpGraph(arguments.TargetPath, Logger.WriteInfo, 100); + LibGitExtensions.DumpGraph(arguments.TargetPath, Logger.WriteInfo, 100); #endif } catch (Exception dumpGraphException) diff --git a/src/GitVersionExe/SpecifiedArgumentRunner.cs b/src/GitVersionExe/SpecifiedArgumentRunner.cs index 25a2e813b7..f4b675a7f4 100644 --- a/src/GitVersionExe/SpecifiedArgumentRunner.cs +++ b/src/GitVersionExe/SpecifiedArgumentRunner.cs @@ -1,11 +1,9 @@ namespace GitVersion { - using GitTools; using GitVersion.Helpers; using System; using System.Collections.Generic; using System.Linq; - using WarningException = System.ComponentModel.WarningException; class SpecifiedArgumentRunner { @@ -125,4 +123,4 @@ static bool RunExecCommandIfNeeded(Arguments args, string workingDirectory, Vers .ToArray(); } } -} \ No newline at end of file +} diff --git a/src/GitVersionTask.Tests/GitVersionTask.Tests.csproj b/src/GitVersionTask.Tests/GitVersionTask.Tests.csproj index 8d5c1d031c..c5ab4f9b72 100644 --- a/src/GitVersionTask.Tests/GitVersionTask.Tests.csproj +++ b/src/GitVersionTask.Tests/GitVersionTask.Tests.csproj @@ -7,7 +7,6 @@ - diff --git a/src/GitVersionTask.Tests/InvalidFileCheckerTests.cs b/src/GitVersionTask.Tests/InvalidFileCheckerTests.cs index d22afabd61..e8877d2f94 100644 --- a/src/GitVersionTask.Tests/InvalidFileCheckerTests.cs +++ b/src/GitVersionTask.Tests/InvalidFileCheckerTests.cs @@ -1,9 +1,9 @@ -using System; +using System; using System.IO; +using GitVersion; using GitVersionTask.Tests.Mocks; using Microsoft.Build.Framework; using NUnit.Framework; -using GitTools; [TestFixture] public class InvalidFileCheckerTests : TestBase @@ -217,4 +217,4 @@ End Class InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.vb" } }, projectFile); } -} \ No newline at end of file +} diff --git a/src/GitVersionTask.Tests/packages.config b/src/GitVersionTask.Tests/packages.config deleted file mode 100644 index 07302cf6d8..0000000000 --- a/src/GitVersionTask.Tests/packages.config +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/GitVersionTask/GenerateGitVersionInformation.cs b/src/GitVersionTask/GenerateGitVersionInformation.cs index 8abaa5a97d..d91a7898dc 100644 --- a/src/GitVersionTask/GenerateGitVersionInformation.cs +++ b/src/GitVersionTask/GenerateGitVersionInformation.cs @@ -1,14 +1,10 @@ -namespace GitVersionTask +namespace GitVersionTask { using System; - using System.ComponentModel; using System.IO; using GitVersion; using GitVersion.Helpers; using Microsoft.Build.Framework; - using GitTools; - - public class GenerateGitVersionInformation : GitVersionTaskBase { @@ -44,7 +40,7 @@ public override bool Execute() InnerExecute(); return true; } - catch (GitTools.WarningException errorException) + catch (WarningException errorException) { logger.LogWarning(errorException.Message); return true; diff --git a/src/GitVersionTask/GetVersion.cs b/src/GitVersionTask/GetVersion.cs index 8a9781352b..818f43eeed 100644 --- a/src/GitVersionTask/GetVersion.cs +++ b/src/GitVersionTask/GetVersion.cs @@ -1,11 +1,9 @@ -namespace GitVersionTask +namespace GitVersionTask { using System; using GitVersion; using Microsoft.Build.Framework; - using GitTools; - using System.Reflection; public class GetVersion : GitVersionTaskBase { @@ -138,4 +136,4 @@ public override bool Execute() } } } -} \ No newline at end of file +} diff --git a/src/GitVersionTask/GitVersionTask.csproj b/src/GitVersionTask/GitVersionTask.csproj index 6b14905c1d..522a5a3112 100644 --- a/src/GitVersionTask/GitVersionTask.csproj +++ b/src/GitVersionTask/GitVersionTask.csproj @@ -17,7 +17,7 @@ NugetAssets\GitVersionTask.nuspec 0.0.1-alpha-0001 - version=$(PackageVersion);configuration=$(Configuration);utilpackversion=$(PackageVersion_UtilPackNuGetMSBuild);gittoolscoreversion=$(PackageVersion_GitToolsCore);yamldotnetversion=$(PackageVersion_YamlDotNet) + version=$(PackageVersion);configuration=$(Configuration);utilpackversion=$(PackageVersion_UtilPackNuGetMSBuild);libgit2sharpversion=$(PackageVersion_LibGit2Sharp);yamldotnetversion=$(PackageVersion_YamlDotNet) $(AssemblyName) @@ -32,9 +32,8 @@ - - All - + + All diff --git a/src/GitVersionTask/InvalidFileChecker.cs b/src/GitVersionTask/InvalidFileChecker.cs index 4f522c9df8..d20be03e56 100644 --- a/src/GitVersionTask/InvalidFileChecker.cs +++ b/src/GitVersionTask/InvalidFileChecker.cs @@ -3,8 +3,8 @@ using System.IO; using System.Linq; using System.Text.RegularExpressions; +using GitVersion; using Microsoft.Build.Framework; -using GitTools; public static class InvalidFileChecker { @@ -104,4 +104,4 @@ static IEnumerable GetInvalidFiles(IEnumerable compileFiles, .Where(compileFile => compileFile.Contains("AssemblyInfo")) .Where(s => FileContainsVersionAttribute(s, projectFile)); } -} \ No newline at end of file +} diff --git a/src/GitVersionTask/NugetAssets/GitVersionTask.nuspec b/src/GitVersionTask/NugetAssets/GitVersionTask.nuspec index d4dc2b0b91..b3436fdce8 100644 --- a/src/GitVersionTask/NugetAssets/GitVersionTask.nuspec +++ b/src/GitVersionTask/NugetAssets/GitVersionTask.nuspec @@ -21,7 +21,7 @@ - + diff --git a/src/GitVersionTask/UpdateAssemblyInfo.cs b/src/GitVersionTask/UpdateAssemblyInfo.cs index b299fcbc93..27ccab47d1 100644 --- a/src/GitVersionTask/UpdateAssemblyInfo.cs +++ b/src/GitVersionTask/UpdateAssemblyInfo.cs @@ -1,13 +1,11 @@ -namespace GitVersionTask +namespace GitVersionTask { using System; using System.IO; - using System.Text; using GitVersion; using GitVersion.Helpers; using Microsoft.Build.Framework; - using GitTools; public class UpdateAssemblyInfo : GitVersionTaskBase { @@ -116,4 +114,4 @@ string GetFileExtension() } } } -} \ No newline at end of file +} diff --git a/src/GitVersionTask/WriteVersionInfoToBuildLog.cs b/src/GitVersionTask/WriteVersionInfoToBuildLog.cs index aa4b4c6e1e..fcc1f8998d 100644 --- a/src/GitVersionTask/WriteVersionInfoToBuildLog.cs +++ b/src/GitVersionTask/WriteVersionInfoToBuildLog.cs @@ -1,10 +1,9 @@ -namespace GitVersionTask +namespace GitVersionTask { using System; using System.Collections.Generic; using GitVersion; using Microsoft.Build.Framework; - using GitTools; public class WriteVersionInfoToBuildLog : GitVersionTaskBase { @@ -69,4 +68,4 @@ void WriteIntegrationParameters(IEnumerable applicableBuildServers } } } -} \ No newline at end of file +}