forked from GitTools/GitVersion
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnrichIncrement.cs
More file actions
48 lines (42 loc) · 2.29 KB
/
Copy pathEnrichIncrement.cs
File metadata and controls
48 lines (42 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System.ComponentModel;
using GitVersion.Configuration;
using GitVersion.Extensions;
using GitVersion.Git;
namespace GitVersion.VersionCalculation.Mainline;
internal sealed class EnrichIncrement : IContextPreEnricher
{
public void Enrich(MainlineIteration iteration, MainlineCommit commit, MainlineContext context)
{
var effectiveConfiguration = commit.GetEffectiveConfiguration(context.Configuration);
var incrementForcedByBranch = effectiveConfiguration.Increment.ToVersionField();
var incrementForcedByCommit = commit.IsDummy
? VersionField.None
: GetIncrementForcedByCommit(context, commit.Value, effectiveConfiguration);
commit.Increment = incrementForcedByCommit;
context.Increment = context.Increment.Consolidate(incrementForcedByBranch, incrementForcedByCommit);
if (commit.Predecessor is not null && commit.Predecessor.BranchName != commit.BranchName)
context.Label = null;
context.Label ??= effectiveConfiguration.GetBranchSpecificLabel(commit.BranchName, null, context.Environment);
if (effectiveConfiguration.IsMainBranch)
context.BaseVersionSource = commit.Predecessor?.Value;
context.ForceIncrement |= effectiveConfiguration.IsMainBranch || commit.IsPredecessorTheLastCommitOnTrunk(context.Configuration);
}
private static VersionField GetIncrementForcedByCommit(
MainlineContext context, ICommit commit, EffectiveConfiguration configuration)
{
context.NotNull();
commit.NotNull();
configuration.NotNull();
return configuration.CommitMessageIncrementing switch
{
CommitMessageIncrementMode.Enabled
=> context.IncrementStrategyFinder.GetIncrementForcedByCommit(commit, context.Configuration),
CommitMessageIncrementMode.Disabled => VersionField.None,
CommitMessageIncrementMode.MergeMessageOnly => commit.IsMergeCommit
? context.IncrementStrategyFinder.GetIncrementForcedByCommit(commit, context.Configuration) : VersionField.None,
_ => throw new InvalidEnumArgumentException(
nameof(configuration.CommitMessageIncrementing), (int)configuration.CommitMessageIncrementing, typeof(CommitMessageIncrementMode)
)
};
}
}