From f6cc4c51dc5da474b904e18b5ddcddea6711130a Mon Sep 17 00:00:00 2001 From: Andrew Oberstar Date: Sun, 18 Sep 2016 17:38:51 -0500 Subject: [PATCH] Fix STAGE_FLOAT to check if normal changed Fixes #210 by ensuring that the nearest any's normal is the same as being inferred by the current build. If it is, then continue checking precedence of preRelease, otherwise just use the float stage on its own. --- .../gradle/git/release/opinion/Strategies.groovy | 7 ++++--- .../gradle/git/release/opinion/StrategiesSpec.groovy | 12 ++++++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main/groovy/org/ajoberstar/gradle/git/release/opinion/Strategies.groovy b/src/main/groovy/org/ajoberstar/gradle/git/release/opinion/Strategies.groovy index b6108e0..37ebc3d 100644 --- a/src/main/groovy/org/ajoberstar/gradle/git/release/opinion/Strategies.groovy +++ b/src/main/groovy/org/ajoberstar/gradle/git/release/opinion/Strategies.groovy @@ -198,9 +198,10 @@ final class Strategies { * to the nearest any's pre-release. */ static final PartialSemVerStrategy STAGE_FLOAT = closure { state -> - def nearestPreRelease = state.nearestVersion.any.preReleaseVersion - if (nearestPreRelease != null && nearestPreRelease > state.stageFromProp) { - state.copyWith(inferredPreRelease: "${nearestPreRelease}.${state.stageFromProp}") + def sameNormal = state.inferredNormal == state.nearestVersion.any.normalVersion + def nearestAnyPreRelease = state.nearestVersion.any.preReleaseVersion + if (sameNormal && nearestAnyPreRelease != null && nearestAnyPreRelease > state.stageFromProp) { + state.copyWith(inferredPreRelease: "${nearestAnyPreRelease}.${state.stageFromProp}") } else { state.copyWith(inferredPreRelease: state.stageFromProp) } diff --git a/src/test/groovy/org/ajoberstar/gradle/git/release/opinion/StrategiesSpec.groovy b/src/test/groovy/org/ajoberstar/gradle/git/release/opinion/StrategiesSpec.groovy index b2e5f1c..5c43329 100644 --- a/src/test/groovy/org/ajoberstar/gradle/git/release/opinion/StrategiesSpec.groovy +++ b/src/test/groovy/org/ajoberstar/gradle/git/release/opinion/StrategiesSpec.groovy @@ -245,16 +245,20 @@ class StrategiesSpec extends Specification { given: def initialState = new SemVerStrategyState( stageFromProp: 'boom', + inferredNormal: '1.1.0', inferredPreRelease: 'other', - nearestVersion: new NearestVersion(any: Version.valueOf(nearest))) + nearestVersion: new NearestVersion( + normal: Version.valueOf('1.0.0'), + any: Version.valueOf(nearest))) expect: Strategies.PreRelease.STAGE_FLOAT.infer(initialState) == initialState.copyWith(inferredPreRelease: expected) where: nearest | expected '1.0.0' | 'boom' - '1.0.0-and.1' | 'boom' - '1.0.0-cat.1' | 'cat.1.boom' - '1.0.0-cat.something.else' | 'cat.something.else.boom' + '1.0.1-cat.something.else' | 'boom' + '1.1.0-and.1' | 'boom' + '1.1.0-cat.1' | 'cat.1.boom' + '1.1.0-cat.something.else' | 'cat.something.else.boom' } def 'PreRelease.COUNT_INCREMENTED will increment the nearest any\'s pre release or set to 1 if not found'() {