From 8107bf471e7aa5f2ec864c86b193e0826f9b8b5c Mon Sep 17 00:00:00 2001 From: Andrew Oberstar Date: Sun, 23 Aug 2015 17:03:42 -0500 Subject: [PATCH] Revert "Don't fail version inference if no commits" This reverts commit 1923b808018bf379426ca81a51f9ef845fb6392d. There are too many scattered changes. I'm not going to tackle this now. See #112. --- .../semver/NearestVersionLocator.groovy | 33 +++---------------- .../semver/NearestVersionLocatorSpec.groovy | 11 ------- 2 files changed, 5 insertions(+), 39 deletions(-) diff --git a/src/main/groovy/org/ajoberstar/gradle/git/release/semver/NearestVersionLocator.groovy b/src/main/groovy/org/ajoberstar/gradle/git/release/semver/NearestVersionLocator.groovy index 9565fcc..c8c2a8a 100644 --- a/src/main/groovy/org/ajoberstar/gradle/git/release/semver/NearestVersionLocator.groovy +++ b/src/main/groovy/org/ajoberstar/gradle/git/release/semver/NearestVersionLocator.groovy @@ -19,7 +19,6 @@ import com.github.zafarkhaja.semver.Version import org.ajoberstar.grgit.Commit import org.ajoberstar.grgit.Grgit -import org.ajoberstar.grgit.exception.GrgitException import org.slf4j.Logger import org.slf4j.LoggerFactory @@ -74,14 +73,7 @@ class NearestVersionLocator { */ NearestVersion locate(Grgit grgit) { logger.debug('Locate beginning on branch: {}', grgit.branch.current.fullName) - - Commit head - try { - head = grgit.head() - } catch (GrgitException e) { - head = null - } - + Commit head = grgit.head() List versionTags = grgit.tag.list().inject([]) { list, tag -> Version version = TagUtil.parseAsVersion(tag) logger.debug('Tag {} ({}) parsed as {} version.', tag.name, tag.commit.abbreviatedId, version) @@ -121,25 +113,10 @@ class NearestVersionLocator { a.distance <=> b.distance ?: (a.version <=> b.version) * -1 } - Version anyVersion - int distanceFromAny - if (any) { - anyVersion = any.version - distanceFromAny = any.distance - } else { - anyVersion = Version.valueOf('0.0.0') - distanceFromAny = head ? grgit.log(includes: [head.id]).size() : 0 - } - - Version normalVersion - int distanceFromNormal - if (normal) { - normalVersion = normal.version - distanceFromNormal = normal.distance - } else { - normalVersion = Version.valueOf('0.0.0') - distanceFromNormal = head ? grgit.log(includes: [head.id]).size() : 0 - } + Version anyVersion = any ? any.version : Version.valueOf('0.0.0') + Version normalVersion = normal ? normal.version : Version.valueOf('0.0.0') + int distanceFromAny = any ? any.distance : grgit.log(includes: [head.id]).size() + int distanceFromNormal = normal ? normal.distance : grgit.log(includes: [head.id]).size() return new NearestVersion(anyVersion, normalVersion, distanceFromAny, distanceFromNormal) } diff --git a/src/test/groovy/org/ajoberstar/gradle/git/release/semver/NearestVersionLocatorSpec.groovy b/src/test/groovy/org/ajoberstar/gradle/git/release/semver/NearestVersionLocatorSpec.groovy index d3b25b0..5148b3d 100644 --- a/src/test/groovy/org/ajoberstar/gradle/git/release/semver/NearestVersionLocatorSpec.groovy +++ b/src/test/groovy/org/ajoberstar/gradle/git/release/semver/NearestVersionLocatorSpec.groovy @@ -116,17 +116,6 @@ class NearestVersionLocatorSpec extends Specification { 'unreachable' | '0.0.0' | '0.0.0' | 2 } - def 'locator returns 0.0.0 when no commits'() { - given: - repoDir = Files.createTempDirectory('empty-repo').toFile() - grgit = Grgit.init(dir: repoDir) - expect: - def nearest = new NearestVersionLocator().locate(grgit) - nearest.any == Version.valueOf('0.0.0') - nearest.normal == Version.valueOf('0.0.0') - nearest.distanceFromNormal == 0 - } - private void commit() { byte[] bytes = new byte[128] random.nextBytes(bytes)