Skip to content

Commit

Permalink
Support omitting the commit count (#65)
Browse files Browse the repository at this point in the history
We handle a negative `commitCountPad` value as request to not render the commit count at all.
  • Loading branch information
lefou authored Sep 1, 2022
1 parent 64cc46b commit f25ae7b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ The `format` method has the following options:

* `noTagFallback: String = "0.0.0"` - will be used when no tag was found
* `countSep: String = "-"` - will be printed before the commit count when it is greater than zero
* `commitCountPad: Byte = 0` - if greater that zero, the commit count will be padded to the given length
* `commitCountPad: Byte = 0` - if greater than zero, the commit count will be padded to the given length; a negative value results in never adding the commit count
* `revSep: String = "-"` - will be printed before the revision hash if it is not a tagged revision
* `revHashDigits: Int = 6` - the number of digits to be used for the revision hash
* `dirtySep: String = "-DIRTY"` - will be printed before the dirty hash if the local repository is in modified state
Expand Down
2 changes: 1 addition & 1 deletion core/src/de/tobiasroeser/mill/vcs/version/VcsState.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ case class VcsState(
val commitCountPart = if (lastTag.isEmpty || commitsSinceLastTag > 0) {
s"$countSep${if (commitCountPad > 0) {
(10000000000000L + commitsSinceLastTag).toString().substring(14 - commitCountPad, 14)
} else commitsSinceLastTag}"
} else if (commitCountPad == 0) commitsSinceLastTag else ""}"
} else ""

val revisionPart = if (lastTag.isEmpty || commitsSinceLastTag > 0) {
Expand Down
10 changes: 10 additions & 0 deletions core/test/src/de/tobiasroeser/mill/vcs/version/VcsStateSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,17 @@ class VcsStateSpec extends AnyFreeSpec {
case t => t
}) === "0.7.3v"
)
}

"should not render the commit count when commitCountPad is negative" in {
assert(
state("0.7.3", 4, "a6ea44d3726", "61568ec80f2465f3f01ea2c7e92273f4fbf94b01")
.format(dirtyHashDigits = 8, commitCountPad = -1, countSep = "") === "0.7.3-61568e-DIRTYa6ea44d3"
)
assert(
state("0.7.3", 4, null, "61568ec80f2465f3f01ea2c7e92273f4fbf94b01")
.format(dirtyHashDigits = 8, commitCountPad = -1, countSep = "") === "0.7.3-61568e"
)
}

"Example format configs" - {
Expand Down

0 comments on commit f25ae7b

Please sign in to comment.