Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the logic inheriting BranchConfiguration from parent branch if the IncrementStrategy is set to Inherit #3190

Merged
merged 69 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
5c619d6
The behavior of GitVersion is sometimes not like I would expected it.…
HHobeck Sep 9, 2022
f2ea9df
Okay I changed the unit and agree on the result. It feels very natura…
HHobeck Sep 9, 2022
3c1e64a
Merge branch 'support/5.x' into feature/3101
HHobeck Sep 9, 2022
0431671
Ignore some failing tests
HHobeck Sep 9, 2022
12a6ecc
Fix some tests
HHobeck Sep 9, 2022
2f89159
Set back the default behavior and change the configuration builder: s…
HHobeck Sep 10, 2022
01100f2
Integrate code review feedbacks from Asbjørn Ulsberg.
HHobeck Sep 10, 2022
dcec44f
Set back the default behavior and change the configuration builder: s…
HHobeck Sep 10, 2022
eac6f01
Set back the default behavior and change the configuration builder: s…
HHobeck Sep 10, 2022
8f09a85
Fix WhenPreventIncrementOfMergedBranchVersionIsSetToFalseForDevelopCo…
HHobeck Sep 10, 2022
c62053b
Add ConfigBuilder to make it easier in tests to create configuration …
HHobeck Sep 12, 2022
3c74141
Create test for discussion: Prevent decrementation of versions on the…
HHobeck Sep 12, 2022
937f761
Modify PreventDecrementationOfVersionsOnTheDevelopBranch and remove T…
HHobeck Sep 13, 2022
befa745
The way I'm calculating the effective configuration for each base ver…
HHobeck Sep 15, 2022
ccb9f1f
Remove BranchConfigurationCalculator
HHobeck Sep 15, 2022
55c899d
Run dotnet format
HHobeck Sep 15, 2022
8f226d4
Remove comments out of the test scenarios which I have added.
HHobeck Sep 15, 2022
4e29b80
Change PreventDecrementationOfVersionsOnTheDevelopBranchScenario and …
HHobeck Sep 15, 2022
9f12b5b
Change PreventDecrementationOfVersionsOnTheDevelopBranchScenario
HHobeck Sep 15, 2022
3110909
Move logic from VersionStrategyBase to VersionStrategyBaseWithInherit…
HHobeck Sep 15, 2022
33dc540
Change back some configuration changes like it was before.
HHobeck Sep 15, 2022
de573a5
Fix FindsVersionInDynamicRepo test
HHobeck Sep 16, 2022
a9471d9
run dotnet format ./src/ --exclude **/AddFormats/
HHobeck Sep 16, 2022
39b1abc
Create integration test for [Bug] #3151 and make some minor changes
HHobeck Sep 16, 2022
28a9d2b
Move this logic to the class BaseVersionCalculator and change the int…
HHobeck Sep 17, 2022
f982607
Create unit test for EffectiveBranchConfigurationFinder
HHobeck Sep 17, 2022
7c585f2
Introduce the concept of fallback and unkown branch configuration. Wh…
HHobeck Sep 18, 2022
da04d3f
Mastering the integration tests CreatingAFeatureBranchFromAReleaseBra…
HHobeck Sep 18, 2022
4475e05
Create a new EffectiveBranchConfiguration class which contains the Br…
HHobeck Sep 18, 2022
e43dbf7
Fuse the BaseVersionCalculator with the NextVersionCalculator. No bus…
HHobeck Sep 18, 2022
2531495
Finally I have changed all calls to GitVersionContext::Configuration …
HHobeck Sep 18, 2022
4095244
dotnet format .\src\ --exclude **/AddFormats/
HHobeck Sep 18, 2022
260ee92
Merge branch 'main' into feature/3101
HHobeck Sep 19, 2022
75f4c37
EffectiveBranchConfigurationFinder public and remove one integration …
HHobeck Sep 19, 2022
c6945fc
Rename GetTargetBranches to GetSourceBranches. Fix some warnings and …
HHobeck Sep 20, 2022
e73c92f
Move commented test to EffectiveBranchConfigurationFinderTests.
HHobeck Sep 20, 2022
6a69dce
Move tests aspects from GitVersionContextTests to EffectiveBranchConf…
HHobeck Sep 20, 2022
043264c
Move tests from BaseVersionCalculatorTests to NextVersionCalculatorTe…
HHobeck Sep 20, 2022
8f8e665
Re comment tests in NextVersionCalculatorTests, MergeMessageBaseVersi…
HHobeck Sep 20, 2022
1c9e3cf
Update documentation how-it-works.md
HHobeck Sep 20, 2022
45cf14f
dotnet format ./src/ --exclude **/AddFormats/ --verify-no-changes
HHobeck Sep 20, 2022
8e1670f
Fix some typos
HHobeck Sep 21, 2022
1041d07
Refactoring of EffectiveConfiguration. no business logic changed
HHobeck Oct 1, 2022
5af8026
Move logic call of UpdatePreReleaseTag back to the previous location.
HHobeck Oct 1, 2022
b9cf015
Merge branch 'main' into feature/3101
HHobeck Oct 1, 2022
016d5a7
Integrate code review comments of reviewer asbjornu and arturcic.
HHobeck Oct 3, 2022
f062817
Change PublicAPI.Shipped and Unshipped
HHobeck Oct 3, 2022
a5f3d5e
Merge branch 'GitTools:main' into feature/3101
HHobeck Oct 4, 2022
74db309
Merge branch main into 'feature/3101'
HHobeck Oct 4, 2022
2425546
Merge branch 'main' into feature/3101
asbjornu Oct 4, 2022
2ba1989
Minor refactoring. No business logic changed.
HHobeck Oct 5, 2022
0080e73
Merge branch 'feature/3101' of https://github.com/HHobeck/GitVersion …
HHobeck Oct 5, 2022
ff6f27f
Refactoring of MainlineBranchFinder class.
HHobeck Oct 5, 2022
061c06e
Merge branch 'main' into feature/3101
HHobeck Oct 5, 2022
7f0309b
Integrate code review comments of reviewer asbjornu.
HHobeck Oct 5, 2022
fc2e75d
Integrate code review comments of reviewer asbjornu.
HHobeck Oct 5, 2022
42da619
Merge branch 'feature/3101' of https://github.com/HHobeck/GitVersion …
HHobeck Oct 5, 2022
f39b551
Removing default values from hotfix branch configuration which should…
HHobeck Oct 6, 2022
94e2127
Remove FixTheBaseVersionSourceOfMergeMessageStrategyIfReleaseBranchWa…
HHobeck Oct 7, 2022
af1bf3f
Merge branch 'main' into feature/3101
asbjornu Oct 10, 2022
6bd49cd
Make the effective configuration tag not nullable. Default value for …
HHobeck Oct 11, 2022
4a405c6
Change breaking changes file
HHobeck Oct 11, 2022
410c92e
Change property FullConfiguration to Configuration in GitVersionContext.
HHobeck Oct 11, 2022
f24f235
Merge branch 'feature/3101' of https://github.com/HHobeck/GitVersion …
HHobeck Oct 11, 2022
77095ac
Fix typo in breaking changes
HHobeck Oct 11, 2022
32b0398
Update breaking changes and document some examples
HHobeck Oct 11, 2022
3971272
Change documentation
HHobeck Oct 11, 2022
0800edf
Remove constructing logic of the configuration in GitToolsTestingExte…
HHobeck Oct 11, 2022
1397f03
Update BREAKING_CHANGES.md
HHobeck Oct 11, 2022
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
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/JsonOutputOnBuildServerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void BeingOnBuildServerWithOutputJsonDoesNotFail()
var result = GitVersionHelper.ExecuteIn(fixture.LocalRepositoryFixture.RepositoryPath, arguments: " /output json /output buildserver", environments: env);

