Skip to content

Commit 6f58131

Browse files
committed
Facilitate running tests with master as the default main branch.
1 parent ab2d303 commit 6f58131

File tree

6 files changed

+42
-30
lines changed

6 files changed

+42
-30
lines changed

src/GitVersion.Core.Tests/Helpers/TestBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace GitVersion.Core.Tests.Helpers;
77

88
public class TestBase
99
{
10-
public const string MainBranch = "main";
10+
public const string MainBranch = RepositoryFixtureBase.MainBranch;
1111

1212
protected static IServiceProvider ConfigureServices(Action<IServiceCollection>? overrideServices = null)
1313
{
Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using GitVersion.Configuration;
12
using GitVersion.Core.Tests.Helpers;
23

34
namespace GitVersion.Core.Tests.IntegrationTests;
@@ -14,69 +15,70 @@ public void GitflowComplexExample()
1415
const string release1Branch = "release/1.1.0";
1516
const string release2Branch = "release/1.2.0";
1617
const string hotfixBranch = "hotfix/hf";
18+
var configuration = GitFlowConfigurationBuilder.New.Build();
1719

1820
using var fixture = new BaseGitFlowRepositoryFixture("1.0.0");
19-
fixture.AssertFullSemver("1.1.0-alpha.1");
21+
fixture.AssertFullSemver("1.1.0-alpha.1", configuration);
2022

2123
// Feature 1
2224
fixture.BranchTo(feature1Branch);
2325
fixture.MakeACommit("added feature 1");
24-
fixture.AssertFullSemver("1.1.0-f1.1+2");
26+
fixture.AssertFullSemver("1.1.0-f1.1+2", configuration);
2527
fixture.Checkout(developBranch);
2628
fixture.MergeNoFF(feature1Branch);
2729
fixture.Repository.Branches.Remove(fixture.Repository.Branches[feature1Branch]);
28-
fixture.AssertFullSemver("1.1.0-alpha.3");
30+
fixture.AssertFullSemver("1.1.0-alpha.3", configuration);
2931

3032
// Release 1.1.0
3133
fixture.BranchTo(release1Branch);
3234
fixture.MakeACommit("release stabilization");
33-
fixture.AssertFullSemver("1.1.0-beta.1+4");
35+
fixture.AssertFullSemver("1.1.0-beta.1+4", configuration);
3436
fixture.Checkout(MainBranch);
3537
fixture.MergeNoFF(release1Branch);
36-
fixture.AssertFullSemver("1.1.0-5");
38+
fixture.AssertFullSemver("1.1.0-5", configuration);
3739
fixture.ApplyTag("1.1.0");
38-
fixture.AssertFullSemver("1.1.0");
40+
fixture.AssertFullSemver("1.1.0", configuration);
3941
fixture.Checkout(developBranch);
4042
fixture.MergeNoFF(release1Branch);
4143
fixture.Repository.Branches.Remove(fixture.Repository.Branches[release1Branch]);
42-
fixture.AssertFullSemver("1.2.0-alpha.1");
44+
fixture.AssertFullSemver("1.2.0-alpha.1", configuration);
4345

4446
// Feature 2
4547
fixture.BranchTo(feature2Branch);
4648
fixture.MakeACommit("added feature 2");
47-
fixture.AssertFullSemver("1.2.0-f2.1+2");
49+
fixture.AssertFullSemver("1.2.0-f2.1+2", configuration);
4850
fixture.Checkout(developBranch);
4951
fixture.MergeNoFF(feature2Branch);
5052
fixture.Repository.Branches.Remove(fixture.Repository.Branches[feature2Branch]);
51-
fixture.AssertFullSemver("1.2.0-alpha.3");
53+
fixture.AssertFullSemver("1.2.0-alpha.3", configuration);
5254

5355
// Release 1.2.0
5456
fixture.BranchTo(release2Branch);
5557
fixture.MakeACommit("release stabilization");
56-
fixture.AssertFullSemver("1.2.0-beta.1+8");
58+
fixture.AssertFullSemver("1.2.0-beta.1+8", configuration);
5759
fixture.Checkout(MainBranch);
5860
fixture.MergeNoFF(release2Branch);
59-
fixture.AssertFullSemver("1.2.0-5");
61+
fixture.AssertFullSemver("1.2.0-5", configuration);
6062
fixture.ApplyTag("1.2.0");
61-
fixture.AssertFullSemver("1.2.0");
63+
fixture.AssertFullSemver("1.2.0", configuration);
6264
fixture.Checkout(developBranch);
6365
fixture.MergeNoFF(release2Branch);
6466
fixture.Repository.Branches.Remove(fixture.Repository.Branches[release2Branch]);
65-
fixture.AssertFullSemver("1.3.0-alpha.1");
67+
fixture.AssertFullSemver("1.3.0-alpha.1", configuration);
6668

6769
// Hotfix
6870
fixture.Checkout(MainBranch);
6971
fixture.BranchTo(hotfixBranch);
7072
fixture.MakeACommit("added hotfix");
71-
fixture.AssertFullSemver("1.2.1-beta.1+1");
73+
fixture.AssertFullSemver("1.2.1-beta.1+1", configuration);
7274
fixture.Checkout(MainBranch);
7375
fixture.MergeNoFF(hotfixBranch);
74-
fixture.AssertFullSemver("1.2.1-2");
76+
fixture.AssertFullSemver("1.2.1-2", configuration);
7577
fixture.ApplyTag("1.2.1");
76-
fixture.AssertFullSemver("1.2.1");
78+
fixture.AssertFullSemver("1.2.1", configuration);
7779
fixture.Checkout(developBranch);
7880
fixture.MergeNoFF(hotfixBranch);
7981
fixture.Repository.Branches.Remove(fixture.Repository.Branches[hotfixBranch]);
80-
fixture.AssertFullSemver("1.3.0-alpha.2");
82+
fixture.AssertFullSemver("1.3.0-alpha.2", configuration);
8183
}
8284
}

