Skip to content

Instantly share code, notes, and snippets.

@djspiewak
Created March 7, 2022 19:15
Show Gist options
  • Save djspiewak/297e03f9dd59e7809ca9120aa34e8e1c to your computer and use it in GitHub Desktop.
Save djspiewak/297e03f9dd59e7809ca9120aa34e8e1c to your computer and use it in GitHub Desktop.
// sbt-git workarounds (TODO upstream into sbt-tl)
inThisBuild {
git.uncommittedSignifier := Some("-SNAPSHOT")
git.formattedShaVersion := {
val Description = """^.*-(\d+)-[a-zA-Z0-9]+$""".r
val suffix = git.makeUncommittedSignifierSuffix(git.gitUncommittedChanges.value, git.uncommittedSignifier.value)
val description = Try("git describe --tags --match v*".!!.trim).toOption
val optDistance = description collect {
case Description(distance) => distance + "-"
}
val distance = optDistance.getOrElse("")
git.gitHeadCommit.value map { _.substring(0, 7) } map { sha =>
tlBaseVersion.value + "-" + distance + sha + suffix
}
}
git.gitUncommittedChanges := Try("git status -s".!!.trim.length > 0).getOrElse(true)
git.gitHeadCommit := Try("git rev-parse HEAD".!!.trim).toOption
git.gitCurrentTags := Try("git tag --contains HEAD".!!.trim.split("\\s+").toList.filter(_ != "")).toOption.toList.flatten
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment