Skip to content

Commit

Permalink
Refactoring/remove the EffectiveConfiguration property in the GitVers…
Browse files Browse the repository at this point in the history
…ionContext class. This change is a preparation for fixing the issue GitTools#3101 in PR GitTools#3190 and targets the v5 version. No business logic changed.
  • Loading branch information
HHobeck committed Oct 1, 2022
1 parent 3b6a100 commit 2dc8ef0
Show file tree
Hide file tree
Showing 56 changed files with 809 additions and 384 deletions.
25 changes: 22 additions & 3 deletions src/GitTools.Testing/Fixtures/BaseGitFlowRepositoryFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,26 @@ public class BaseGitFlowRepositoryFixture : EmptyRepositoryFixture
///
/// Main will be tagged with the initial version before branching develop
/// </summary>
public BaseGitFlowRepositoryFixture(string initialVersion) :
this(r => r.MakeATaggedCommit(initialVersion))
public BaseGitFlowRepositoryFixture(string initialVersion) : this(initialVersion, "main")
{
}

/// <summary>
/// Creates a repo with a develop branch off main which is a single commit ahead of main
///
/// Main will be tagged with the initial version before branching develop
/// </summary>
public BaseGitFlowRepositoryFixture(string initialVersion, string branchName) :
this(r => r.MakeATaggedCommit(initialVersion), branchName)
{
}

/// <summary>
/// Creates a repo with a develop branch off main which is a single commit ahead of main
///
/// The initial setup actions will be performed before branching develop
/// </summary>
public BaseGitFlowRepositoryFixture(Action<IRepository> initialMainAction) : this(initialMainAction, "main")
{
}

Expand All @@ -22,7 +40,8 @@ public BaseGitFlowRepositoryFixture(string initialVersion) :
///
/// The initial setup actions will be performed before branching develop
/// </summary>
public BaseGitFlowRepositoryFixture(Action<IRepository> initialMainAction) => SetupRepo(initialMainAction);
public BaseGitFlowRepositoryFixture(Action<IRepository> initialMainAction, string branchName) :
base(branchName) => SetupRepo(initialMainAction);