src/GitVersion.Testing/Fixtures/BaseGitFlowRepositoryFixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class BaseGitFlowRepositoryFixture : EmptyRepositoryFixture
1212
/// <para>Creates a repo with a develop branch off main which is a single commit ahead of main branch</para>
1313
/// <para>Main will be tagged with the initial version before branching develop</para>
1414
/// </summary>
15-
public BaseGitFlowRepositoryFixture(string initialVersion, string branchName = "main") :
15+
public BaseGitFlowRepositoryFixture(string initialVersion, string branchName = MainBranch) :
1616
this(r => r.MakeATaggedCommit(initialVersion), branchName)
1717
{
1818
}
@@ -21,7 +21,7 @@ public BaseGitFlowRepositoryFixture(string initialVersion, string branchName = "
2121
/// <para>Creates a repo with a develop branch off main which is a single commit ahead of main</para>
2222
/// <para>The initial setup actions will be performed before branching develop</para>
2323
/// </summary>
24-
public BaseGitFlowRepositoryFixture(Action<IRepository> initialMainAction, string branchName = "main") :
24+
public BaseGitFlowRepositoryFixture(Action<IRepository> initialMainAction, string branchName = MainBranch) :
2525
base(branchName) => SetupRepo(initialMainAction);
2626

2727
private void SetupRepo(Action<IRepository> initialMainAction)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
namespace GitVersion.Testing;
22

3-
public class EmptyRepositoryFixture(string branchName = "main") : RepositoryFixtureBase(path => CreateNewRepository(path, branchName));
3+
public class EmptyRepositoryFixture(string branchName = RepositoryFixtureBase.MainBranch) : RepositoryFixtureBase(path => CreateNewRepository(path, branchName));

src/GitVersion.Testing/Fixtures/RemoteRepositoryFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class RemoteRepositoryFixture : RepositoryFixtureBase
1212
public RemoteRepositoryFixture(Func<string, Repository> builder)
1313
: base(builder) => LocalRepositoryFixture = CloneRepository();
1414

15-
public RemoteRepositoryFixture(string branchName = "main")
15+
public RemoteRepositoryFixture(string branchName = MainBranch)
1616
: this(path => CreateNewRepository(path, branchName, 5))
1717
{
1818
}

src/GitVersion.Testing/Fixtures/RepositoryFixtureBase.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ namespace GitVersion.Testing;
99
/// </summary>
1010
public abstract class RepositoryFixtureBase : IDisposable
1111
{
12+
public const string MainBranch = "master";
13+
public const bool DeleteOnDispose = true;
14+
1215
protected RepositoryFixtureBase(Func<string, Repository> repositoryBuilder)
1316
: this(repositoryBuilder(FileSystemHelper.Path.GetRepositoryTempPath()))
1417
{
@@ -47,16 +50,23 @@ protected virtual void Dispose(bool disposing)
4750
Repository.Dispose();
4851
var directoryPath = FileSystemHelper.Path.GetFileName(RepositoryPath);
4952

50-
try
53+
if (DeleteOnDispose)
5154
{
52-
Console.WriteLine("Cleaning up repository path at {0}", directoryPath);
53-
FileSystemHelper.Directory.DeleteDirectory(RepositoryPath);
54-
Console.WriteLine("Cleaned up repository path at {0}", directoryPath);
55+
try
56+
{
57+
Console.WriteLine("Cleaning up repository path at {0}", directoryPath);
58+
FileSystemHelper.Directory.DeleteDirectory(RepositoryPath);
59+
Console.WriteLine("Cleaned up repository path at {0}", directoryPath);
60+
}
61+
catch (Exception e)
62+
{
63+
Console.WriteLine("Failed to clean up repository path at {0}. Received exception: {1}", directoryPath, e.Message);
64+
// throw;
65+
}
5566
}
56-
catch (Exception e)
67+
else
5768
{
58-
Console.WriteLine("Failed to clean up repository path at {0}. Received exception: {1}", directoryPath, e.Message);
59-
// throw;
69+
Console.WriteLine("Leaving repository path at {0} intact", directoryPath);
6070
}
6171

6272
this.SequenceDiagram.End();
@@ -73,7 +83,7 @@ public void Remove(string branch)
7383
SequenceDiagram.Destroy(branch);
7484
}
7585

76-
public static void Init(string path, string branchName = "main") => GitTestExtensions.ExecuteGitCmd($"init {path} -b {branchName}", ".");
86+
public static void Init(string path, string branchName = MainBranch) => GitTestExtensions.ExecuteGitCmd($"init {path} -b {branchName}", ".");
7787

7888
public string MakeATaggedCommit(string tag)
7989
{

0 commit comments

Comments
 (0)