Skip to content

Commit

Permalink
Merge pull request #34 from dwijnand/helpers
Browse files Browse the repository at this point in the history
Introduce GitRef.isTag & GitCommitSuffix.isEmpty
  • Loading branch information
dwijnand authored Apr 1, 2017
2 parents e40a517 + 9cf52dc commit e0b8007
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/main/scala/sbtdynver/DynVerPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,17 @@ final case class GitDirtySuffix(value: String)

object GitRef extends (String => GitRef) {
final implicit class GitRefOps(val x: GitRef) extends AnyVal { import x._
def isTag: Boolean = value startsWith "v"
def dropV: GitRef = GitRef(value.replaceAll("^v", ""))
def mkString(prefix: String, suffix: String): String = if (value.isEmpty) "" else prefix + value + suffix
}
}

object GitCommitSuffix extends ((Int, String) => GitCommitSuffix) {
final implicit class GitCommitSuffixOps(val x: GitCommitSuffix) extends AnyVal { import x._
def isEmpty: Boolean = distance <= 0 || sha.isEmpty
def mkString(prefix: String, infix: String, suffix: String): String =
if (distance <= 0 || sha.isEmpty) "" else prefix + distance + infix + sha + suffix
if (isEmpty) "" else prefix + distance + infix + sha + suffix
}
}

Expand All @@ -63,7 +65,7 @@ final case class GitDescribeOutput(ref: GitRef, commitSuffix: GitCommitSuffix, d
def isSnapshot(): Boolean = isDirty() || hasNoTags()

def isDirty(): Boolean = dirtySuffix.value.nonEmpty
def hasNoTags(): Boolean = !(ref.value startsWith "v")
def hasNoTags(): Boolean = !ref.isTag
}

object GitDescribeOutput extends ((GitRef, GitCommitSuffix, GitDirtySuffix) => GitDescribeOutput) {
Expand Down

0 comments on commit e0b8007

Please sign in to comment.