sbt / sbt-dynver

An sbt plugin to dynamically set your version from git
Apache License 2.0
300 stars 47 forks source link

DynVer.isSnapshot is wrong when no tagPrefix is used #294

Open SuperFola opened 4 months ago

SuperFola commented 4 months ago

We have a use case where we do not use the tag prefix (our projects are tagged like 4.1.2, 12.0.0...), and make use of DynVer.isSnapshot to determine where we want to publish projects.

ThisBuild / publishTo := {
  val nexus: String = "https://nexus.example.net/repository/my-repository"
  val a = if (DynVer.isSnapshot())
    Some("Sonatype Nexus Repository Manager" at nexus + "-dev-snapshot")
  else {
    Some("Sonatype Nexus Repository Manager" at nexus + "-release")
  }

  a match {
    case Some(v) => streams.value.log.log(Level.Info, s">>> ${v.toString()} hasNoTag:${DynVer.hasNoTags()} isDirty:${DynVer.isDirty()} ${DynVer.tagPrefix}")
  }

  a
}

However in this example we always log the dev-snapshot repository, because hasNoTag is always true, because it is implemented as follows:

def hasNoTags(): Boolean = !ref.isTag

And isTag is based on the prefix (which we do not use, we have set ThisBuild / dynverVTagPrefix := false:

def isTag: Boolean     = value.startsWith(prefix)

I think it would be better to make use of inheritance on GitRef, so that a proper isTag could be implemented for GitCommit, GitTag, etc.