Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce GitRef.isTag & GitCommitSuffix.isEmpty #34

Merged
merged 1 commit into from
Apr 1, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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