Skip to content

Commit

Permalink
support both libgit2sharp and gitexe at the same time and update test…
Browse files Browse the repository at this point in the history
… cases
  • Loading branch information
ahmelsayed committed Jan 29, 2015
1 parent 9e26833 commit 7e29fa2
Show file tree
Hide file tree
Showing 27 changed files with 797 additions and 208 deletions.
15 changes: 0 additions & 15 deletions .editorconfig

This file was deleted.

10 changes: 9 additions & 1 deletion Kudu.Console/Program.cs
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions Kudu.Contracts/Settings/DeploymentSettingsExtension.cs
Expand Up @@ -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";
}
}
}
1 change: 1 addition & 0 deletions Kudu.Contracts/Settings/SettingsKeys.cs
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion Kudu.Contracts/SourceControl/IRepository.cs
Expand Up @@ -26,7 +26,7 @@ public interface IRepository : IFileFinder
/// Commits new, modified and deleted files to the repository.
/// </summary>
/// <returns>True if one or more files were added to a changeset</returns>
bool Commit(string message, string authorName);
bool Commit(string message, string authorName, string emailAddress);
void Update(string id);
void Update();
void Push();
Expand Down
1 change: 1 addition & 0 deletions Kudu.Contracts/SourceControl/IRepositoryFactory.cs
Expand Up @@ -7,5 +7,6 @@ public interface IRepositoryFactory
IRepository EnsureRepository(RepositoryType repositoryType);
IRepository GetRepository();
IRepository GetCustomRepository();
IRepository GetGitRepository();
}
}
43 changes: 42 additions & 1 deletion Kudu.Core.Test/GitRepositoryTest.cs
Expand Up @@ -16,6 +16,47 @@ namespace Kudu.Core.Test
{
public class GitRepositoryTest
{
[Fact]
public void ParseCommitParsesCommit()
{
string commitText = @"commit 307d8fe354ff30609decef49f91195e2e9719398
Author: David Fowler <davidfowl@gmail.com>
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 <davidfowl@gmail.com>
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\"")]
Expand Down Expand Up @@ -49,7 +90,7 @@ public void GitExecuteWithRetryTest(string message, int expect)
// Test
try
{
repository.GitFetchWithRetry(() =>
repository.ExecuteGenericGitCommandWithRetryAndCatchingWellKnownGitErrors(() =>
{
++actual;
if (message == null)
Expand Down
2 changes: 1 addition & 1 deletion Kudu.Core.Test/NullRepositoryFacts.cs
Expand Up @@ -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);
Expand Down
12 changes: 8 additions & 4 deletions Kudu.Core/Kudu.Core.csproj
@@ -1,17 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\LibGit2Sharp.0.20.0.0\build\net40\LibGit2Sharp.props" Condition="Exists('..\packages\LibGit2Sharp.0.20.0.0\build\net40\LibGit2Sharp.props')" />
<Import Project="..\packages\LibGit2Sharp.0.20.2.0\build\net40\LibGit2Sharp.props" Condition="Exists('..\packages\LibGit2Sharp.0.20.2.0\build\net40\LibGit2Sharp.props')" />
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory),Kudu.sln))\Build\Kudu.targets" />
<PropertyGroup>
<ProjectGuid>{5320177C-725A-44BD-8FA6-F88D9725B46C}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Kudu.Core</RootNamespace>
<AssemblyName>Kudu.Core</AssemblyName>
<NuGetPackageImportStamp>4423e462</NuGetPackageImportStamp>
</PropertyGroup>
<ItemGroup>
<Reference Include="LibGit2Sharp">
<HintPath>..\packages\LibGit2Sharp.0.20.0.0\lib\net40\LibGit2Sharp.dll</HintPath>
<Reference Include="LibGit2Sharp, Version=0.20.2.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\LibGit2Sharp.0.20.2.0\lib\net40\LibGit2Sharp.dll</HintPath>
</Reference>
<Reference Include="Mercurial.Net, Version=1.1.1.607, Culture=neutral, PublicKeyToken=9e2fabf3af85dba9, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
Expand Down Expand Up @@ -107,6 +109,8 @@
<Compile Include="Settings\DiagnosticsSettingsManager.cs" />
<Compile Include="SiteExtensions\SemanticVersion.cs" />
<Compile Include="SiteExtensions\SiteExtensionManager.cs" />
<Compile Include="SourceControl\Git\IGitRepository.cs" />
<Compile Include="SourceControl\Git\LibGit2SharpRepository.cs" />
<Compile Include="Tracing\KuduEventSource.cs" />
<Compile Include="Tracing\KuduSiteExtensionLogEvent.cs" />
<Compile Include="Tracing\NullTracer.cs" />
Expand Down Expand Up @@ -260,7 +264,7 @@
<ErrorText>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}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Diagnostics.Tracing.EventRegister.1.0.26\build\Microsoft.Diagnostics.Tracing.EventRegister.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Diagnostics.Tracing.EventRegister.1.0.26\build\Microsoft.Diagnostics.Tracing.EventRegister.targets'))" />
<Error Condition="!Exists('..\packages\LibGit2Sharp.0.20.0.0\build\net40\LibGit2Sharp.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\LibGit2Sharp.0.20.0.0\build\net40\LibGit2Sharp.props'))" />
<Error Condition="!Exists('..\packages\LibGit2Sharp.0.20.2.0\build\net40\LibGit2Sharp.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\LibGit2Sharp.0.20.2.0\build\net40\LibGit2Sharp.props'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down

0 comments on commit 7e29fa2

Please sign in to comment.