private void SetupRepo(Action<IRepository> initialMainAction)
{
Expand Down
11 changes: 8 additions & 3 deletions src/GitTools.Testing/Fixtures/EmptyRepositoryFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ namespace GitTools.Testing;

public class EmptyRepositoryFixture : RepositoryFixtureBase
{
public EmptyRepositoryFixture() : base(CreateNewRepository)
public EmptyRepositoryFixture() : this("main")
{
}

private static IRepository CreateNewRepository(string path)
public EmptyRepositoryFixture(string branchName)
: base(path => CreateNewRepository(path, branchName))
{
Init(path);
}

private static IRepository CreateNewRepository(string path, string branchName)
{
Init(path, branchName);
Console.WriteLine("Created git repository at '{0}'", path);

return new Repository(path);
Expand Down
11 changes: 8 additions & 3 deletions src/GitTools.Testing/Fixtures/RemoteRepositoryFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ public class RemoteRepositoryFixture : RepositoryFixtureBase
public RemoteRepositoryFixture(Func<string, IRepository> builder)
: base(builder) => CreateLocalRepository();

public RemoteRepositoryFixture() : this(CreateNewRepository)
public RemoteRepositoryFixture() : this("main")
{
}

public RemoteRepositoryFixture(string branchName) :
this(path => CreateNewRepository(path, branchName))
{
}

Expand All @@ -21,9 +26,9 @@ public RemoteRepositoryFixture() : this(CreateNewRepository)
/// </summary>
public LocalRepositoryFixture LocalRepositoryFixture { get; private set; }

private static IRepository CreateNewRepository(string path)
private static IRepository CreateNewRepository(string path, string branchName)
{
Init(path);
Init(path, branchName);
Console.WriteLine("Created git repository at '{0}'", path);

var repo = new Repository(path);
Expand Down
2 changes: 1 addition & 1 deletion src/GitTools.Testing/Fixtures/RepositoryFixtureBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected virtual void Dispose(bool disposing)

public void Checkout(string branch) => Commands.Checkout(Repository, branch);

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

public void MakeATaggedCommit(string tag)
{
Expand Down
4 changes: 2 additions & 2 deletions src/GitVersion.App.Tests/PullRequestInBuildAgentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ public async Task VerifyBitBucketPipelinesPullRequest(string pullRequestRef)

private static async Task VerifyPullRequestVersionIsCalculatedProperly(string pullRequestRef, Dictionary<string, string> env)
{
using var fixture = new EmptyRepositoryFixture();
using var fixture = new EmptyRepositoryFixture("main");
var remoteRepositoryPath = ExecutableHelper.GetTempPath();
RepositoryFixtureBase.Init(remoteRepositoryPath);
RepositoryFixtureBase.Init(remoteRepositoryPath, "main");
using (var remoteRepository = new Repository(remoteRepositoryPath))
{
remoteRepository.Config.Set("user.name", "Test");
Expand Down
4 changes: 2 additions & 2 deletions src/GitVersion.App.Tests/TagCheckoutInBuildAgentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public async Task VerifyTagCheckoutOnGitHubActions()

private static async Task VerifyTagCheckoutVersionIsCalculatedProperly(Dictionary<string, string> env)
{
using var fixture = new EmptyRepositoryFixture();
using var fixture = new EmptyRepositoryFixture("main");
var remoteRepositoryPath = ExecutableHelper.GetTempPath();
RepositoryFixtureBase.Init(remoteRepositoryPath);
RepositoryFixtureBase.Init(remoteRepositoryPath, "main");
using (var remoteRepository = new Repository(remoteRepositoryPath))
{
remoteRepository.Config.Set("user.name", "Test");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,8 @@ branches:
pre-release-weight: 30000
feature:
mode: ContinuousDelivery
tag: useBranchName
tag: '{BranchName}'
increment: Inherit
prevent-increment-of-merged-branch-version: false
track-merge-target: false
regex: ^features?[/-]
source-branches:
- develop
Expand All @@ -69,17 +67,12 @@ branches:
- feature
- support
- hotfix
tracks-release-branches: false
is-release-branch: false
is-mainline: false
pre-release-weight: 30000
pull-request:
mode: ContinuousDelivery
tag: PullRequest
increment: Inherit
prevent-increment-of-merged-branch-version: false
tag-number-pattern: '[/-](?<number>\d+)'
track-merge-target: false
regex: ^(pull|pull\-requests|pr)[/-]
source-branches:
- develop
Expand All @@ -88,9 +81,6 @@ branches:
- feature
- support
- hotfix
tracks-release-branches: false
is-release-branch: false
is-mainline: false
pre-release-weight: 30000
hotfix:
mode: ContinuousDelivery
Expand All @@ -100,9 +90,10 @@ branches:
track-merge-target: false
regex: ^hotfix(es)?[/-]
source-branches:
- develop
- release
- main
- support
- hotfix
tracks-release-branches: false
is-release-branch: false
is-mainline: false
Expand All @@ -122,6 +113,7 @@ branches:
pre-release-weight: 55000
ignore:
sha: []
increment: Inherit
commit-date-format: yyyy-MM-dd
merge-message-formats: {}
update-build-number: true
13 changes: 5 additions & 8 deletions src/GitVersion.Core.Tests/Core/RepositoryStoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using GitVersion.Core.Tests.IntegrationTests;
using GitVersion.Logging;
using GitVersion.Model.Configuration;
using GitVersion.VersionCalculation;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;
using Shouldly;
Expand All @@ -14,13 +13,11 @@ namespace GitVersion.Core.Tests;
public class RepositoryStoreTests : TestBase
{
private readonly ILog log;
private readonly IIncrementStrategyFinder incrementStrategyFinder;

public RepositoryStoreTests()
{
var sp = ConfigureServices();
this.log = sp.GetRequiredService<ILog>();
this.incrementStrategyFinder = sp.GetRequiredService<IIncrementStrategyFinder>();
}

[Test]
Expand Down Expand Up @@ -65,7 +62,7 @@ public void FindsCorrectMergeBaseForForwardMerge()

var develop = fixtureRepository.FindBranch("develop");
var release = fixtureRepository.FindBranch("release-2.0.0");
var gitRepoMetadataProvider = new RepositoryStore(this.log, fixtureRepository, this.incrementStrategyFinder);
var gitRepoMetadataProvider = new RepositoryStore(this.log, fixtureRepository);

var releaseBranchMergeBase = gitRepoMetadataProvider.FindMergeBase(release, develop);

Expand Down Expand Up @@ -121,7 +118,7 @@ public void FindsCorrectMergeBaseForForwardMergeMovesOn()

var develop = fixtureRepository.FindBranch("develop");
var release = fixtureRepository.FindBranch("release-2.0.0");
var gitRepoMetadataProvider = new RepositoryStore(this.log, fixtureRepository, this.incrementStrategyFinder);
var gitRepoMetadataProvider = new RepositoryStore(this.log, fixtureRepository);

var releaseBranchMergeBase = gitRepoMetadataProvider.FindMergeBase(release, develop);

Expand Down Expand Up @@ -196,7 +193,7 @@ public void FindsCorrectMergeBaseForMultipleForwardMerges()
var develop = fixtureRepository.FindBranch("develop");
var release = fixtureRepository.FindBranch("release-2.0.0");

var gitRepoMetadataProvider = new RepositoryStore(this.log, fixtureRepository, this.incrementStrategyFinder);
var gitRepoMetadataProvider = new RepositoryStore(this.log, fixtureRepository);

var releaseBranchMergeBase = gitRepoMetadataProvider.FindMergeBase(release, develop);

Expand All @@ -213,7 +210,7 @@ public void GetBranchesContainingCommitThrowsDirectlyOnNullCommit()
{
using var fixture = new EmptyRepositoryFixture();
var fixtureRepository = fixture.Repository.ToGitRepository();
var gitRepoMetadataProvider = new RepositoryStore(this.log, fixtureRepository, this.incrementStrategyFinder);
var gitRepoMetadataProvider = new RepositoryStore(this.log, fixtureRepository);

Assert.Throws<ArgumentNullException>(() => gitRepoMetadataProvider.GetBranchesContainingCommit(null));
}
Expand All @@ -227,7 +224,7 @@ public void FindCommitBranchWasBranchedFromShouldReturnNullIfTheRemoteIsTheOnlyS

var localRepository = fixture.LocalRepositoryFixture.Repository.ToGitRepository();

var gitRepoMetadataProvider = new RepositoryStore(this.log, localRepository, this.incrementStrategyFinder);
var gitRepoMetadataProvider = new RepositoryStore(this.log, localRepository);

var branch = localRepository.FindBranch("main");
branch.ShouldNotBeNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public static VersionVariables GetVersion(this RepositoryFixtureBase fixture, Co

try
{
var semanticVersion = nextVersionCalculator.FindVersion();
var variables = variableProvider.GetVariablesFor(semanticVersion, context.Configuration, context.IsCurrentCommitTagged);
var nextVersion = nextVersionCalculator.FindVersion();
var variables = variableProvider.GetVariablesFor(nextVersion.IncrementedVersion, nextVersion.Configuration, context.IsCurrentCommitTagged);

return variables;
}
Expand Down
Loading

0 comments on commit 2dc8ef0

Please sign in to comment.