Skip to content

Feature/netstandard2 (NETCore 2.1 support) #1422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ works out the [semantic version][semver] of the commit being built.
| **Docker FullFX** | [FullFX][dockerhub-fullfx] | - |

## Compatibility

GitVersion works on Mac, Linux with Mono and Windows.
GitVersion works Windows, Linux, and Mac.

Tip: If you get `System.TypeInitializationException: The type initializer for
'LibGit2Sharp.Core.NativeMethods' threw an exception. --->
Expand Down
4 changes: 2 additions & 2 deletions build/parameters.cake
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ public class BuildParameters
public string Target { get; private set; }
public string Configuration { get; private set; }

public string NetCoreVersion { get; private set; } = "netcoreapp2.0";
public string FullFxVersion { get; private set; } = "net40";
public string NetCoreVersion { get; private set; } = "netcoreapp2.1";
public string FullFxVersion { get; private set; } = "net461";

public bool EnabledUnitTests { get; private set; }
public bool EnabledPublishGem { get; private set; }
Expand Down
2 changes: 1 addition & 1 deletion build/paths.cake
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class BuildPaths

var artifactsDir = (DirectoryPath)(context.Directory("./artifacts") + context.Directory("v" + semVersion));
var artifactsBinDir = artifactsDir.Combine("bin");
var artifactsBinFullFxDir = artifactsBinDir.Combine("net40");
var artifactsBinFullFxDir = artifactsBinDir.Combine("net461");
var artifactsBinFullFxILMergeDir = artifactsBinFullFxDir.Combine("il-merge");
var artifactsBinFullFxPortableDir = artifactsBinFullFxDir.Combine("portable");
var artifactsBinFullFxCmdlineDir = artifactsBinFullFxDir.Combine("cmdline");
Expand Down
4 changes: 2 additions & 2 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<PackageVersion_GitToolsCore>1.3.1</PackageVersion_GitToolsCore>
<PackageVersion_YamlDotNet>5.2.1</PackageVersion_YamlDotNet>
<PackageVersion_LibGit2SharpNativeBinaries>[1.0.185]</PackageVersion_LibGit2SharpNativeBinaries>
<PackageVersion_LibGit2Sharp>0.26.0-preview-0070</PackageVersion_LibGit2Sharp>
<PackageVersion_LibGit2SharpNativeBinaries>[1.0.258]</PackageVersion_LibGit2SharpNativeBinaries>
</PropertyGroup>
</Project>
325 changes: 325 additions & 0 deletions src/GitTools.Core.Tests/Git/DynamicRepositoriesTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,325 @@
namespace GitTools.Tests.Git
{
using System;
using System.IO;
using System.Linq;
using GitTools.Git;
using IO;
using LibGit2Sharp;
using NUnit.Framework;
using Shouldly;
using Testing;

[TestFixture]
public class DynamicRepositoriesTests
{
const string DefaultBranchName = "master";
const string SpecificBranchName = "feature/foo";

[Test]
[TestCase(DefaultBranchName, DefaultBranchName)]
[TestCase(SpecificBranchName, SpecificBranchName)]
[Category("NoMono")]
public void WorksCorrectlyWithRemoteRepository(string branchName, string expectedBranchName)
{
var repoName = Guid.NewGuid().ToString();
var tempPath = Path.GetTempPath();
var tempDir = Path.Combine(tempPath, repoName);
Directory.CreateDirectory(tempDir);
string dynamicRepositoryPath = null;

try
{
using (var fixture = new EmptyRepositoryFixture())
{
var expectedDynamicRepoLocation = Path.Combine(tempPath, fixture.RepositoryPath.Split(Path.DirectorySeparatorChar).Last());

fixture.Repository.MakeCommits(5);
fixture.Repository.CreateFileAndCommit("TestFile.txt");

var branch = fixture.Repository.CreateBranch(SpecificBranchName);

// Copy contents into working directory
File.Copy(Path.Combine(fixture.RepositoryPath, "TestFile.txt"), Path.Combine(tempDir, "TestFile.txt"));

var repositoryInfo = new RepositoryInfo
{
Url = fixture.RepositoryPath
};

using (var dynamicRepository = DynamicRepositories.CreateOrOpen(repositoryInfo, tempPath, branchName, branch.Tip.Sha))
{
dynamicRepositoryPath = dynamicRepository.Repository.Info.Path;
dynamicRepository.Repository.Info.Path.ShouldBe(Path.Combine(expectedDynamicRepoLocation, ".git\\"));

var currentBranch = dynamicRepository.Repository.Head.CanonicalName;

currentBranch.ShouldEndWith(expectedBranchName);
}
}
}
finally
{
Directory.Delete(tempDir, true);

if (dynamicRepositoryPath != null)
{
DeleteHelper.DeleteGitRepository(dynamicRepositoryPath);
}
}
}

[Test]
public void UpdatesExistingDynamicRepository()
{
var repoName = Guid.NewGuid().ToString();
var tempPath = Path.GetTempPath();
var tempDir = Path.Combine(tempPath, repoName);
Directory.CreateDirectory(tempDir);
string dynamicRepositoryPath = null;

try
{
using (var mainRepositoryFixture = new EmptyRepositoryFixture())
{
var commit = mainRepositoryFixture.Repository.MakeACommit();

var repositoryInfo = new RepositoryInfo
{
Url = mainRepositoryFixture.RepositoryPath
};

using (var dynamicRepository = DynamicRepositories.CreateOrOpen(repositoryInfo, tempPath, "master", commit.Sha))
{
dynamicRepositoryPath = dynamicRepository.Repository.Info.Path;
}

var newCommit = mainRepositoryFixture.Repository.MakeACommit();

using (var dynamicRepository = DynamicRepositories.CreateOrOpen(repositoryInfo, tempPath, "master", newCommit.Sha))
{
dynamicRepository.Repository.Info.Path.ShouldBe(dynamicRepositoryPath);
dynamicRepository.Repository.Commits.ShouldContain(c => c.Sha == newCommit.Sha);
}
}
}
finally
{
Directory.Delete(tempDir, true);

if (dynamicRepositoryPath != null)
{
DeleteHelper.DeleteGitRepository(dynamicRepositoryPath);
}
}
}

[Test]
[Category("NoMono")]
public void PicksAnotherDirectoryNameWhenDynamicRepoFolderTaken()
{
var repoName = Guid.NewGuid().ToString();
var tempPath = Path.GetTempPath();
var tempDir = Path.Combine(tempPath, repoName);
Directory.CreateDirectory(tempDir);
string expectedDynamicRepoLocation = null;

try
{
using (var fixture = new EmptyRepositoryFixture())
{
var head = fixture.Repository.CreateFileAndCommit("TestFile.txt");
File.Copy(Path.Combine(fixture.RepositoryPath, "TestFile.txt"), Path.Combine(tempDir, "TestFile.txt"));
expectedDynamicRepoLocation = Path.Combine(tempPath, fixture.RepositoryPath.Split(Path.DirectorySeparatorChar).Last());
Directory.CreateDirectory(expectedDynamicRepoLocation);

var repositoryInfo = new RepositoryInfo
{
Url = fixture.RepositoryPath
};

using (var dynamicRepository = DynamicRepositories.CreateOrOpen(repositoryInfo, tempPath, "master", head.Sha))
{
dynamicRepository.Repository.Info.Path.ShouldBe(Path.Combine(expectedDynamicRepoLocation + "_1", ".git\\"));
}
}
}
finally
{
DeleteHelper.DeleteDirectory(tempDir, true);
if (expectedDynamicRepoLocation != null)
{
DeleteHelper.DeleteDirectory(expectedDynamicRepoLocation, true);
}

if (expectedDynamicRepoLocation != null)
{
DeleteHelper.DeleteGitRepository(expectedDynamicRepoLocation + "_1");
}
}
}

[Test]
[Category("NoMono")]
public void PicksAnotherDirectoryNameWhenDynamicRepoFolderIsInUse()
{
var tempPath = Path.GetTempPath();
var expectedDynamicRepoLocation = default(string);
var expectedDynamicRepo2Location = default(string);

try
{
using (var fixture = new EmptyRepositoryFixture())
{
var head = fixture.Repository.CreateFileAndCommit("TestFile.txt");
var repositoryInfo = new RepositoryInfo
{
Url = fixture.RepositoryPath
};

using (var dynamicRepository = DynamicRepositories.CreateOrOpen(repositoryInfo, tempPath, "master", head.Sha))
using (var dynamicRepository2 = DynamicRepositories.CreateOrOpen(repositoryInfo, tempPath, "master", head.Sha))
{
expectedDynamicRepoLocation = dynamicRepository.Repository.Info.Path;
expectedDynamicRepo2Location = dynamicRepository2.Repository.Info.Path;
dynamicRepository.Repository.Info.Path.ShouldNotBe(dynamicRepository2.Repository.Info.Path);
}
}
}
finally
{
if (expectedDynamicRepoLocation != null)
{
DeleteHelper.DeleteDirectory(expectedDynamicRepoLocation, true);
}

if (expectedDynamicRepo2Location != null)
{
DeleteHelper.DeleteGitRepository(expectedDynamicRepo2Location);
}
}
}

[Test]
public void ThrowsExceptionWhenNotEnoughInfo()
{
var tempDir = Path.GetTempPath();

var repositoryInfo = new RepositoryInfo
{
Url = tempDir
};

Should.Throw<Exception>(() => DynamicRepositories.CreateOrOpen(repositoryInfo, tempDir, null, null));
}

[Test]
public void UsingDynamicRepositoryWithFeatureBranchWorks()
{
var repoName = Guid.NewGuid().ToString();
var tempPath = Path.GetTempPath();
var tempDir = Path.Combine(tempPath, repoName);
Directory.CreateDirectory(tempDir);

try
{
using (var mainRepositoryFixture = new EmptyRepositoryFixture())
{
var commit = mainRepositoryFixture.Repository.MakeACommit();

var repositoryInfo = new RepositoryInfo
{
Url = mainRepositoryFixture.RepositoryPath
};

Commands.Checkout(mainRepositoryFixture.Repository, mainRepositoryFixture.Repository.CreateBranch("feature1"));

Should.NotThrow(() =>
{
using (DynamicRepositories.CreateOrOpen(repositoryInfo, tempPath, "feature1", commit.Sha))
{
}
});
}
}
finally
{
Directory.Delete(tempDir, true);
}
}

[Test]
public void UsingDynamicRepositoryWithoutTargetBranchFails()
{
var tempPath = Path.GetTempPath();

using (var mainRepositoryFixture = new EmptyRepositoryFixture())
{
mainRepositoryFixture.Repository.MakeACommit();

var repositoryInfo = new RepositoryInfo
{
Url = mainRepositoryFixture.RepositoryPath
};

Should.Throw<GitToolsException>(() =>
{
using (DynamicRepositories.CreateOrOpen(repositoryInfo, tempPath, null, null))
{
}
});
}
}

[Test]
public void UsingDynamicRepositoryWithoutTargetBranchCommitFails()
{
var tempPath = Path.GetTempPath();

using (var mainRepositoryFixture = new EmptyRepositoryFixture())
{
mainRepositoryFixture.Repository.MakeACommit();

var repositoryInfo = new RepositoryInfo
{
Url = mainRepositoryFixture.RepositoryPath
};

Should.Throw<GitToolsException>(() =>
{
using (DynamicRepositories.CreateOrOpen(repositoryInfo, tempPath, "master", null))
{
}
});
}
}

[Test]
public void TestErrorThrownForInvalidRepository()
{
var repoName = Guid.NewGuid().ToString();
var tempPath = Path.GetTempPath();
var tempDir = Path.Combine(tempPath, repoName);
Directory.CreateDirectory(tempDir);

try
{
var repositoryInfo = new RepositoryInfo
{
Url = "http://127.0.0.1/testrepo.git"
};

Should.Throw<Exception>(() =>
{
using (DynamicRepositories.CreateOrOpen(repositoryInfo, tempPath, "master", "sha"))
{
}
});
}
finally
{
Directory.Delete(tempDir, true);
}
}
}
}
Loading