Skip to content

Commit cf2ccfa

Browse files
authored
Merge pull request #1422 from kll/feature/netstandard2
Feature/netstandard2 (NETCore 2.1 support)
2 parents 9b22496 + 031834e commit cf2ccfa

File tree

80 files changed

+7539
-273
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+7539
-273
lines changed

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ works out the [semantic version][semver] of the commit being built.
2727
| **Docker FullFX** | [FullFX][dockerhub-fullfx] | - |
2828

2929
## Compatibility
30-
31-
GitVersion works on Mac, Linux with Mono and Windows.
30+
GitVersion works Windows, Linux, and Mac.
3231

3332
Tip: If you get `System.TypeInitializationException: The type initializer for
3433
'LibGit2Sharp.Core.NativeMethods' threw an exception. --->

build/parameters.cake

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ public class BuildParameters
88
public string Target { get; private set; }
99
public string Configuration { get; private set; }
1010

11-
public string NetCoreVersion { get; private set; } = "netcoreapp2.0";
12-
public string FullFxVersion { get; private set; } = "net40";
11+
public string NetCoreVersion { get; private set; } = "netcoreapp2.1";
12+
public string FullFxVersion { get; private set; } = "net461";
1313

1414
public bool EnabledUnitTests { get; private set; }
1515
public bool EnabledPublishGem { get; private set; }

build/paths.cake

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class BuildPaths
2626

2727
var artifactsDir = (DirectoryPath)(context.Directory("./artifacts") + context.Directory("v" + semVersion));
2828
var artifactsBinDir = artifactsDir.Combine("bin");
29-
var artifactsBinFullFxDir = artifactsBinDir.Combine("net40");
29+
var artifactsBinFullFxDir = artifactsBinDir.Combine("net461");
3030
var artifactsBinFullFxILMergeDir = artifactsBinFullFxDir.Combine("il-merge");
3131
var artifactsBinFullFxPortableDir = artifactsBinFullFxDir.Combine("portable");
3232
var artifactsBinFullFxCmdlineDir = artifactsBinFullFxDir.Combine("cmdline");

src/Directory.Build.props

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22
<PropertyGroup>
3-
<PackageVersion_GitToolsCore>1.3.1</PackageVersion_GitToolsCore>
43
<PackageVersion_YamlDotNet>5.2.1</PackageVersion_YamlDotNet>
5-
<PackageVersion_LibGit2SharpNativeBinaries>[1.0.185]</PackageVersion_LibGit2SharpNativeBinaries>
4+
<PackageVersion_LibGit2Sharp>0.26.0-preview-0070</PackageVersion_LibGit2Sharp>
5+
<PackageVersion_LibGit2SharpNativeBinaries>[1.0.258]</PackageVersion_LibGit2SharpNativeBinaries>
66
</PropertyGroup>
77
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,325 @@
1+
namespace GitTools.Tests.Git
2+
{
3+
using System;
4+
using System.IO;
5+
using System.Linq;
6+
using GitTools.Git;
7+
using IO;
8+
using LibGit2Sharp;
9+
using NUnit.Framework;
10+
using Shouldly;
11+
using Testing;
12+
13+
[TestFixture]
14+
public class DynamicRepositoriesTests
15+
{
16+
const string DefaultBranchName = "master";
17+
const string SpecificBranchName = "feature/foo";
18+
19+
[Test]
20+
[TestCase(DefaultBranchName, DefaultBranchName)]
21+
[TestCase(SpecificBranchName, SpecificBranchName)]
22+
[Category("NoMono")]
23+
public void WorksCorrectlyWithRemoteRepository(string branchName, string expectedBranchName)
24+
{
25+
var repoName = Guid.NewGuid().ToString();
26+
var tempPath = Path.GetTempPath();
27+
var tempDir = Path.Combine(tempPath, repoName);
28+
Directory.CreateDirectory(tempDir);
29+
string dynamicRepositoryPath = null;
30+
31+
try
32+
{
33+
using (var fixture = new EmptyRepositoryFixture())
34+
{
35+
var expectedDynamicRepoLocation = Path.Combine(tempPath, fixture.RepositoryPath.Split(Path.DirectorySeparatorChar).Last());
36+
37+
fixture.Repository.MakeCommits(5);
38+
fixture.Repository.CreateFileAndCommit("TestFile.txt");
39+
40+
var branch = fixture.Repository.CreateBranch(SpecificBranchName);
41+
42+
// Copy contents into working directory
43+
File.Copy(Path.Combine(fixture.RepositoryPath, "TestFile.txt"), Path.Combine(tempDir, "TestFile.txt"));
44+
45+
var repositoryInfo = new RepositoryInfo
46+
{
47+
Url = fixture.RepositoryPath
48+
};
49+
50+
using (var dynamicRepository = DynamicRepositories.CreateOrOpen(repositoryInfo, tempPath, branchName, branch.Tip.Sha))
51+
{
52+
dynamicRepositoryPath = dynamicRepository.Repository.Info.Path;
53+
dynamicRepository.Repository.Info.Path.ShouldBe(Path.Combine(expectedDynamicRepoLocation, ".git\\"));
54+
55+
var currentBranch = dynamicRepository.Repository.Head.CanonicalName;
56+
57+
currentBranch.ShouldEndWith(expectedBranchName);
58+
}
59+
}
60+
}
61+
finally
62+
{
63+
Directory.Delete(tempDir, true);
64+
65+
if (dynamicRepositoryPath != null)
66+
{
67+
DeleteHelper.DeleteGitRepository(dynamicRepositoryPath);
68+
}
69+
}
70+
}
71+
72+
[Test]
73+
public void UpdatesExistingDynamicRepository()
74+
{
75+
var repoName = Guid.NewGuid().ToString();
76+
var tempPath = Path.GetTempPath();
77+
var tempDir = Path.Combine(tempPath, repoName);
78+
Directory.CreateDirectory(tempDir);
79+
string dynamicRepositoryPath = null;
80+
81+
try
82+
{
83+
using (var mainRepositoryFixture = new EmptyRepositoryFixture())
84+
{
85+
var commit = mainRepositoryFixture.Repository.MakeACommit();
86+
87+
var repositoryInfo = new RepositoryInfo
88+
{
89+
Url = mainRepositoryFixture.RepositoryPath
90+
};
91+
92+
using (var dynamicRepository = DynamicRepositories.CreateOrOpen(repositoryInfo, tempPath, "master", commit.Sha))
93+
{
94+
dynamicRepositoryPath = dynamicRepository.Repository.Info.Path;
95+
}
96+
97+
var newCommit = mainRepositoryFixture.Repository.MakeACommit();
98+
99+
using (var dynamicRepository = DynamicRepositories.CreateOrOpen(repositoryInfo, tempPath, "master", newCommit.Sha))
100+
{
101+
dynamicRepository.Repository.Info.Path.ShouldBe(dynamicRepositoryPath);
102+
dynamicRepository.Repository.Commits.ShouldContain(c => c.Sha == newCommit.Sha);
103+
}
104+
}
105+
}
106+
finally
107+
{
108+
Directory.Delete(tempDir, true);
109+
110+
if (dynamicRepositoryPath != null)
111+
{
112+
DeleteHelper.DeleteGitRepository(dynamicRepositoryPath);
113+
}
114+
}
115+
}
116+
117+
[Test]
118+
[Category("NoMono")]
119+
public void PicksAnotherDirectoryNameWhenDynamicRepoFolderTaken()
120+
{
121+
var repoName = Guid.NewGuid().ToString();
122+
var tempPath = Path.GetTempPath();
123+
var tempDir = Path.Combine(tempPath, repoName);
124+
Directory.CreateDirectory(tempDir);
125+
string expectedDynamicRepoLocation = null;
126+
127+
try
128+
{
129+
using (var fixture = new EmptyRepositoryFixture())
130+
{
131+
var head = fixture.Repository.CreateFileAndCommit("TestFile.txt");
132+
File.Copy(Path.Combine(fixture.RepositoryPath, "TestFile.txt"), Path.Combine(tempDir, "TestFile.txt"));
133+
expectedDynamicRepoLocation = Path.Combine(tempPath, fixture.RepositoryPath.Split(Path.DirectorySeparatorChar).Last());
134+
Directory.CreateDirectory(expectedDynamicRepoLocation);
135+
136+
var repositoryInfo = new RepositoryInfo
137+
{
138+
Url = fixture.RepositoryPath
139+
};
140+
141+
using (var dynamicRepository = DynamicRepositories.CreateOrOpen(repositoryInfo, tempPath, "master", head.Sha))
142+
{
143+
dynamicRepository.Repository.Info.Path.ShouldBe(Path.Combine(expectedDynamicRepoLocation + "_1", ".git\\"));
144+
}
145+
}
146+
}
147+
finally
148+
{
149+
DeleteHelper.DeleteDirectory(tempDir, true);
150+
if (expectedDynamicRepoLocation != null)
151+
{
152+
DeleteHelper.DeleteDirectory(expectedDynamicRepoLocation, true);
153+
}
154+
155+
if (expectedDynamicRepoLocation != null)
156+
{
157+
DeleteHelper.DeleteGitRepository(expectedDynamicRepoLocation + "_1");
158+
}
159+
}
160+
}
161+
162+
[Test]
163+
[Category("NoMono")]
164+
public void PicksAnotherDirectoryNameWhenDynamicRepoFolderIsInUse()
165+
{
166+
var tempPath = Path.GetTempPath();
167+
var expectedDynamicRepoLocation = default(string);
168+
var expectedDynamicRepo2Location = default(string);
169+
170+
try
171+
{
172+
using (var fixture = new EmptyRepositoryFixture())
173+
{
174+
var head = fixture.Repository.CreateFileAndCommit("TestFile.txt");
175+
var repositoryInfo = new RepositoryInfo
176+
{
177+
Url = fixture.RepositoryPath
178+
};
179+
180+
using (var dynamicRepository = DynamicRepositories.CreateOrOpen(repositoryInfo, tempPath, "master", head.Sha))
181+
using (var dynamicRepository2 = DynamicRepositories.CreateOrOpen(repositoryInfo, tempPath, "master", head.Sha))
182+
{
183+
expectedDynamicRepoLocation = dynamicRepository.Repository.Info.Path;
184+
expectedDynamicRepo2Location = dynamicRepository2.Repository.Info.Path;
185+
dynamicRepository.Repository.Info.Path.ShouldNotBe(dynamicRepository2.Repository.Info.Path);
186+
}
187+
}
188+
}
189+
finally
190+
{
191+
if (expectedDynamicRepoLocation != null)
192+
{
193+
DeleteHelper.DeleteDirectory(expectedDynamicRepoLocation, true);
194+
}
195+
196+
if (expectedDynamicRepo2Location != null)
197+
{
198+
DeleteHelper.DeleteGitRepository(expectedDynamicRepo2Location);
199+
}
200+
}
201+
}
202+
203+
[Test]
204+
public void ThrowsExceptionWhenNotEnoughInfo()
205+
{
206+
var tempDir = Path.GetTempPath();
207+
208+
var repositoryInfo = new RepositoryInfo
209+
{
210+
Url = tempDir
211+
};
212+
213+
Should.Throw<Exception>(() => DynamicRepositories.CreateOrOpen(repositoryInfo, tempDir, null, null));
214+
}
215+
216+
[Test]
217+
public void UsingDynamicRepositoryWithFeatureBranchWorks()
218+
{
219+
var repoName = Guid.NewGuid().ToString();
220+
var tempPath = Path.GetTempPath();
221+
var tempDir = Path.Combine(tempPath, repoName);
222+
Directory.CreateDirectory(tempDir);
223+
224+
try
225+
{
226+
using (var mainRepositoryFixture = new EmptyRepositoryFixture())
227+
{
228+
var commit = mainRepositoryFixture.Repository.MakeACommit();
229+
230+
var repositoryInfo = new RepositoryInfo
231+
{
232+
Url = mainRepositoryFixture.RepositoryPath
233+
};
234+
235+
Commands.Checkout(mainRepositoryFixture.Repository, mainRepositoryFixture.Repository.CreateBranch("feature1"));
236+
237+
Should.NotThrow(() =>
238+
{
239+
using (DynamicRepositories.CreateOrOpen(repositoryInfo, tempPath, "feature1", commit.Sha))
240+
{
241+
}
242+
});
243+
}
244+
}
245+
finally
246+
{
247+
Directory.Delete(tempDir, true);
248+
}
249+
}
250+
251+
[Test]
252+
public void UsingDynamicRepositoryWithoutTargetBranchFails()
253+
{
254+
var tempPath = Path.GetTempPath();
255+
256+
using (var mainRepositoryFixture = new EmptyRepositoryFixture())
257+
{
258+
mainRepositoryFixture.Repository.MakeACommit();
259+
260+
var repositoryInfo = new RepositoryInfo
261+
{
262+
Url = mainRepositoryFixture.RepositoryPath
263+
};
264+
265+
Should.Throw<GitToolsException>(() =>
266+
{
267+
using (DynamicRepositories.CreateOrOpen(repositoryInfo, tempPath, null, null))
268+
{
269+
}
270+
});
271+
}
272+
}
273+
274+
[Test]
275+
public void UsingDynamicRepositoryWithoutTargetBranchCommitFails()
276+
{
277+
var tempPath = Path.GetTempPath();
278+
279+
using (var mainRepositoryFixture = new EmptyRepositoryFixture())
280+
{
281+
mainRepositoryFixture.Repository.MakeACommit();
282+
283+
var repositoryInfo = new RepositoryInfo
284+
{
285+
Url = mainRepositoryFixture.RepositoryPath
286+
};
287+
288+
Should.Throw<GitToolsException>(() =>
289+
{
290+
using (DynamicRepositories.CreateOrOpen(repositoryInfo, tempPath, "master", null))
291+
{
292+
}
293+
});
294+
}
295+
}
296+
297+
[Test]
298+
public void TestErrorThrownForInvalidRepository()
299+
{
300+
var repoName = Guid.NewGuid().ToString();
301+
var tempPath = Path.GetTempPath();
302+
var tempDir = Path.Combine(tempPath, repoName);
303+
Directory.CreateDirectory(tempDir);
304+
305+
try
306+
{
307+
var repositoryInfo = new RepositoryInfo
308+
{
309+
Url = "http://127.0.0.1/testrepo.git"
310+
};
311+
312+
Should.Throw<Exception>(() =>
313+
{
314+
using (DynamicRepositories.CreateOrOpen(repositoryInfo, tempPath, "master", "sha"))
315+
{
316+
}
317+
});
318+
}
319+
finally
320+
{
321+
Directory.Delete(tempDir, true);
322+
}
323+
}
324+
}
325+
}

0 commit comments

Comments
 (0)