Skip to content

Commit

Permalink
Allow building insignificant when normal claimed
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ajoberstar committed May 30, 2018
1 parent ce28b11 commit 8bf99d5
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 11 deletions.
22 changes: 11 additions & 11 deletions reckon-core/src/main/java/org/ajoberstar/reckon/core/Reckoner.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private Reckoner(VcsInventorySupplier inventorySupplier, Function<VcsInventory,

/**
* Infers the version that reflects the current state of your repository.
*
*
* @return the reckoned version
*/
public Version reckon() {
Expand All @@ -47,6 +47,10 @@ public Version reckon() {
throw new IllegalStateException("Reckoned version " + reckoned + " has already been released.");
}

if (inventory.getClaimedVersions().contains(targetNormal) && !inventory.getCurrentVersion().filter(targetNormal::equals).isPresent() && reckoned.isSignificant()) {
throw new IllegalStateException("Reckoned target normal version " + targetNormal + " has already been released.");
}

if (inventory.getBaseVersion().compareTo(reckoned) > 0) {
throw new IllegalStateException("Reckoned version " + reckoned + " is (and cannot be) less than base version " + inventory.getBaseVersion());
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -173,7 +173,7 @@ public Builder scopeCalc(Function<VcsInventory, Optional<String>> scopeCalc) {

/**
* Use the given stages as valid options during inference.
*
*
* @param stages the valid stages
* @return this builder
*/
Expand All @@ -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() {
Expand All @@ -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
*/
Expand All @@ -212,7 +212,7 @@ public Builder stageCalc(BiFunction<VcsInventory, Version, Optional<String>> sta

/**
* Builds the reckoner.
*
*
* @return the reckoner
*/
public Reckoner build() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 8bf99d5

Please sign in to comment.