From 8bf99d57b45ffe628d314fcf6ca3fb4e33aed87b Mon Sep 17 00:00:00 2001 From: Andrew Oberstar Date: Tue, 29 May 2018 21:44:04 -0500 Subject: [PATCH] Allow building insignificant when normal claimed On top of already allowing a rebuild of a tagged version that's already claimed, we should allow rebuilding insignificant versions. As noted in the issue, this allows use of git bisect on reckoned repos. This fixes #78. --- .../org/ajoberstar/reckon/core/Reckoner.java | 22 ++++++------ .../reckon/core/ReckonerTest.groovy | 34 +++++++++++++++++++ 2 files changed, 45 insertions(+), 11 deletions(-) diff --git a/reckon-core/src/main/java/org/ajoberstar/reckon/core/Reckoner.java b/reckon-core/src/main/java/org/ajoberstar/reckon/core/Reckoner.java index c7019aea..ec4abe7c 100644 --- a/reckon-core/src/main/java/org/ajoberstar/reckon/core/Reckoner.java +++ b/reckon-core/src/main/java/org/ajoberstar/reckon/core/Reckoner.java @@ -35,7 +35,7 @@ private Reckoner(VcsInventorySupplier inventorySupplier, Function 0) { throw new IllegalStateException("Reckoned version " + reckoned + " is (and cannot be) less than base version " + inventory.getBaseVersion()); } @@ -78,10 +82,6 @@ private Version reckonNormal(VcsInventory inventory) { targetNormal = targetNormal.incrementNormal(scope); } - if (inventory.getClaimedVersions().contains(targetNormal) && !inventory.getCurrentVersion().filter(targetNormal::equals).isPresent()) { - throw new IllegalStateException("Reckoned target normal version " + targetNormal + " has already been released."); - } - return targetNormal; } @@ -147,7 +147,7 @@ Builder vcs(VcsInventorySupplier inventorySupplier) { /** * Use the given JGit repository to infer the state of Git. - * + * * @param repo repository that the version should be inferred from * @return this builder */ @@ -162,7 +162,7 @@ public Builder git(Repository repo) { /** * Use the given function to determine what scope should be used when inferring the version. - * + * * @param scopeCalc the function that provides the scope * @return this builder */ @@ -173,7 +173,7 @@ public Builder scopeCalc(Function> scopeCalc) { /** * Use the given stages as valid options during inference. - * + * * @param stages the valid stages * @return this builder */ @@ -189,7 +189,7 @@ public Builder stages(String... stages) { /** * Use only the {@code snapshot} and {@code final} stages. Alternative to calling {@code stages()}. - * + * * @return this builder */ public Builder snapshots() { @@ -201,7 +201,7 @@ public Builder snapshots() { /** * Use the given function to determine what staged should be used when inferring the version. This * must return a version contained in {@code stages()}. - * + * * @param stageCalc the function that provides the stage * @return this builder */ @@ -212,7 +212,7 @@ public Builder stageCalc(BiFunction> sta /** * Builds the reckoner. - * + * * @return the reckoner */ public Reckoner build() { diff --git a/reckon-core/src/test/groovy/org/ajoberstar/reckon/core/ReckonerTest.groovy b/reckon-core/src/test/groovy/org/ajoberstar/reckon/core/ReckonerTest.groovy index a9b220c2..27007479 100644 --- a/reckon-core/src/test/groovy/org/ajoberstar/reckon/core/ReckonerTest.groovy +++ b/reckon-core/src/test/groovy/org/ajoberstar/reckon/core/ReckonerTest.groovy @@ -189,6 +189,40 @@ class ReckonerTest extends Specification { reckonStage(inventory, null, null) == '0.1.0' } + def 'if target normal claimed, but building insignificant, succeed'() { + given: + def inventory = new VcsInventory( + 'abcdef', + true, + null, + Version.valueOf('0.0.0'), + Version.valueOf('0.0.0'), + 1, + [] as Set, + [Version.valueOf('0.1.0'), Version.valueOf('0.1.1'), Version.valueOf('0.2.0')] as Set + ) + expect: + reckonStage(inventory, null, null) == '0.1.0-beta.0.1+abcdef' + } + + def 'if target normal claimed, and building significant, throw'() { + given: + def inventory = new VcsInventory( + 'abcdef', + true, + null, + Version.valueOf('0.0.0'), + Version.valueOf('0.0.0'), + 1, + [] as Set, + [Version.valueOf('0.1.0'), Version.valueOf('0.1.1'), Version.valueOf('0.2.0')] as Set + ) + when: + reckonStage(inventory, null, 'rc') + then: + thrown(IllegalStateException) + } + def 'if scope supplier returns invalid scope, throw'() { given: def inventory = new VcsInventory(