Skip to content

Commit e2b8860

Browse files
committed
cleanup
1 parent 12438e2 commit e2b8860

15 files changed

+409
-440
lines changed

GitVersionCore.Tests/ConfigProviderTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Reflection;
44
using GitVersion;
55
using GitVersion.Helpers;
6-
using GitVersionCore.Tests;
76
using NUnit.Framework;
87
using Shouldly;
98
using YamlDotNet.Serialization;
Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,48 @@
11
using System;
22

3-
namespace GitVersionCore.Tests.Fixtures
4-
{
53
using GitVersion;
64
using LibGit2Sharp;
75

8-
public class RemoteRepositoryFixture : RepositoryFixtureBase
9-
{
10-
public string LocalRepositoryPath;
11-
public IRepository LocalRepository;
12-
13-
public RemoteRepositoryFixture(Config configuration)
14-
: base(CreateNewRepository, configuration)
15-
{
16-
17-
CloneRepository();
18-
}
6+
public class RemoteRepositoryFixture : RepositoryFixtureBase
7+
{
8+
public string LocalRepositoryPath;
9+
public IRepository LocalRepository;
1910

20-
11+
public RemoteRepositoryFixture(Config configuration)
12+
: base(CreateNewRepository, configuration)
13+
{
14+
CloneRepository();
15+
}
2116

22-
static IRepository CreateNewRepository(string path)
23-
{
24-
LibGit2Sharp.Repository.Init(path);
25-
Console.WriteLine("Created git repository at '{0}'", path);
17+
static IRepository CreateNewRepository(string path)
18+
{
19+
LibGit2Sharp.Repository.Init(path);
20+
Console.WriteLine("Created git repository at '{0}'", path);
2621

27-
var repo = new Repository(path);
28-
repo.MakeCommits(5);
29-
return repo;
30-
}
22+
var repo = new Repository(path);
23+
repo.MakeCommits(5);
24+
return repo;
25+
}
3126

27+
void CloneRepository()
28+
{
29+
LocalRepositoryPath = PathHelper.GetTempPath();
30+
LibGit2Sharp.Repository.Clone(RepositoryPath, LocalRepositoryPath);
31+
LocalRepository = new Repository(LocalRepositoryPath);
32+
}
3233

33-
void CloneRepository()
34+
public override void Dispose()
35+
{
36+
LocalRepository.Dispose();
37+
try
3438
{
35-
LocalRepositoryPath = PathHelper.GetTempPath();
36-
LibGit2Sharp.Repository.Clone(RepositoryPath, LocalRepositoryPath);
37-
LocalRepository = new Repository(LocalRepositoryPath);
39+
DirectoryHelper.DeleteDirectory(LocalRepositoryPath);
3840
}
39-
40-
41-
public override void Dispose()
41+
catch (Exception e)
4242
{
43-
LocalRepository.Dispose();
44-
try
45-
{
46-
DirectoryHelper.DeleteDirectory(LocalRepositoryPath);
47-
}
48-
catch (Exception e)
49-
{
50-
Console.WriteLine("Failed to clean up repository path at {0}. Received exception: {1}", RepositoryPath, e.Message);
51-
}
52-
53-
base.Dispose();
43+
Console.WriteLine("Failed to clean up repository path at {0}. Received exception: {1}", RepositoryPath, e.Message);
5444
}
45+
46+
base.Dispose();
5547
}
56-
}
48+
}

GitVersionCore.Tests/GitVersionCore.Tests.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,20 @@
7878
<Compile Include="Fixtures\BaseGitFlowRepositoryFixture.cs" />
7979
<Compile Include="IntegrationTests\RemoteRepositoryTests.cs" />
8080
<Compile Include="IntegrationTests\GitFlow\DevelopScenarios.cs" />
81-
<Compile Include="IntegrationTests\GitFlow\FeatureBranchTests.cs" />
82-
<Compile Include="IntegrationTests\GitFlow\SupportBranchScenarios.cs" />
81+
<Compile Include="IntegrationTests\GitFlow\GitFlowFeatureBranchTests.cs" />
82+
<Compile Include="IntegrationTests\GitFlow\GitFlowSupportBranchScenarios.cs" />
8383
<Compile Include="IntegrationTests\GitFlow\MetaDataByCommitScenarios.cs" />
8484
<Compile Include="IntegrationTests\GitFlow\PatchScenarios.cs" />
8585
<Compile Include="IntegrationTests\GitFlow\ReleaseBranchTests.cs" />
8686
<Compile Include="IntegrationTests\GitFlow\SwitchingToGitFlowScenarios.cs" />
8787
<Compile Include="IntegrationTests\GitFlow\WikiScenarios.cs" />
88-
<Compile Include="IntegrationTests\GitHubFlow\FeatureBranchTests.cs" />
88+
<Compile Include="IntegrationTests\GitHubFlow\GitHubFlowFeatureBranchTests.cs" />
8989
<Compile Include="IntegrationTests\GitHubFlow\OtherBranchTests.cs" />
9090
<Compile Include="IntegrationTests\GitHubFlow\ReleaseBranchTests.cs" />
9191
<Compile Include="Helpers\Constants.cs" />
9292
<Compile Include="Helpers\NextVersionWriter.cs" />
9393
<Compile Include="InformationalVersionBuilderTests.cs" />
94-
<Compile Include="IntegrationTests\GitHubFlow\SupportBranchScenarios.cs" />
94+
<Compile Include="IntegrationTests\GitHubFlow\GitHubFlowSupportBranchScenarios.cs" />
9595
<Compile Include="JsonVersionBuilderTests.cs" />
9696
<Compile Include="ModuleInitializer.cs" />
9797
<Compile Include="Fixtures\EmptyRepositoryFixture.cs" />

GitVersionCore.Tests/IntegrationTests/GitFlow/FeatureBranchTests.cs renamed to GitVersionCore.Tests/IntegrationTests/GitFlow/GitFlowFeatureBranchTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using NUnit.Framework;
44

55
[TestFixture]
6-
public class FeatureBranchTests
6+
public class GitFlowFeatureBranchTests
77
{
88
[Test]
99
public void ShouldNotUseNumberInFeatureBranchAsPreReleaseNumber()
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using LibGit2Sharp;
2+
using NUnit.Framework;
3+
4+
[TestFixture]
5+
public class GitFlowSupportBranchScenarios
6+
{
7+
[Test]
8+
public void SupportIsCalculatedCorrectly()
9+
{
10+
using (var fixture = new BaseGitFlowRepositoryFixture("1.1.0"))
11+
{
12+
// Create 2.0.0 release
13+
fixture.Repository.CreateBranch("release-2.0.0").Checkout();
14+
fixture.Repository.MakeCommits(2);
15+
16+
// Merge into develop and master
17+
fixture.Repository.Checkout("master");
18+
fixture.Repository.MergeNoFF("release-2.0.0");
19+
fixture.Repository.ApplyTag("2.0.0");
20+
fixture.Repository.Checkout("develop");
21+
fixture.Repository.MergeNoFF("release-2.0.0");
22+
fixture.AssertFullSemver("2.1.0-unstable.0+0");
23+
24+
// Now lets support 1.x release
25+
fixture.Repository.Checkout("1.1.0");
26+
fixture.Repository.CreateBranch("support/1.0.0").Checkout();
27+
fixture.AssertFullSemver("1.1.0");
28+
29+
// Create release branch from support branch
30+
fixture.Repository.CreateBranch("release/1.2.0").Checkout();
31+
fixture.Repository.MakeACommit();
32+
fixture.AssertFullSemver("1.2.0-beta.1+1");
33+
34+
// Create 1.2.0 release
35+
fixture.Repository.Checkout("support/1.0.0");
36+
fixture.Repository.MergeNoFF("release/1.2.0");
37+
fixture.AssertFullSemver("1.2.0");
38+
fixture.Repository.ApplyTag("1.2.0");
39+
40+
// Create 1.2.1 hotfix
41+
fixture.Repository.CreateBranch("hotfix/1.2.1").Checkout();
42+
fixture.Repository.MakeACommit();
43+
fixture.AssertFullSemver("1.2.1-beta.1+3"); // TODO This should be +1
44+
fixture.Repository.Checkout("support/1.0.0");
45+
fixture.Repository.MergeNoFF("hotfix/1.2.1");
46+
fixture.AssertFullSemver("1.2.1");
47+
}
48+
}
49+
}

GitVersionCore.Tests/IntegrationTests/GitFlow/SupportBranchScenarios.cs

Lines changed: 0 additions & 52 deletions
This file was deleted.

GitVersionCore.Tests/IntegrationTests/GitHubFlow/FeatureBranchTests.cs

Lines changed: 0 additions & 38 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using GitVersion;
2+
using LibGit2Sharp;
3+
using NUnit.Framework;
4+
5+
[TestFixture]
6+
public class GitHubFlowFeatureBranchTests
7+
{
8+
[Test]
9+
public void ShouldNotUseNumberInFeatureBranchAsPreReleaseNumber()
10+
{
11+
using (var fixture = new EmptyRepositoryFixture(new Config()))
12+
{
13+
fixture.Repository.MakeATaggedCommit("1.0.0");
14+
fixture.Repository.CreateBranch("feature/JIRA-123");
15+
fixture.Repository.Checkout("feature/JIRA-123");
16+
fixture.Repository.MakeCommits(5);
17+
18+
fixture.AssertFullSemver("1.0.1-JIRA-123+5");
19+
}
20+
}
21+
22+
[Test]
23+
public void TestFeatureBranch()
24+
{
25+
using (var fixture = new EmptyRepositoryFixture(new Config()))
26+
{
27+
fixture.Repository.MakeATaggedCommit("1.0.0");
28+
fixture.Repository.CreateBranch("feature-test");
29+
fixture.Repository.Checkout("feature-test");
30+
fixture.Repository.MakeCommits(5);
31+
32+
fixture.AssertFullSemver("1.0.1-feature-test+5");
33+
}
34+
}
35+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using GitVersion;
2+
using LibGit2Sharp;
3+
using NUnit.Framework;
4+
5+
[TestFixture]
6+
public class GitHubFlowSupportBranchScenarios
7+
{
8+
[Test]
9+
public void SupportIsCalculatedCorrectly()
10+
{
11+
using (var fixture = new EmptyRepositoryFixture(new Config()))
12+
{
13+
// Start at 1.0.0
14+
fixture.Repository.MakeACommit();
15+
fixture.Repository.ApplyTag("1.1.0");
16+
17+
// Create 2.0.0 release
18+
fixture.Repository.CreateBranch("release-2.0.0").Checkout();
19+
fixture.Repository.MakeCommits(2);
20+
21+
// Merge into develop and master
22+
fixture.Repository.Checkout("master");
23+
fixture.Repository.MergeNoFF("release-2.0.0");
24+
fixture.Repository.ApplyTag("2.0.0");
25+
fixture.AssertFullSemver("2.0.0+0");
26+
27+
// Now lets support 1.x release
28+
fixture.Repository.Checkout("1.1.0");
29+
fixture.Repository.CreateBranch("support/1.0.0").Checkout();
30+
fixture.AssertFullSemver("1.1.0+0");
31+
32+
// Create release branch from support branch
33+
fixture.Repository.CreateBranch("release/1.2.0").Checkout();
34+
fixture.Repository.MakeACommit();
35+
fixture.AssertFullSemver("1.2.0-beta.1+1");
36+
37+
// Create 1.2.0 release
38+
fixture.Repository.Checkout("support/1.0.0");
39+
fixture.Repository.MergeNoFF("release/1.2.0");
40+
fixture.AssertFullSemver("1.2.0+2");
41+
fixture.Repository.ApplyTag("1.2.0");
42+
43+
// Create 1.2.1 hotfix
44+
fixture.Repository.CreateBranch("hotfix/1.2.1").Checkout();
45+
fixture.Repository.MakeACommit();
46+
fixture.AssertFullSemver("1.2.1+1");
47+
fixture.Repository.Checkout("support/1.0.0");
48+
fixture.Repository.MergeNoFF("hotfix/1.2.1");
49+
fixture.AssertFullSemver("1.2.1+2");
50+
}
51+
}
52+
53+
[Test]
54+
public void WhenSupportIsBranchedAndTaggedFromAnotherSupportEnsureNewMinorIsUsed()
55+
{
56+
using (var fixture = new EmptyRepositoryFixture(new Config()))
57+
{
58+
fixture.Repository.MakeACommit();
59+
fixture.Repository.CreateBranch("Support-1.2.0");
60+
fixture.Repository.Checkout("Support-1.2.0");
61+
fixture.Repository.MakeACommit();
62+
fixture.Repository.ApplyTag("1.2.0");
63+
64+
fixture.Repository.CreateBranch("Support-1.3.0");
65+
fixture.Repository.Checkout("Support-1.3.0");
66+
fixture.Repository.ApplyTag("1.3.0");
67+
68+
//Move On
69+
fixture.Repository.MakeACommit();
70+
fixture.Repository.MakeACommit();
71+
72+
fixture.AssertFullSemver("1.3.1+2");
73+
}
74+
}
75+
}

0 commit comments

Comments
 (0)