Skip to content
This repository has been archived by the owner on Oct 5, 2018. It is now read-only.

Commit

Permalink
Revert "Don't fail version inference if no commits"
Browse files Browse the repository at this point in the history
This reverts commit 1923b80.

There are too many scattered changes. I'm not going to tackle this
now. See #112.
  • Loading branch information
ajoberstar committed Aug 23, 2015
1 parent d24e043 commit 8107bf4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8107bf4

Please # to comment.