From dc0f528b1cd01afc7594cb21ca6ba514370f67e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Mon, 31 Oct 2016 20:59:39 +0100 Subject: [PATCH 1/6] Ignore JetBrains IDE files. --- .gitignore | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index bd715e0..d36403d 100644 --- a/.gitignore +++ b/.gitignore @@ -80,7 +80,7 @@ deployment/InnoSetup/template/snippets deployment/InnoSetup/template/libraries deployment/InnoSetup/template/doc -# Installshield output folder +# Installshield output folder [Ee]xpress # DocProject is a documentation generator add-in @@ -115,7 +115,7 @@ Backup*/ UpgradeLog*.XML # Windows image file caches -Thumbs.db +Thumbs.db # Folder config file Desktop.ini @@ -123,3 +123,9 @@ Desktop.ini # mstest test results TestResults src/_NCrunch_GitTools.Core/ + + +#################### +# JetBrains IDEs +#################### +.idea \ No newline at end of file From 744d8726bcf45c097d239b66a71c704c28f9461b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Tue, 1 Nov 2016 08:19:55 +0100 Subject: [PATCH 2/6] Changed EOL to LF in some files. --- .travis.yml | 20 +- .../GitTools.Core.Tests.csproj | 202 +++--- src/GitTools.Core.Tests/app.config | 20 +- src/GitTools.Core.Tests/packages.config | 16 +- src/GitTools.Core.sln | 124 ++-- .../GitTools.Core.NET40.csproj | 150 ++--- .../GitTools.Core.NET40/packages.config | 10 +- .../GitTools.Core.NET45.csproj | 148 ++--- .../GitTools.Core.NET45/packages.config | 10 +- .../Git/Helpers/GitRepositoryHelper.cs | 594 +++++++++--------- .../GitTools.Core.Shared.projitems | 68 +- .../IO/Helpers/DeleteHelper.cs | 6 +- 12 files changed, 684 insertions(+), 684 deletions(-) diff --git a/.travis.yml b/.travis.yml index 822095b..ad7c609 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,10 @@ -language: csharp -solution: src/GitTools.Core.sln -sudo: false -install: - # - sudo nuget update -self - - nuget restore src/GitTools.Core.sln - - nuget install NUnit.Runners -Version 3.2.1 -OutputDirectory ./src/packages -script: - - xbuild ./src/GitTools.Core.sln /property:Configuration="Debug" /verbosity:detailed - - mono --debug --runtime=v4.0.30319 ./src/packages/NUnit.ConsoleRunner.3.2.1/tools/nunit3-console.exe ./output/debug/GitTools.Core.Tests/net45/GitTools.Core.Tests.dll -where "cat != NoMono" +language: csharp +solution: src/GitTools.Core.sln +sudo: false +install: + # - sudo nuget update -self + - nuget restore src/GitTools.Core.sln + - nuget install NUnit.Runners -Version 3.2.1 -OutputDirectory ./src/packages +script: + - xbuild ./src/GitTools.Core.sln /property:Configuration="Debug" /verbosity:detailed + - mono --debug --runtime=v4.0.30319 ./src/packages/NUnit.ConsoleRunner.3.2.1/tools/nunit3-console.exe ./output/debug/GitTools.Core.Tests/net45/GitTools.Core.Tests.dll -where "cat != NoMono" diff --git a/src/GitTools.Core.Tests/GitTools.Core.Tests.csproj b/src/GitTools.Core.Tests/GitTools.Core.Tests.csproj index b57a718..8517eba 100644 --- a/src/GitTools.Core.Tests/GitTools.Core.Tests.csproj +++ b/src/GitTools.Core.Tests/GitTools.Core.Tests.csproj @@ -1,108 +1,108 @@ - - - - - - Debug - AnyCPU - {0834BE9B-5CDE-4CAB-A683-C70A7D91450B} - Library - Properties - GitTools.Tests - GitTools.Core.Tests - v4.5 - 512 - 5 - - - - - true - full - false - ..\..\output\debug\GitTools.Core.Tests\net45\ - TRACE;DEBUG - prompt - 4 - true - 1591,1701 - - - pdbonly - true - ..\..\output\release\GitTools.Core.Tests\net45\ - TRACE - prompt - 4 - true - 1591 - - - - False - ..\packages\Atlassian.SDK.2.5.0\lib\Atlassian.Jira.dll - - - ..\packages\GitTools.Testing.1.1.1-beta0001\lib\net4\GitTools.Testing.dll - True - - - ..\packages\LibGit2Sharp.0.23.0-pre20150419160303\lib\net40\LibGit2Sharp.dll - True - - - ..\packages\NUnit.3.2.1\lib\net45\nunit.framework.dll - True - - - ..\packages\Shouldly.2.7.0\lib\net40\Shouldly.dll - True - - - - - - - - - - - - - Properties\SolutionAssemblyInfo.cs - - - - - - - - - - - {C11252F9-0ECA-44DC-860B-E029C04FBD10} - GitTools.Core.NET40 - - - - - - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - + + + + + + Debug + AnyCPU + {0834BE9B-5CDE-4CAB-A683-C70A7D91450B} + Library + Properties + GitTools.Tests + GitTools.Core.Tests + v4.5 + 512 + 5 + + + + + true + full + false + ..\..\output\debug\GitTools.Core.Tests\net45\ + TRACE;DEBUG + prompt + 4 + true + 1591,1701 + + + pdbonly + true + ..\..\output\release\GitTools.Core.Tests\net45\ + TRACE + prompt + 4 + true + 1591 + + + + False + ..\packages\Atlassian.SDK.2.5.0\lib\Atlassian.Jira.dll + + + ..\packages\GitTools.Testing.1.1.1-beta0001\lib\net4\GitTools.Testing.dll + True + + + ..\packages\LibGit2Sharp.0.23.0-pre20150419160303\lib\net40\LibGit2Sharp.dll + True + + + ..\packages\NUnit.3.2.1\lib\net45\nunit.framework.dll + True + + + ..\packages\Shouldly.2.7.0\lib\net40\Shouldly.dll + True + + + + + + + + + + + + + Properties\SolutionAssemblyInfo.cs + + + + + + + + + + + {C11252F9-0ECA-44DC-860B-E029C04FBD10} + GitTools.Core.NET40 + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + --> \ No newline at end of file diff --git a/src/GitTools.Core.Tests/app.config b/src/GitTools.Core.Tests/app.config index 372f8b6..b57ccf8 100644 --- a/src/GitTools.Core.Tests/app.config +++ b/src/GitTools.Core.Tests/app.config @@ -1,11 +1,11 @@ - - - - - - - - - - + + + + + + + + + + \ No newline at end of file diff --git a/src/GitTools.Core.Tests/packages.config b/src/GitTools.Core.Tests/packages.config index 9c8e6dd..720ce84 100644 --- a/src/GitTools.Core.Tests/packages.config +++ b/src/GitTools.Core.Tests/packages.config @@ -1,9 +1,9 @@ - - - - - - - - + + + + + + + + \ No newline at end of file diff --git a/src/GitTools.Core.sln b/src/GitTools.Core.sln index 117ad84..347ac06 100644 --- a/src/GitTools.Core.sln +++ b/src/GitTools.Core.sln @@ -1,62 +1,62 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25123.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".misc", ".misc", "{72ECAB81-A674-4AC8-8795-7AD71C3E1A5A}" - ProjectSection(SolutionItems) = preProject - ..\.travis.yml = ..\.travis.yml - ..\appveyor.yml = ..\appveyor.yml - GitTools.Core.sln.DotSettings = GitTools.Core.sln.DotSettings - ..\GitVersionConfig.yaml = ..\GitVersionConfig.yaml - ..\README.md = ..\README.md - Settings.StyleCop = Settings.StyleCop - SolutionAssemblyInfo.cs = SolutionAssemblyInfo.cs - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitTools.Core.Tests", "GitTools.Core.Tests\GitTools.Core.Tests.csproj", "{0834BE9B-5CDE-4CAB-A683-C70A7D91450B}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitTools.Core.NET40", "GitTools.Core\GitTools.Core.NET40\GitTools.Core.NET40.csproj", "{C11252F9-0ECA-44DC-860B-E029C04FBD10}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "GitTools.Core", "GitTools.Core", "{753DD689-12ED-42D8-8AF7-936336D65FA0}" - ProjectSection(SolutionItems) = preProject - GitTools.Core\GitTools.Core.nuspec = GitTools.Core\GitTools.Core.nuspec - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitTools.Core.NET45", "GitTools.Core\GitTools.Core.NET45\GitTools.Core.NET45.csproj", "{66295D7C-58FD-4641-AEAB-3DF7EA8FA4D2}" -EndProject -Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "GitTools.Core.Shared", "GitTools.Core\GitTools.Core.Shared\GitTools.Core.Shared.shproj", "{C4B449DF-3E78-4F3B-81A8-DE0DC5827532}" -EndProject -Global - GlobalSection(SharedMSBuildProjectFiles) = preSolution - GitTools.Core\GitTools.Core.Shared\GitTools.Core.Shared.projitems*{66295d7c-58fd-4641-aeab-3df7ea8fa4d2}*SharedItemsImports = 4 - GitTools.Core\GitTools.Core.Shared\GitTools.Core.Shared.projitems*{c4b449df-3e78-4f3b-81a8-de0dc5827532}*SharedItemsImports = 13 - GitTools.Core\GitTools.Core.Shared\GitTools.Core.Shared.projitems*{c11252f9-0eca-44dc-860b-e029c04fbd10}*SharedItemsImports = 4 - EndGlobalSection - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {0834BE9B-5CDE-4CAB-A683-C70A7D91450B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0834BE9B-5CDE-4CAB-A683-C70A7D91450B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0834BE9B-5CDE-4CAB-A683-C70A7D91450B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0834BE9B-5CDE-4CAB-A683-C70A7D91450B}.Release|Any CPU.Build.0 = Release|Any CPU - {C11252F9-0ECA-44DC-860B-E029C04FBD10}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C11252F9-0ECA-44DC-860B-E029C04FBD10}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C11252F9-0ECA-44DC-860B-E029C04FBD10}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C11252F9-0ECA-44DC-860B-E029C04FBD10}.Release|Any CPU.Build.0 = Release|Any CPU - {66295D7C-58FD-4641-AEAB-3DF7EA8FA4D2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {66295D7C-58FD-4641-AEAB-3DF7EA8FA4D2}.Debug|Any CPU.Build.0 = Debug|Any CPU - {66295D7C-58FD-4641-AEAB-3DF7EA8FA4D2}.Release|Any CPU.ActiveCfg = Release|Any CPU - {66295D7C-58FD-4641-AEAB-3DF7EA8FA4D2}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {C11252F9-0ECA-44DC-860B-E029C04FBD10} = {753DD689-12ED-42D8-8AF7-936336D65FA0} - {66295D7C-58FD-4641-AEAB-3DF7EA8FA4D2} = {753DD689-12ED-42D8-8AF7-936336D65FA0} - {C4B449DF-3E78-4F3B-81A8-DE0DC5827532} = {753DD689-12ED-42D8-8AF7-936336D65FA0} - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25123.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".misc", ".misc", "{72ECAB81-A674-4AC8-8795-7AD71C3E1A5A}" + ProjectSection(SolutionItems) = preProject + ..\.travis.yml = ..\.travis.yml + ..\appveyor.yml = ..\appveyor.yml + GitTools.Core.sln.DotSettings = GitTools.Core.sln.DotSettings + ..\GitVersionConfig.yaml = ..\GitVersionConfig.yaml + ..\README.md = ..\README.md + Settings.StyleCop = Settings.StyleCop + SolutionAssemblyInfo.cs = SolutionAssemblyInfo.cs + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitTools.Core.Tests", "GitTools.Core.Tests\GitTools.Core.Tests.csproj", "{0834BE9B-5CDE-4CAB-A683-C70A7D91450B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitTools.Core.NET40", "GitTools.Core\GitTools.Core.NET40\GitTools.Core.NET40.csproj", "{C11252F9-0ECA-44DC-860B-E029C04FBD10}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "GitTools.Core", "GitTools.Core", "{753DD689-12ED-42D8-8AF7-936336D65FA0}" + ProjectSection(SolutionItems) = preProject + GitTools.Core\GitTools.Core.nuspec = GitTools.Core\GitTools.Core.nuspec + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitTools.Core.NET45", "GitTools.Core\GitTools.Core.NET45\GitTools.Core.NET45.csproj", "{66295D7C-58FD-4641-AEAB-3DF7EA8FA4D2}" +EndProject +Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "GitTools.Core.Shared", "GitTools.Core\GitTools.Core.Shared\GitTools.Core.Shared.shproj", "{C4B449DF-3E78-4F3B-81A8-DE0DC5827532}" +EndProject +Global + GlobalSection(SharedMSBuildProjectFiles) = preSolution + GitTools.Core\GitTools.Core.Shared\GitTools.Core.Shared.projitems*{66295d7c-58fd-4641-aeab-3df7ea8fa4d2}*SharedItemsImports = 4 + GitTools.Core\GitTools.Core.Shared\GitTools.Core.Shared.projitems*{c4b449df-3e78-4f3b-81a8-de0dc5827532}*SharedItemsImports = 13 + GitTools.Core\GitTools.Core.Shared\GitTools.Core.Shared.projitems*{c11252f9-0eca-44dc-860b-e029c04fbd10}*SharedItemsImports = 4 + EndGlobalSection + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0834BE9B-5CDE-4CAB-A683-C70A7D91450B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0834BE9B-5CDE-4CAB-A683-C70A7D91450B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0834BE9B-5CDE-4CAB-A683-C70A7D91450B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0834BE9B-5CDE-4CAB-A683-C70A7D91450B}.Release|Any CPU.Build.0 = Release|Any CPU + {C11252F9-0ECA-44DC-860B-E029C04FBD10}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C11252F9-0ECA-44DC-860B-E029C04FBD10}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C11252F9-0ECA-44DC-860B-E029C04FBD10}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C11252F9-0ECA-44DC-860B-E029C04FBD10}.Release|Any CPU.Build.0 = Release|Any CPU + {66295D7C-58FD-4641-AEAB-3DF7EA8FA4D2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {66295D7C-58FD-4641-AEAB-3DF7EA8FA4D2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {66295D7C-58FD-4641-AEAB-3DF7EA8FA4D2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {66295D7C-58FD-4641-AEAB-3DF7EA8FA4D2}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {C11252F9-0ECA-44DC-860B-E029C04FBD10} = {753DD689-12ED-42D8-8AF7-936336D65FA0} + {66295D7C-58FD-4641-AEAB-3DF7EA8FA4D2} = {753DD689-12ED-42D8-8AF7-936336D65FA0} + {C4B449DF-3E78-4F3B-81A8-DE0DC5827532} = {753DD689-12ED-42D8-8AF7-936336D65FA0} + EndGlobalSection +EndGlobal diff --git a/src/GitTools.Core/GitTools.Core.NET40/GitTools.Core.NET40.csproj b/src/GitTools.Core/GitTools.Core.NET40/GitTools.Core.NET40.csproj index b2c14b2..4c97549 100644 --- a/src/GitTools.Core/GitTools.Core.NET40/GitTools.Core.NET40.csproj +++ b/src/GitTools.Core/GitTools.Core.NET40/GitTools.Core.NET40.csproj @@ -1,82 +1,82 @@ - - - - - - Debug - AnyCPU - {C11252F9-0ECA-44DC-860B-E029C04FBD10} - Library - Properties - GitTools - GitTools.Core - v4.0 - 5 - 512 - - - - - - true - full - false - ..\..\..\output\Debug\GitTools.Core\net4\ - TRACE;DEBUG - prompt - 4 - ..\..\..\output\Debug\GitTools.Core\net4\GitTools.Core.xml - true - 1591,414 - - - pdbonly - true - ..\..\..\output\Release\GitTools.Core\net4\ - TRACE - prompt - 4 - 1591 - true - ..\..\..\output\Release\GitTools.Core\net4\GitTools.Core.xml - - - - ..\..\packages\LibGit2Sharp.0.23.0-pre20150419160303\lib\net40\LibGit2Sharp.dll - True - - - - - - - - - - - - Properties\SolutionAssemblyInfo.cs - - - - - - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - + + + + + + Debug + AnyCPU + {C11252F9-0ECA-44DC-860B-E029C04FBD10} + Library + Properties + GitTools + GitTools.Core + v4.0 + 5 + 512 + + + + + + true + full + false + ..\..\..\output\Debug\GitTools.Core\net4\ + TRACE;DEBUG + prompt + 4 + ..\..\..\output\Debug\GitTools.Core\net4\GitTools.Core.xml + true + 1591,414 + + + pdbonly + true + ..\..\..\output\Release\GitTools.Core\net4\ + TRACE + prompt + 4 + 1591 + true + ..\..\..\output\Release\GitTools.Core\net4\GitTools.Core.xml + + + + ..\..\packages\LibGit2Sharp.0.23.0-pre20150419160303\lib\net40\LibGit2Sharp.dll + True + + + + + + + + + + + + Properties\SolutionAssemblyInfo.cs + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + --> \ No newline at end of file diff --git a/src/GitTools.Core/GitTools.Core.NET40/packages.config b/src/GitTools.Core/GitTools.Core.NET40/packages.config index 0e1184b..705055c 100644 --- a/src/GitTools.Core/GitTools.Core.NET40/packages.config +++ b/src/GitTools.Core/GitTools.Core.NET40/packages.config @@ -1,6 +1,6 @@ - - - - - + + + + + \ No newline at end of file diff --git a/src/GitTools.Core/GitTools.Core.NET45/GitTools.Core.NET45.csproj b/src/GitTools.Core/GitTools.Core.NET45/GitTools.Core.NET45.csproj index 6ccc06d..75789ff 100644 --- a/src/GitTools.Core/GitTools.Core.NET45/GitTools.Core.NET45.csproj +++ b/src/GitTools.Core/GitTools.Core.NET45/GitTools.Core.NET45.csproj @@ -1,81 +1,81 @@ - - - - - - Debug - AnyCPU - {66295D7C-58FD-4641-AEAB-3DF7EA8FA4D2} - Library - Properties - GitTools - GitTools.Core - v4.5 - 512 - 5 - - - - - true - full - false - ..\..\..\output\Debug\GitTools.Core\net45\ - TRACE;DEBUG - prompt - 4 - ..\..\..\output\Debug\GitTools.Core\net45\GitTools.Core.xml - true - 1591,414 - - - pdbonly - true - ..\..\..\output\Release\GitTools.Core\net45\ - TRACE - prompt - 4 - 1591 - true - ..\..\..\output\Release\GitTools.Core\net45\GitTools.Core.xml - - - - ..\..\packages\LibGit2Sharp.0.23.0-pre20150419160303\lib\net40\LibGit2Sharp.dll - True - - - - - - - - - - - - Properties\SolutionAssemblyInfo.cs - - - - - - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - + + + + + + Debug + AnyCPU + {66295D7C-58FD-4641-AEAB-3DF7EA8FA4D2} + Library + Properties + GitTools + GitTools.Core + v4.5 + 512 + 5 + + + + + true + full + false + ..\..\..\output\Debug\GitTools.Core\net45\ + TRACE;DEBUG + prompt + 4 + ..\..\..\output\Debug\GitTools.Core\net45\GitTools.Core.xml + true + 1591,414 + + + pdbonly + true + ..\..\..\output\Release\GitTools.Core\net45\ + TRACE + prompt + 4 + 1591 + true + ..\..\..\output\Release\GitTools.Core\net45\GitTools.Core.xml + + + + ..\..\packages\LibGit2Sharp.0.23.0-pre20150419160303\lib\net40\LibGit2Sharp.dll + True + + + + + + + + + + + + Properties\SolutionAssemblyInfo.cs + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + --> \ No newline at end of file diff --git a/src/GitTools.Core/GitTools.Core.NET45/packages.config b/src/GitTools.Core/GitTools.Core.NET45/packages.config index c6a9e46..8807f96 100644 --- a/src/GitTools.Core/GitTools.Core.NET45/packages.config +++ b/src/GitTools.Core/GitTools.Core.NET45/packages.config @@ -1,6 +1,6 @@ - - - - - + + + + + \ No newline at end of file diff --git a/src/GitTools.Core/GitTools.Core.Shared/Git/Helpers/GitRepositoryHelper.cs b/src/GitTools.Core/GitTools.Core.Shared/Git/Helpers/GitRepositoryHelper.cs index 792687e..c2c3bcc 100644 --- a/src/GitTools.Core/GitTools.Core.Shared/Git/Helpers/GitRepositoryHelper.cs +++ b/src/GitTools.Core/GitTools.Core.Shared/Git/Helpers/GitRepositoryHelper.cs @@ -1,298 +1,298 @@ -namespace GitTools.Git -{ - using System; - using System.Collections.Generic; - using System.ComponentModel; - using System.Linq; - using LibGit2Sharp; - using Logging; - - /// - /// Static helper class for creating/normalising git repositories - /// - public static class GitRepositoryHelper - { - static readonly ILog Log = LogProvider.GetCurrentClassLogger(); - - /// - /// 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) - { - Log.Info("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, currentBranch); - CreateOrUpdateLocalBranchesFromRemoteTrackingOnes(repo, remote.Name); - - var headSha = repo.Refs.Head.TargetIdentifier; - - if (!repo.Info.IsHeadDetached) - { - Log.Info(string.Format("HEAD points at branch '{0}'.", headSha)); - return; - } - - Log.Info(string.Format("HEAD is detached and points at commit '{0}'.", headSha)); - Log.Info(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) - { - Log.Info(string.Format("Checking out local branch '{0}'.", currentBranch)); - repo.Checkout(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"; - - Log.Warn(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) - { - Log.Warn("Because one of the branches is 'master', will build master." + moveBranchMsg); - repo.Checkout(master); - } - else - { - var branchesWithoutSeparators = localBranchesWhereCommitShaIsHead.Where(b => !b.FriendlyName.Contains('/') && !b.FriendlyName.Contains('-')).ToList(); - if (branchesWithoutSeparators.Count == 1) - { - var branchWithoutSeparator = branchesWithoutSeparators[0]; - Log.Warn(string.Format("Choosing {0} as it is the only branch without / or - in it. " + moveBranchMsg, branchWithoutSeparator.CanonicalName)); - repo.Checkout(branchWithoutSeparator); - } - else - { - throw new WarningException("Failed to try and guess branch to use. " + moveBranchMsg); - } - } - } - else if (localBranchesWhereCommitShaIsHead.Count == 0) - { - Log.Info(string.Format("No local branch pointing at the commit '{0}'. Fake branch needs to be created.", headSha)); - CreateFakeBranchPointingAtThePullRequestTip(repo, authentication); - } - else - { - Log.Info(string.Format("Checking out local branch 'refs/heads/{0}'.", localBranchesWhereCommitShaIsHead[0].FriendlyName)); - repo.Checkout(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(@"GitTools.Core 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/GitTools.Core", - LibGitExtensions.CreateGitLogArgs(100))); - } - } - } - } - } - - public static void Fetch(AuthenticationInfo authentication, Remote remote, Repository repo) - { - Log.Info(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, 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; - var repoTipId = repoTip.Id; - - if (repo.Branches.All(b => b.CanonicalName != localCanonicalName)) - { - Log.Info(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 - { - Log.Info(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); - } - - repo.Checkout(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); - - Log.Info(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(); - - Log.Info("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(); - - Log.Info("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; - Log.Info(string.Format("Found remote tip '{0}' pointing at the commit '{1}'.", canonicalName, headTipSha)); - - if (canonicalName.StartsWith("refs/tags")) - { - Log.Info(string.Format("Checking out tag '{0}'", canonicalName)); - repo.Checkout(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/"); - - Log.Info(string.Format("Creating fake local branch '{0}'.", fakeBranchName)); - repo.Refs.Add(fakeBranchName, new ObjectId(headTipSha)); - - Log.Info(string.Format("Checking local branch '{0}' out.", fakeBranchName)); - repo.Checkout(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) - { - Log.Info(string.Format("Skipping update of '{0}' as it already matches the remote ref.", remoteTrackingReference.CanonicalName)); - continue; - } - var remoteRefTipId = remotedirectReference.Target.Id; - Log.Info(string.Format("Updating local ref '{0}' to point at {1}.", localRef.CanonicalName, remoteRefTipId)); - repo.Refs.UpdateTarget(localRef, remoteRefTipId); - continue; - } - - Log.Info(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(); - Log.Info(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); - } - } +namespace GitTools.Git +{ + using System; + using System.Collections.Generic; + using System.ComponentModel; + using System.Linq; + using LibGit2Sharp; + using Logging; + + /// + /// Static helper class for creating/normalising git repositories + /// + public static class GitRepositoryHelper + { + static readonly ILog Log = LogProvider.GetCurrentClassLogger(); + + /// + /// 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) + { + Log.Info("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, currentBranch); + CreateOrUpdateLocalBranchesFromRemoteTrackingOnes(repo, remote.Name); + + var headSha = repo.Refs.Head.TargetIdentifier; + + if (!repo.Info.IsHeadDetached) + { + Log.Info(string.Format("HEAD points at branch '{0}'.", headSha)); + return; + } + + Log.Info(string.Format("HEAD is detached and points at commit '{0}'.", headSha)); + Log.Info(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) + { + Log.Info(string.Format("Checking out local branch '{0}'.", currentBranch)); + repo.Checkout(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"; + + Log.Warn(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) + { + Log.Warn("Because one of the branches is 'master', will build master." + moveBranchMsg); + repo.Checkout(master); + } + else + { + var branchesWithoutSeparators = localBranchesWhereCommitShaIsHead.Where(b => !b.FriendlyName.Contains('/') && !b.FriendlyName.Contains('-')).ToList(); + if (branchesWithoutSeparators.Count == 1) + { + var branchWithoutSeparator = branchesWithoutSeparators[0]; + Log.Warn(string.Format("Choosing {0} as it is the only branch without / or - in it. " + moveBranchMsg, branchWithoutSeparator.CanonicalName)); + repo.Checkout(branchWithoutSeparator); + } + else + { + throw new WarningException("Failed to try and guess branch to use. " + moveBranchMsg); + } + } + } + else if (localBranchesWhereCommitShaIsHead.Count == 0) + { + Log.Info(string.Format("No local branch pointing at the commit '{0}'. Fake branch needs to be created.", headSha)); + CreateFakeBranchPointingAtThePullRequestTip(repo, authentication); + } + else + { + Log.Info(string.Format("Checking out local branch 'refs/heads/{0}'.", localBranchesWhereCommitShaIsHead[0].FriendlyName)); + repo.Checkout(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(@"GitTools.Core 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/GitTools.Core", + LibGitExtensions.CreateGitLogArgs(100))); + } + } + } + } + } + + public static void Fetch(AuthenticationInfo authentication, Remote remote, Repository repo) + { + Log.Info(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, 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; + var repoTipId = repoTip.Id; + + if (repo.Branches.All(b => b.CanonicalName != localCanonicalName)) + { + Log.Info(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 + { + Log.Info(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); + } + + repo.Checkout(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); + + Log.Info(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(); + + Log.Info("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(); + + Log.Info("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; + Log.Info(string.Format("Found remote tip '{0}' pointing at the commit '{1}'.", canonicalName, headTipSha)); + + if (canonicalName.StartsWith("refs/tags")) + { + Log.Info(string.Format("Checking out tag '{0}'", canonicalName)); + repo.Checkout(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/"); + + Log.Info(string.Format("Creating fake local branch '{0}'.", fakeBranchName)); + repo.Refs.Add(fakeBranchName, new ObjectId(headTipSha)); + + Log.Info(string.Format("Checking local branch '{0}' out.", fakeBranchName)); + repo.Checkout(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) + { + Log.Info(string.Format("Skipping update of '{0}' as it already matches the remote ref.", remoteTrackingReference.CanonicalName)); + continue; + } + var remoteRefTipId = remotedirectReference.Target.Id; + Log.Info(string.Format("Updating local ref '{0}' to point at {1}.", localRef.CanonicalName, remoteRefTipId)); + repo.Refs.UpdateTarget(localRef, remoteRefTipId); + continue; + } + + Log.Info(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(); + Log.Info(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); + } + } } \ No newline at end of file diff --git a/src/GitTools.Core/GitTools.Core.Shared/GitTools.Core.Shared.projitems b/src/GitTools.Core/GitTools.Core.Shared/GitTools.Core.Shared.projitems index f135c8e..50bc512 100644 --- a/src/GitTools.Core/GitTools.Core.Shared/GitTools.Core.Shared.projitems +++ b/src/GitTools.Core/GitTools.Core.Shared/GitTools.Core.Shared.projitems @@ -1,35 +1,35 @@ - - - - $(MSBuildAllProjects);$(MSBuildThisFileFullPath) - true - c4b449df-3e78-4f3b-81a8-de0dc5827532 - - - GitTools - - - - - - - - - - - - - - - - - - - - - - - - - + + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + true + c4b449df-3e78-4f3b-81a8-de0dc5827532 + + + GitTools + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/GitTools.Core/GitTools.Core.Shared/IO/Helpers/DeleteHelper.cs b/src/GitTools.Core/GitTools.Core.Shared/IO/Helpers/DeleteHelper.cs index 57638f5..f51bf1f 100644 --- a/src/GitTools.Core/GitTools.Core.Shared/IO/Helpers/DeleteHelper.cs +++ b/src/GitTools.Core/GitTools.Core.Shared/IO/Helpers/DeleteHelper.cs @@ -27,9 +27,9 @@ public static void DeleteGitRepository(string directory) } catch (FileNotFoundException) { - } - catch (UnauthorizedAccessException) - { + } + catch (UnauthorizedAccessException) + { } } From d3adbd489d9feafecf1c6b148fb6151712cd06ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Tue, 1 Nov 2016 08:28:10 +0100 Subject: [PATCH 3/6] Added dot files to the solution --- src/GitTools.Core.sln | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/GitTools.Core.sln b/src/GitTools.Core.sln index 347ac06..1c7ec25 100644 --- a/src/GitTools.Core.sln +++ b/src/GitTools.Core.sln @@ -12,6 +12,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".misc", ".misc", "{72ECAB81 ..\README.md = ..\README.md Settings.StyleCop = Settings.StyleCop SolutionAssemblyInfo.cs = SolutionAssemblyInfo.cs + ..\.gitattributes = ..\.gitattributes + ..\.gitignore = ..\.gitignore EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitTools.Core.Tests", "GitTools.Core.Tests\GitTools.Core.Tests.csproj", "{0834BE9B-5CDE-4CAB-A683-C70A7D91450B}" From 636aff0c2210086eb2386570b8a90aa412a651b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Mon, 31 Oct 2016 21:38:07 +0100 Subject: [PATCH 4/6] Added GitHubFlowMajorRelease test from GitVersion. --- .../Git/GitRepositoryHelperTests.cs | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/GitTools.Core.Tests/Git/GitRepositoryHelperTests.cs b/src/GitTools.Core.Tests/Git/GitRepositoryHelperTests.cs index 53ae411..bd1f279 100644 --- a/src/GitTools.Core.Tests/Git/GitRepositoryHelperTests.cs +++ b/src/GitTools.Core.Tests/Git/GitRepositoryHelperTests.cs @@ -176,5 +176,52 @@ public void CheckedOutShaShouldNotChanged() } } } + + + [Test] + // Copied from GitVersion, to attempt fixing this bug: https://travis-ci.org/GitTools/GitVersion/jobs/171288284#L2025 + public void GitHubFlowMajorRelease() + { + using (var fixture = new EmptyRepositoryFixture()) + { + fixture.SequenceDiagram.Participant("master"); + + fixture.Repository.MakeACommit(); + fixture.ApplyTag("1.3.0"); + + // Create release branch + fixture.BranchTo("release/2.0.0", "release"); + fixture.SequenceDiagram.Activate("release/2.0.0"); + fixture.MakeACommit(); + // fixture.AssertFullSemver("2.0.0-beta.1+1"); + fixture.MakeACommit(); + // fixture.AssertFullSemver("2.0.0-beta.1+2"); + + // Apply beta.1 tag should be exact tag + fixture.ApplyTag("2.0.0-beta.1"); + // fixture.AssertFullSemver("2.0.0-beta.1"); + + // test that the CommitsSinceVersionSource should still return commit count + // var version = fixture.GetVersion(); + // version.CommitsSinceVersionSource.ShouldBe("2"); + + // Make a commit after a tag should bump up the beta + fixture.MakeACommit(); + // fixture.AssertFullSemver("2.0.0-beta.2+3"); + + // Complete release + fixture.Checkout("master"); + fixture.MergeNoFF("release/2.0.0"); + fixture.SequenceDiagram.Destroy("release/2.0.0"); + fixture.SequenceDiagram.NoteOver("Release branches are deleted once merged", "release/2.0.0"); + + //fixture.AssertFullSemver("2.0.0+0"); + fixture.ApplyTag("2.0.0"); + // fixture.AssertFullSemver("2.0.0"); + fixture.MakeACommit(); + fixture.Repository.DumpGraph(); + // fixture.AssertFullSemver("2.0.1+1"); + } + } } } \ No newline at end of file From c1f332d1bde90f739ef0fa09dd241668f2c7d4cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Mon, 31 Oct 2016 21:38:44 +0100 Subject: [PATCH 5/6] Add try/catch for setting the process priority class, ignoring the exception if its message is "Success". --- .../Helpers/ProcessHelper.cs | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/GitTools.Core/GitTools.Core.Shared/Helpers/ProcessHelper.cs b/src/GitTools.Core/GitTools.Core.Shared/Helpers/ProcessHelper.cs index a4662d5..99f712d 100644 --- a/src/GitTools.Core/GitTools.Core.Shared/Helpers/ProcessHelper.cs +++ b/src/GitTools.Core/GitTools.Core.Shared/Helpers/ProcessHelper.cs @@ -24,11 +24,11 @@ public static Process Start(ProcessStartInfo startInfo) try { process = Process.Start(startInfo); - process.PriorityClass = ProcessPriorityClass.Idle; } catch (Win32Exception exception) { - // NOTE: https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396 @asbjornu + // NOTE: https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382.aspx + // -- @asbjornu if (exception.NativeErrorCode == 2) { throw new FileNotFoundException(string.Format("The executable file '{0}' could not be found.", @@ -39,6 +39,28 @@ public static Process Start(ProcessStartInfo startInfo) throw; } + + try + { + if (process != null) + { + process.PriorityClass = ProcessPriorityClass.Idle; + } + } + catch (Win32Exception exception) + { + + // NOTE: It seems like in some situations, setting the priority class will throw an exception + // 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 + // -- @asbjornu + if (exception.NativeErrorCode == 0) + { + throw; + } + } } } @@ -137,7 +159,7 @@ public struct ChangeErrorMode : IDisposable public ChangeErrorMode(ErrorModes mode) { try - { + { oldMode = SetErrorMode((int)mode); } catch (EntryPointNotFoundException) @@ -150,7 +172,7 @@ public ChangeErrorMode(ErrorModes mode) void IDisposable.Dispose() { try - { + { SetErrorMode(oldMode); } catch (EntryPointNotFoundException) From 87ea2ede1090167821c4895fb056084ab9dc2408 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Tue, 1 Nov 2016 11:33:03 +0100 Subject: [PATCH 6/6] Added NativeErrorCode enum, cleaned up catch logic and throw DirectoryNotFoundException on error code 3. --- .../Helpers/ProcessHelper.cs | 56 +++++++++++++------ 1 file changed, 40 insertions(+), 16 deletions(-) diff --git a/src/GitTools.Core/GitTools.Core.Shared/Helpers/ProcessHelper.cs b/src/GitTools.Core/GitTools.Core.Shared/Helpers/ProcessHelper.cs index 99f712d..f962a09 100644 --- a/src/GitTools.Core/GitTools.Core.Shared/Helpers/ProcessHelper.cs +++ b/src/GitTools.Core/GitTools.Core.Shared/Helpers/ProcessHelper.cs @@ -27,14 +27,22 @@ public static Process Start(ProcessStartInfo startInfo) } catch (Win32Exception exception) { - // NOTE: https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382.aspx - // -- @asbjornu - if (exception.NativeErrorCode == 2) + switch ((NativeErrorCode)exception.NativeErrorCode) { - throw new FileNotFoundException(string.Format("The executable file '{0}' could not be found.", - startInfo.FileName), - startInfo.FileName, - exception); + 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; @@ -47,19 +55,24 @@ public static Process Start(ProcessStartInfo startInfo) process.PriorityClass = ProcessPriorityClass.Idle; } } - catch (Win32Exception exception) + catch { - - // NOTE: It seems like in some situations, setting the priority class will throw an exception + // 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 + // + // 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 - if (exception.NativeErrorCode == 0) - { - throw; - } } } } @@ -142,6 +155,17 @@ public static int Run(Action output, Action errorOutput, TextRea } } + /// + /// 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 {