result.ExitCode.ShouldBe(0);
const string version = "0.1.0+4";
const string version = "0.0.1+5";
asbjornu marked this conversation as resolved.
Show resolved Hide resolved
result.Output.ShouldContain($"##teamcity[buildNumber '{version}']");
result.OutputVariables.ShouldNotBeNull();
result.OutputVariables.FullSemVer.ShouldBeEquivalentTo(version);
Expand All @@ -56,7 +56,7 @@ public void BeingOnBuildServerWithOutputJsonAndOutputFileDoesNotFail(string outp
var result = GitVersionHelper.ExecuteIn(fixture.LocalRepositoryFixture.RepositoryPath, arguments: $" /output json /output buildserver /output file /outputfile {outputFile}", environments: env);

result.ExitCode.ShouldBe(0);
const string version = "0.1.0+4";
const string version = "0.0.1+5";
asbjornu marked this conversation as resolved.
Show resolved Hide resolved
result.Output.ShouldContain($"##teamcity[buildNumber '{version}']");
result.OutputVariables.ShouldNotBeNull();
result.OutputVariables.FullSemVer.ShouldBeEquivalentTo(version);
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 @@ -30,7 +30,7 @@ branches:
tag: ''
increment: Patch
prevent-increment-of-merged-branch-version: true
track-merge-target: false
track-merge-target: true
regex: ^master$|^main$
source-branches:
- develop
Expand Down Expand Up @@ -112,7 +112,7 @@ branches:
tag: ''
increment: Patch
prevent-increment-of-merged-branch-version: true
track-merge-target: false
track-merge-target: true
regex: ^support[/-]
source-branches:
- main
Expand Down
16 changes: 10 additions & 6 deletions src/GitVersion.Core.Tests/Core/GitVersionExecutorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public void CacheFileExistsOnDisk()
var gitVersionCalculator = GetGitVersionCalculator(gitVersionOptions, this.log);

var versionVariables = gitVersionCalculator.CalculateVersionVariables();
versionVariables.AssemblySemVer.ShouldBe("0.1.0.0");
versionVariables.AssemblySemVer.ShouldBe("0.0.1.0");

this.fileSystem.WriteAllText(versionVariables.FileName, versionCacheFileContent);
versionVariables = gitVersionCalculator.CalculateVersionVariables();
Expand Down Expand Up @@ -215,7 +215,7 @@ public void CacheFileExistsOnDiskWhenOverrideConfigIsSpecifiedVersionShouldBeDyn
var gitVersionCalculator = GetGitVersionCalculator(gitVersionOptions, this.log);

var versionVariables = gitVersionCalculator.CalculateVersionVariables();
versionVariables.AssemblySemVer.ShouldBe("0.1.0.0");
versionVariables.AssemblySemVer.ShouldBe("0.0.1.0");

this.fileSystem.WriteAllText(versionVariables.FileName, versionCacheFileContent);

Expand All @@ -229,7 +229,7 @@ public void CacheFileExistsOnDiskWhenOverrideConfigIsSpecifiedVersionShouldBeDyn
gitVersionCalculator = GetGitVersionCalculator(gitVersionOptions);
versionVariables = gitVersionCalculator.CalculateVersionVariables();

versionVariables.AssemblySemVer.ShouldBe("0.1.0.0");
versionVariables.AssemblySemVer.ShouldBe("0.0.1.0");

var cachedDirectoryTimestampAfter = this.fileSystem.GetLastDirectoryWrite(cacheDirectory);
cachedDirectoryTimestampAfter.ShouldBe(cacheDirectoryTimestamp, "Cache was updated when override config was set");
Expand Down Expand Up @@ -305,7 +305,7 @@ public void ConfigChangeInvalidatesCache()
var gitVersionCalculator = GetGitVersionCalculator(gitVersionOptions);
var versionVariables = gitVersionCalculator.CalculateVersionVariables();

versionVariables.AssemblySemVer.ShouldBe("0.1.0.0");
versionVariables.AssemblySemVer.ShouldBe("0.0.1.0");
versionVariables.FileName.ShouldNotBeNullOrEmpty();

this.fileSystem.WriteAllText(versionVariables.FileName, versionCacheFileContent);
Expand Down Expand Up @@ -370,7 +370,7 @@ public void NoCacheBypassesCache()

var versionVariables = gitVersionCalculator.CalculateVersionVariables();

versionVariables.AssemblySemVer.ShouldBe("0.1.0.0");
versionVariables.AssemblySemVer.ShouldBe("0.0.1.0");
versionVariables.FileName.ShouldNotBeNullOrEmpty();

this.fileSystem.WriteAllText(versionVariables.FileName, versionCacheFileContent);
Expand All @@ -379,7 +379,7 @@ public void NoCacheBypassesCache()

gitVersionOptions.Settings.NoCache = true;
versionVariables = gitVersionCalculator.CalculateVersionVariables();
versionVariables.AssemblySemVer.ShouldBe("0.1.0.0");
versionVariables.AssemblySemVer.ShouldBe("0.0.1.0");
}

[Test]
Expand All @@ -398,15 +398,19 @@ public void WorkingDirectoryWithoutGit()
[Test]
public void WorkingDirectoryWithoutCommits()
HHobeck marked this conversation as resolved.
Show resolved Hide resolved
{
// Setup
using var fixture = new EmptyRepositoryFixture();

var gitVersionOptions = new GitVersionOptions { WorkingDirectory = fixture.RepositoryPath };

var exception = Assert.Throws<GitVersionException>(() =>
{
// Execute
var gitVersionCalculator = GetGitVersionCalculator(gitVersionOptions);
gitVersionCalculator.CalculateVersionVariables();
});

// Verify
exception?.Message.ShouldContain("No commits found on the current branch.");
}

Expand Down
99 changes: 99 additions & 0 deletions src/GitVersion.Core.Tests/Helpers/ConfigBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using GitVersion.Configuration;
using GitVersion.Model.Configuration;
using GitVersion.VersionCalculation;

namespace GitVersion.Core.Tests.Helpers;

public sealed class ConfigBuilder
{
public static ConfigBuilder New => new();

private string? nextVerson;
private VersioningMode versioningMode;
private bool withoutAnyTrackMergeTargets;
private IDictionary<string, bool> trackMergeTargetsDictionary;
private IDictionary<string, bool> preventIncrementOfMergedBranchVersionDictionary;
private IgnoreConfig? ignoreConfig;

private ConfigBuilder()
{
withoutAnyTrackMergeTargets = false;
versioningMode = VersioningMode.ContinuousDelivery;
trackMergeTargetsDictionary = new Dictionary<string, bool>();
preventIncrementOfMergedBranchVersionDictionary = new Dictionary<string, bool>();
}

public ConfigBuilder WithNextVersion(string? value)
{
nextVerson = value;
return this;
}

public ConfigBuilder WithVersioningMode(VersioningMode value)
{
versioningMode = value;
return this;
}

public ConfigBuilder WithTrackMergeTarget(string branch, bool value)
{
trackMergeTargetsDictionary[branch] = value;
return this;
}

public ConfigBuilder WithoutAnyTrackMergeTargets()
{
withoutAnyTrackMergeTargets = true;
trackMergeTargetsDictionary.Clear();
return this;
}

public ConfigBuilder WithPreventIncrementOfMergedBranchVersion(string branch, bool value)
{
preventIncrementOfMergedBranchVersionDictionary[branch] = value;
return this;
}

public ConfigBuilder WithIgnoreConfig(IgnoreConfig value)
{
ignoreConfig = value;
return this;
}

public Config Build()
{
Config configuration = new()
{
NextVersion = nextVerson,
VersioningMode = versioningMode
};

if (ignoreConfig != null)
{
configuration.Ignore = ignoreConfig;
}

ConfigurationBuilder configurationBuilder = new();
configuration = configurationBuilder.Add(configuration).Build();

if (withoutAnyTrackMergeTargets)
{
foreach (var branchConfiguration in configuration.Branches.Values)
{
branchConfiguration.TrackMergeTarget = false;
}
}

foreach (var item in trackMergeTargetsDictionary)
{
configuration.Branches[item.Key].TrackMergeTarget = item.Value;
}

foreach (var item in preventIncrementOfMergedBranchVersionDictionary)
{
configuration.Branches[item.Key].PreventIncrementOfMergedBranchVersion = item.Value;
}

return configuration;
}
}
Loading