@@ -40,7 +40,7 @@ public VersionField DetermineIncrementedField(
4040 configuration . NotNull ( ) ;
4141
4242 var commitMessageIncrement = FindCommitMessageIncrement (
43- configuration , baseVersion . BaseVersionSource , currentCommit , label ) ;
43+ configuration , baseVersion , currentCommit , label ) ;
4444
4545 var defaultIncrement = configuration . Increment . ToVersionField ( ) ;
4646
@@ -81,31 +81,38 @@ public VersionField DetermineIncrementedField(
8181 }
8282
8383 private VersionField ? FindCommitMessageIncrement (
84- EffectiveConfiguration configuration , ICommit ? baseCommit , ICommit ? currentCommit , string ? label )
84+ EffectiveConfiguration configuration , BaseVersion baseVersion , ICommit ? currentCommit , string ? label )
8585 {
8686 if ( configuration . CommitMessageIncrementing == CommitMessageIncrementMode . Disabled )
8787 {
8888 return null ;
8989 }
9090
91+ var baseCommit = baseVersion . BaseVersionSource ;
92+
9193 //get tags with valid version - depends on configuration (see #3757)
9294 var targetShas = new Lazy < IReadOnlySet < string > > ( ( ) =>
9395 this . taggedSemanticVersionRepository . GetTaggedSemanticVersions ( configuration . TagPrefix , configuration . SemanticVersionFormat )
94- . SelectMany ( _ => _ ) . Where ( _ => _ . Value . IsMatchForBranchSpecificLabel ( label ) ) . Select ( _ => _ . Tag . TargetSha ) . ToHashSet ( )
96+ . SelectMany ( _ => _ ) . Where ( _ => _ . Value . IsMatchForBranchSpecificLabel ( label ) ) . Select ( _ => _ . Tag . TargetSha ) . ToHashSet ( )
9597 ) ;
9698
97- var commits = GetIntermediateCommits ( baseCommit , currentCommit ) ;
99+ var targetTags = this . taggedSemanticVersionRepository
100+ . GetTaggedSemanticVersions ( configuration . TagPrefix , configuration . SemanticVersionFormat )
101+ . SelectMany ( _ => _ ) . Where ( element => element . Value . IsMatchForBranchSpecificLabel ( label )
102+ && element . Value . CompareTo ( baseVersion . GetSemanticVersion ( ) ) == 0 ) . Select ( _ => _ . Tag . TargetSha ) . ToHashSet ( ) ;
103+
104+ var intermediateCommits = GetIntermediateCommits ( baseCommit , currentCommit ) ;
98105 // consider commit messages since latest tag only (see #3071)
99- commits = commits
106+ var commits = intermediateCommits
100107 . Reverse ( )
101- . TakeWhile ( x => ! targetShas . Value . Contains ( x . Sha ) )
108+ . TakeWhile ( x => baseCommit != x )
109+ . Where ( element => ! targetShas . Value . Contains ( element . Sha ) )
102110 . Reverse ( ) ;
103111
104112 if ( configuration . CommitMessageIncrementing == CommitMessageIncrementMode . MergeMessageOnly )
105113 {
106114 commits = commits . Where ( c => c . Parents . Count ( ) > 1 ) ;
107115 }
108-
109116 return GetIncrementForCommits (
110117 majorVersionBumpMessage : configuration . MajorVersionBumpMessage ,
111118 minorVersionBumpMessage : configuration . MinorVersionBumpMessage ,
0 commit comments