Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Facilitate running tests with master as the default main branch.
  • Loading branch information
9swampy committed Jun 28, 2025
commit 6f58131ffcbaab8aaa732944fc95a7b4054b1ae6
2 changes: 1 addition & 1 deletion src/GitVersion.Core.Tests/Helpers/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace GitVersion.Core.Tests.Helpers;

public class TestBase
{
public const string MainBranch = "main";
public const string MainBranch = RepositoryFixtureBase.MainBranch;
Copy link
Contributor Author

@9swampy 9swampy Jun 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#4589 Magic strings >> BranchConfigurationKey.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May I ask you: Why do you care about how the branch is named in the unit tests? Does it make any different if it is named master or main? From the configuration point of view both are included and treated the same. At the end everyone can use their own name and their own configuration in the unit tests. There is no need for unification IMO.


protected static IServiceProvider ConfigureServices(Action<IServiceCollection>? overrideServices = null)
{
Expand Down
36 changes: 19 additions & 17 deletions src/GitVersion.Core.Tests/IntegrationTests/GitflowScenarios.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using GitVersion.Configuration;
using GitVersion.Core.Tests.Helpers;

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

using var fixture = new BaseGitFlowRepositoryFixture("1.0.0");
fixture.AssertFullSemver("1.1.0-alpha.1");
fixture.AssertFullSemver("1.1.0-alpha.1", configuration);

// Feature 1
fixture.BranchTo(feature1Branch);
fixture.MakeACommit("added feature 1");
fixture.AssertFullSemver("1.1.0-f1.1+2");
fixture.AssertFullSemver("1.1.0-f1.1+2", configuration);
fixture.Checkout(developBranch);
fixture.MergeNoFF(feature1Branch);
fixture.Repository.Branches.Remove(fixture.Repository.Branches[feature1Branch]);
fixture.AssertFullSemver("1.1.0-alpha.3");
fixture.AssertFullSemver("1.1.0-alpha.3", configuration);

// Release 1.1.0
fixture.BranchTo(release1Branch);
fixture.MakeACommit("release stabilization");
fixture.AssertFullSemver("1.1.0-beta.1+4");
fixture.AssertFullSemver("1.1.0-beta.1+4", configuration);
fixture.Checkout(MainBranch);
fixture.MergeNoFF(release1Branch);
fixture.AssertFullSemver("1.1.0-5");
fixture.AssertFullSemver("1.1.0-5", configuration);
fixture.ApplyTag("1.1.0");
fixture.AssertFullSemver("1.1.0");
fixture.AssertFullSemver("1.1.0", configuration);
fixture.Checkout(developBranch);
fixture.MergeNoFF(release1Branch);
fixture.Repository.Branches.Remove(fixture.Repository.Branches[release1Branch]);
fixture.AssertFullSemver("1.2.0-alpha.1");
fixture.AssertFullSemver("1.2.0-alpha.1", configuration);

// Feature 2
fixture.BranchTo(feature2Branch);
fixture.MakeACommit("added feature 2");
fixture.AssertFullSemver("1.2.0-f2.1+2");
fixture.AssertFullSemver("1.2.0-f2.1+2", configuration);
fixture.Checkout(developBranch);
fixture.MergeNoFF(feature2Branch);
fixture.Repository.Branches.Remove(fixture.Repository.Branches[feature2Branch]);
fixture.AssertFullSemver("1.2.0-alpha.3");
fixture.AssertFullSemver("1.2.0-alpha.3", configuration);

// Release 1.2.0
fixture.BranchTo(release2Branch);
fixture.MakeACommit("release stabilization");
fixture.AssertFullSemver("1.2.0-beta.1+8");
fixture.AssertFullSemver("1.2.0-beta.1+8", configuration);
fixture.Checkout(MainBranch);
fixture.MergeNoFF(release2Branch);
fixture.AssertFullSemver("1.2.0-5");
fixture.AssertFullSemver("1.2.0-5", configuration);
fixture.ApplyTag("1.2.0");
fixture.AssertFullSemver("1.2.0");
fixture.AssertFullSemver("1.2.0", configuration);
fixture.Checkout(developBranch);
fixture.MergeNoFF(release2Branch);
fixture.Repository.Branches.Remove(fixture.Repository.Branches[release2Branch]);
fixture.AssertFullSemver("1.3.0-alpha.1");
fixture.AssertFullSemver("1.3.0-alpha.1", configuration);

// Hotfix
fixture.Checkout(MainBranch);
fixture.BranchTo(hotfixBranch);
fixture.MakeACommit("added hotfix");
fixture.AssertFullSemver("1.2.1-beta.1+1");
fixture.AssertFullSemver("1.2.1-beta.1+1", configuration);
fixture.Checkout(MainBranch);
fixture.MergeNoFF(hotfixBranch);
fixture.AssertFullSemver("1.2.1-2");
fixture.AssertFullSemver("1.2.1-2", configuration);
fixture.ApplyTag("1.2.1");
fixture.AssertFullSemver("1.2.1");
fixture.AssertFullSemver("1.2.1", configuration);
fixture.Checkout(developBranch);
fixture.MergeNoFF(hotfixBranch);
fixture.Repository.Branches.Remove(fixture.Repository.Branches[hotfixBranch]);
fixture.AssertFullSemver("1.3.0-alpha.2");
fixture.AssertFullSemver("1.3.0-alpha.2", configuration);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class BaseGitFlowRepositoryFixture : EmptyRepositoryFixture
/// <para>Creates a repo with a develop branch off main which is a single commit ahead of main branch</para>
/// <para>Main will be tagged with the initial version before branching develop</para>
/// </summary>
public BaseGitFlowRepositoryFixture(string initialVersion, string branchName = "main") :
public BaseGitFlowRepositoryFixture(string initialVersion, string branchName = MainBranch) :
this(r => r.MakeATaggedCommit(initialVersion), branchName)
{
}
Expand All @@ -21,7 +21,7 @@ public BaseGitFlowRepositoryFixture(string initialVersion, string branchName = "
/// <para>Creates a repo with a develop branch off main which is a single commit ahead of main</para>
/// <para>The initial setup actions will be performed before branching develop</para>
/// </summary>
public BaseGitFlowRepositoryFixture(Action<IRepository> initialMainAction, string branchName = "main") :
public BaseGitFlowRepositoryFixture(Action<IRepository> initialMainAction, string branchName = MainBranch) :
base(branchName) => SetupRepo(initialMainAction);

private void SetupRepo(Action<IRepository> initialMainAction)
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersion.Testing/Fixtures/EmptyRepositoryFixture.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
namespace GitVersion.Testing;

public class EmptyRepositoryFixture(string branchName = "main") : RepositoryFixtureBase(path => CreateNewRepository(path, branchName));
public class EmptyRepositoryFixture(string branchName = RepositoryFixtureBase.MainBranch) : RepositoryFixtureBase(path => CreateNewRepository(path, branchName));
2 changes: 1 addition & 1 deletion src/GitVersion.Testing/Fixtures/RemoteRepositoryFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class RemoteRepositoryFixture : RepositoryFixtureBase
public RemoteRepositoryFixture(Func<string, Repository> builder)
: base(builder) => LocalRepositoryFixture = CloneRepository();

public RemoteRepositoryFixture(string branchName = "main")
public RemoteRepositoryFixture(string branchName = MainBranch)
: this(path => CreateNewRepository(path, branchName, 5))
{
}
Expand Down
26 changes: 18 additions & 8 deletions src/GitVersion.Testing/Fixtures/RepositoryFixtureBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ namespace GitVersion.Testing;
/// </summary>
public abstract class RepositoryFixtureBase : IDisposable
{
public const string MainBranch = "master";
public const bool DeleteOnDispose = true;

protected RepositoryFixtureBase(Func<string, Repository> repositoryBuilder)
: this(repositoryBuilder(FileSystemHelper.Path.GetRepositoryTempPath()))
{
Expand Down Expand Up @@ -47,16 +50,23 @@ protected virtual void Dispose(bool disposing)
Repository.Dispose();
var directoryPath = FileSystemHelper.Path.GetFileName(RepositoryPath);

try
if (DeleteOnDispose)
{
Console.WriteLine("Cleaning up repository path at {0}", directoryPath);
FileSystemHelper.Directory.DeleteDirectory(RepositoryPath);
Console.WriteLine("Cleaned up repository path at {0}", directoryPath);
try
{
Console.WriteLine("Cleaning up repository path at {0}", directoryPath);
FileSystemHelper.Directory.DeleteDirectory(RepositoryPath);
Console.WriteLine("Cleaned up repository path at {0}", directoryPath);
}
catch (Exception e)
{
Console.WriteLine("Failed to clean up repository path at {0}. Received exception: {1}", directoryPath, e.Message);
// throw;
}
}
catch (Exception e)
else
{
Console.WriteLine("Failed to clean up repository path at {0}. Received exception: {1}", directoryPath, e.Message);
// throw;
Console.WriteLine("Leaving repository path at {0} intact", directoryPath);
}

this.SequenceDiagram.End();
Expand All @@ -73,7 +83,7 @@ public void Remove(string branch)
SequenceDiagram.Destroy(branch);
}

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

public string MakeATaggedCommit(string tag)
{
Expand Down