From 7e29fa2122cbe12aa45d641439067e94c3c2a10d Mon Sep 17 00:00:00 2001 From: Ahmed ElSayed Date: Wed, 14 Jan 2015 18:33:50 -0800 Subject: [PATCH] support both libgit2sharp and gitexe at the same time and update test cases --- .editorconfig | 15 - Kudu.Console/Program.cs | 10 +- .../Settings/DeploymentSettingsExtension.cs | 5 + Kudu.Contracts/Settings/SettingsKeys.cs | 1 + Kudu.Contracts/SourceControl/IRepository.cs | 2 +- .../SourceControl/IRepositoryFactory.cs | 1 + Kudu.Core.Test/GitRepositoryTest.cs | 43 +- Kudu.Core.Test/NullRepositoryFacts.cs | 2 +- Kudu.Core/Kudu.Core.csproj | 12 +- .../SourceControl/Git/GitExeRepository.cs | 169 ++++--- Kudu.Core/SourceControl/Git/IGitRepository.cs | 13 + .../Git/LibGit2SharpRepository.cs | 418 ++++++++++++++++++ Kudu.Core/SourceControl/Hg/HgRepository.cs | 11 +- Kudu.Core/SourceControl/NullRepository.cs | 8 +- Kudu.Core/SourceControl/RepositoryFactory.cs | 33 +- Kudu.Core/packages.config | 2 +- .../DeploymentManagerTests.cs | 77 ++-- Kudu.FunctionalTests/GitRepositoryFacts.cs | 103 +++-- .../Infrastructure/KuduAssert.cs | 25 ++ .../Vfs/VfsControllerBaseTest.cs | 10 +- .../App_Start/NinjectServices.cs | 5 - Kudu.Services/FetchHelpers/DropboxHelper.cs | 2 +- Kudu.Services/GitServer/InfoRefsController.cs | 2 +- .../SourceControl/LiveScmController.cs | 5 +- .../SourceControl/LiveScmEditorController.cs | 7 +- Kudu.TestHarness/TestRepository.cs | 5 +- build.cmd | 19 +- 27 files changed, 797 insertions(+), 208 deletions(-) delete mode 100644 .editorconfig create mode 100644 Kudu.Core/SourceControl/Git/IGitRepository.cs create mode 100644 Kudu.Core/SourceControl/Git/LibGit2SharpRepository.cs diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 096ff2565..000000000 --- a/.editorconfig +++ /dev/null @@ -1,15 +0,0 @@ -; Check http://editorconfig.org/ for more informations -; Top-most EditorConfig file -root = true - -; 4-column space indentation -[*] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true -insert_final_newline = true - -; Not change VS generated files -[*.{sln,csroj}] -trim_trailing_whitespace = false -insert_final_newline = false diff --git a/Kudu.Console/Program.cs b/Kudu.Console/Program.cs index f5a3ed6d8..e2b3fbaa7 100644 --- a/Kudu.Console/Program.cs +++ b/Kudu.Console/Program.cs @@ -83,7 +83,15 @@ private static int Main(string[] args) IBuildPropertyProvider buildPropertyProvider = new BuildPropertyProvider(); ISiteBuilderFactory builderFactory = new SiteBuilderFactory(buildPropertyProvider, env); - IRepository gitRepository = new GitExeRepository(env, settingsManager, traceFactory); + IRepository gitRepository; + if (settingsManager.UseLibGit2SharpRepository()) + { + gitRepository = new LibGit2SharpRepository(env, settingsManager, traceFactory); + } + else + { + gitRepository = new GitExeRepository(env, settingsManager, traceFactory); + } IServerConfiguration serverConfiguration = new ServerConfiguration(); IAnalytics analytics = new Analytics(settingsManager, serverConfiguration, traceFactory); diff --git a/Kudu.Contracts/Settings/DeploymentSettingsExtension.cs b/Kudu.Contracts/Settings/DeploymentSettingsExtension.cs index fa2939b1e..947560902 100644 --- a/Kudu.Contracts/Settings/DeploymentSettingsExtension.cs +++ b/Kudu.Contracts/Settings/DeploymentSettingsExtension.cs @@ -190,5 +190,10 @@ public static string GetSiteExtensionRemoteUrl(this IDeploymentSettingsManager s string value = settings.GetValue(SettingsKeys.SiteExtensionsFeedUrl); return !String.IsNullOrEmpty(value) ? value : DefaultSiteExtensionFeedUrl; } + + public static bool UseLibGit2SharpRepository(this IDeploymentSettingsManager settings) + { + return settings.GetValue(SettingsKeys.UseLibGit2SharpRepository) == "1"; + } } } \ No newline at end of file diff --git a/Kudu.Contracts/Settings/SettingsKeys.cs b/Kudu.Contracts/Settings/SettingsKeys.cs index 1423bf91b..c35e71894 100644 --- a/Kudu.Contracts/Settings/SettingsKeys.cs +++ b/Kudu.Contracts/Settings/SettingsKeys.cs @@ -23,6 +23,7 @@ public static class SettingsKeys public const string TargetPath = "SCM_TARGET_PATH"; public const string RepositoryPath = "SCM_REPOSITORY_PATH"; public const string NoRepository = "SCM_NO_REPOSITORY"; + public const string UseLibGit2SharpRepository = "SCM_USE_LIBGIT2SHARP_REPOSITORY"; // Free, Shared, Basic, Standard, Premium public const string WebSiteSku = "WEBSITE_SKU"; public const string WebJobsRestartTime = "WEBJOBS_RESTART_TIME"; diff --git a/Kudu.Contracts/SourceControl/IRepository.cs b/Kudu.Contracts/SourceControl/IRepository.cs index 5a0da0d91..cc1d8d49d 100644 --- a/Kudu.Contracts/SourceControl/IRepository.cs +++ b/Kudu.Contracts/SourceControl/IRepository.cs @@ -26,7 +26,7 @@ public interface IRepository : IFileFinder /// Commits new, modified and deleted files to the repository. /// /// True if one or more files were added to a changeset - bool Commit(string message, string authorName); + bool Commit(string message, string authorName, string emailAddress); void Update(string id); void Update(); void Push(); diff --git a/Kudu.Contracts/SourceControl/IRepositoryFactory.cs b/Kudu.Contracts/SourceControl/IRepositoryFactory.cs index 143b03b07..aa2fe77f2 100644 --- a/Kudu.Contracts/SourceControl/IRepositoryFactory.cs +++ b/Kudu.Contracts/SourceControl/IRepositoryFactory.cs @@ -7,5 +7,6 @@ public interface IRepositoryFactory IRepository EnsureRepository(RepositoryType repositoryType); IRepository GetRepository(); IRepository GetCustomRepository(); + IRepository GetGitRepository(); } } diff --git a/Kudu.Core.Test/GitRepositoryTest.cs b/Kudu.Core.Test/GitRepositoryTest.cs index 00f1aa95b..07c75f489 100644 --- a/Kudu.Core.Test/GitRepositoryTest.cs +++ b/Kudu.Core.Test/GitRepositoryTest.cs @@ -16,6 +16,47 @@ namespace Kudu.Core.Test { public class GitRepositoryTest { + [Fact] + public void ParseCommitParsesCommit() + { + string commitText = @"commit 307d8fe354ff30609decef49f91195e2e9719398 +Author: David Fowler +Date: Thu Jul 7 19:05:40 2011 -0700 + + Initial commit"; + + ChangeSet changeSet = GitExeRepository.ParseCommit(commitText.AsReader()); + + Assert.Equal("307d8fe354ff30609decef49f91195e2e9719398", changeSet.Id); + Assert.Equal("David Fowler", changeSet.AuthorName); + Assert.Equal("davidfowl@gmail.com", changeSet.AuthorEmail); + Assert.Equal("Initial commit", changeSet.Message); + } + + [Fact] + public void ParseCommitWithMultipleCommitsParsesOneCommit() + { + string commitText = @"commit d35697645e2472f5e327c0ec4b9f3489e806c276 +Author: John Doe +Date: Thu Jul 7 19:23:07 2011 -0700 + + Second commit + +commit 307d8fe354ff30609decef49f91195e2e9719398 +Author: David Fowler +Date: Thu Jul 7 19:05:40 2011 -0700 + + Initial commit +"; + + ChangeSet changeSet = GitExeRepository.ParseCommit(commitText.AsReader()); + + Assert.Equal("d35697645e2472f5e327c0ec4b9f3489e806c276", changeSet.Id); + Assert.Equal("John Doe", changeSet.AuthorName); + Assert.Null(changeSet.AuthorEmail); + Assert.Equal(@"Second commit", changeSet.Message); + } + [Theory] [InlineData(" a b c \\d e f", " a b c \\d e f")] [InlineData("\"\\303\\245benr\\303\\245.sln\"", "\"åbenrå.sln\"")] @@ -49,7 +90,7 @@ public void GitExecuteWithRetryTest(string message, int expect) // Test try { - repository.GitFetchWithRetry(() => + repository.ExecuteGenericGitCommandWithRetryAndCatchingWellKnownGitErrors(() => { ++actual; if (message == null) diff --git a/Kudu.Core.Test/NullRepositoryFacts.cs b/Kudu.Core.Test/NullRepositoryFacts.cs index 77a00e9cd..bf149266a 100644 --- a/Kudu.Core.Test/NullRepositoryFacts.cs +++ b/Kudu.Core.Test/NullRepositoryFacts.cs @@ -51,7 +51,7 @@ public void NullRepositoryCommitTests() var message = "this is testing"; var author = "john doe"; var email = "john.doe@live.com"; - var success = repository.Commit(message, author + " <" + email + ">"); + var success = repository.Commit(message, author, email); // Assert Assert.True(success); diff --git a/Kudu.Core/Kudu.Core.csproj b/Kudu.Core/Kudu.Core.csproj index 7d889fd05..e0390ea96 100644 --- a/Kudu.Core/Kudu.Core.csproj +++ b/Kudu.Core/Kudu.Core.csproj @@ -1,6 +1,6 @@  - + {5320177C-725A-44BD-8FA6-F88D9725B46C} @@ -8,10 +8,12 @@ Properties Kudu.Core Kudu.Core + 4423e462 - - ..\packages\LibGit2Sharp.0.20.0.0\lib\net40\LibGit2Sharp.dll + + False + ..\packages\LibGit2Sharp.0.20.2.0\lib\net40\LibGit2Sharp.dll False @@ -107,6 +109,8 @@ + + @@ -260,7 +264,7 @@ This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - +