Skip to content

Commit 2f7e406

Browse files
committed
ws
1 parent 464a5d8 commit 2f7e406

File tree

3 files changed

+70
-74
lines changed

3 files changed

+70
-74
lines changed

src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/MergeMessageVersionStrategy.cs

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,38 +37,40 @@ private IEnumerable<BaseVersion> GetBaseVersionsInternal(EffectiveBranchConfigur
3737

3838
foreach (var commit in configuration.Value.Ignore.Filter(Context.CurrentBranchCommits.ToArray()))
3939
{
40-
if (MergeMessage.TryParse(commit, Context.Configuration, out var mergeMessage)
41-
&& mergeMessage.Version is not null
42-
&& Context.Configuration.IsReleaseBranch(mergeMessage.MergedBranch!))
40+
if (!MergeMessage.TryParse(commit, Context.Configuration, out var mergeMessage)
41+
|| mergeMessage.Version is null
42+
|| !Context.Configuration.IsReleaseBranch(mergeMessage.MergedBranch!))
4343
{
44-
this.log.Info($"Found commit [{commit}] matching merge message format: {mergeMessage.FormatName}");
44+
continue;
45+
}
4546

46-
var baseVersionSource = commit;
47-
if (commit.IsMergeCommit())
48-
{
49-
baseVersionSource = this.repositoryStore.FindMergeBase(commit.Parents[0], commit.Parents[1]);
50-
}
47+
this.log.Info($"Found commit [{commit}] matching merge message format: {mergeMessage.FormatName}");
5148

52-
var label = configuration.Value.GetBranchSpecificLabel(Context.CurrentBranch.Name, null);
53-
var increment = configuration.Value.PreventIncrementOfMergedBranch
54-
? VersionField.None : incrementStrategyFinder.DetermineIncrementedField(
55-
currentCommit: Context.CurrentCommit,
56-
baseVersionSource: baseVersionSource,
57-
shouldIncrement: true,
58-
configuration: configuration.Value,
59-
label: label
60-
);
49+
var baseVersionSource = commit;
50+
if (commit.IsMergeCommit())
51+
{
52+
baseVersionSource = this.repositoryStore.FindMergeBase(commit.Parents[0], commit.Parents[1]);
53+
}
6154

62-
yield return new BaseVersion($"Merge message '{commit.Message.Trim()}'", mergeMessage.Version)
55+
var label = configuration.Value.GetBranchSpecificLabel(Context.CurrentBranch.Name, null);
56+
var increment = configuration.Value.PreventIncrementOfMergedBranch
57+
? VersionField.None : this.incrementStrategyFinder.DetermineIncrementedField(
58+
currentCommit: Context.CurrentCommit,
59+
baseVersionSource: baseVersionSource,
60+
shouldIncrement: true,
61+
configuration: configuration.Value,
62+
label: label
63+
);
64+
65+
yield return new BaseVersion($"Merge message '{commit.Message.Trim()}'", mergeMessage.Version)
66+
{
67+
Operator = new()
6368
{
64-
Operator = new()
65-
{
66-
Increment = increment,
67-
ForceIncrement = false,
68-
Label = label
69-
}
70-
};
71-
}
69+
Increment = increment,
70+
ForceIncrement = false,
71+
Label = label
72+
}
73+
};
7274
}
7375
}
7476
}

src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/TrackReleaseBranchesVersionStrategy.cs

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,12 @@ public IEnumerable<BaseVersion> GetBaseVersions(EffectiveBranchConfiguration con
2929
if (!Context.Configuration.VersionStrategy.HasFlag(VersionStrategies.TrackReleaseBranches))
3030
yield break;
3131

32-
if (configuration.Value.TracksReleaseBranches)
32+
if (!configuration.Value.TracksReleaseBranches) yield break;
33+
foreach (var releaseBranch in this.branchRepository.GetReleaseBranches(Context.Configuration))
3334
{
34-
foreach (var releaseBranche in branchRepository.GetReleaseBranches(Context.Configuration))
35+
if (TryGetBaseVersion(releaseBranch, configuration, out var baseVersion))
3536
{
36-
if (TryGetBaseVersion(releaseBranche, configuration, out var baseVersion))
37-
{
38-
yield return baseVersion;
39-
}
37+
yield return baseVersion;
4038
}
4139
}
4240
}
@@ -47,31 +45,29 @@ private bool TryGetBaseVersion(
4745
result = null;
4846

4947
var releaseBranchConfiguration = Context.Configuration.GetEffectiveBranchConfiguration(releaseBranch);
50-
if (this.releaseVersionStrategy.TryGetBaseVersion(releaseBranchConfiguration, out var baseVersion))
51-
{
52-
// Find the commit where the child branch was created.
53-
var baseVersionSource = this.repositoryStore.FindMergeBase(releaseBranch, Context.CurrentBranch);
54-
var label = configuration.Value.GetBranchSpecificLabel(Context.CurrentBranch.Name, null);
55-
var increment = incrementStrategyFinder.DetermineIncrementedField(
56-
currentCommit: Context.CurrentCommit,
57-
baseVersionSource: baseVersionSource,
58-
shouldIncrement: true,
59-
configuration: configuration.Value,
60-
label: label
61-
);
48+
if (!this.releaseVersionStrategy.TryGetBaseVersion(releaseBranchConfiguration, out var baseVersion)) return result is not null;
49+
// Find the commit where the child branch was created.
50+
var baseVersionSource = this.repositoryStore.FindMergeBase(releaseBranch, Context.CurrentBranch);
51+
var label = configuration.Value.GetBranchSpecificLabel(Context.CurrentBranch.Name, null);
52+
var increment = this.incrementStrategyFinder.DetermineIncrementedField(
53+
currentCommit: Context.CurrentCommit,
54+
baseVersionSource: baseVersionSource,
55+
shouldIncrement: true,
56+
configuration: configuration.Value,
57+
label: label
58+
);
6259

63-
result = new BaseVersion(
64-
"Release branch exists -> " + baseVersion.Source, baseVersion.SemanticVersion, baseVersionSource)
60+
result = new BaseVersion(
61+
"Release branch exists -> " + baseVersion.Source, baseVersion.SemanticVersion, baseVersionSource)
62+
{
63+
Operator = new BaseVersionOperator
6564
{
66-
Operator = new BaseVersionOperator
67-
{
68-
Increment = increment,
69-
ForceIncrement = false,
70-
Label = label
71-
}
72-
};
73-
}
65+
Increment = increment,
66+
ForceIncrement = false,
67+
Label = label
68+
}
69+
};
7470

75-
return result is not null;
71+
return true;
7672
}
7773
}

src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/VersionInBranchNameVersionStrategy.cs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,26 @@ public bool TryGetBaseVersion(EffectiveBranchConfiguration configuration, [NotNu
3535

3636
foreach (var branch in new[] { Context.CurrentBranch, configuration.Branch })
3737
{
38-
if (branch.Name.TryGetSemanticVersion(out var result, configuration.Value))
38+
if (!branch.Name.TryGetSemanticVersion(out var result, configuration.Value)) continue;
39+
string? branchNameOverride = null;
40+
if (!result.Name.IsNullOrEmpty() && (Context.CurrentBranch.Name.Equals(branch.Name)
41+
|| Context.Configuration.GetBranchConfiguration(Context.CurrentBranch.Name).Label is null))
3942
{
40-
string? branchNameOverride = null;
41-
if (!result.Name.IsNullOrEmpty() && (Context.CurrentBranch.Name.Equals(branch.Name)
42-
|| Context.Configuration.GetBranchConfiguration(Context.CurrentBranch.Name).Label is null))
43-
{
44-
branchNameOverride = result.Name;
45-
}
43+
branchNameOverride = result.Name;
44+
}
4645

47-
var label = configuration.Value.GetBranchSpecificLabel(Context.CurrentBranch.Name, branchNameOverride);
46+
var label = configuration.Value.GetBranchSpecificLabel(Context.CurrentBranch.Name, branchNameOverride);
4847

49-
baseVersion = new BaseVersion("Version in branch name", result.Value)
48+
baseVersion = new BaseVersion("Version in branch name", result.Value)
49+
{
50+
Operator = new BaseVersionOperator
5051
{
51-
Operator = new BaseVersionOperator
52-
{
53-
Increment = VersionField.None,
54-
ForceIncrement = false,
55-
Label = label
56-
}
57-
};
58-
return true;
59-
}
52+
Increment = VersionField.None,
53+
ForceIncrement = false,
54+
Label = label
55+
}
56+
};
57+
return true;
6058
}
6159

6260
return false;

0 commit comments

Comments
 (0)