diff --git a/plugin/src/main/scala/io/isomarcte/sbt/version/scheme/enforcer/plugin/Keys.scala b/plugin/src/main/scala/io/isomarcte/sbt/version/scheme/enforcer/plugin/Keys.scala index 618bc2f..d507468 100644 --- a/plugin/src/main/scala/io/isomarcte/sbt/version/scheme/enforcer/plugin/Keys.scala +++ b/plugin/src/main/scala/io/isomarcte/sbt/version/scheme/enforcer/plugin/Keys.scala @@ -44,6 +44,11 @@ trait Keys { ).mkString(" ") ) + final val versionSchemeEnforcerPreviousVCSTagStringTransformer: SettingKey[String => String] = + settingKey[String => String]( + "This setting operates only on the String representation of a VCS Tag and allows transforming that string." + ) + final val versionSchemeEnforcerTagDomain: SettingKey[TagDomain] = settingKey[TagDomain]( "The domain of VCS tags to consider when looking for previous releases to use in the binary compatibility check. For example, this can be TagDomain.All to consider all tags on the repository, or TagDomain.Reachable to only consider tags which are reachable (ancestors) of the current commit. The later case can be useful when you have multiple branches which should not be considered directly related for the purposes of binary compatibility. TagDomain.All is the default as of 2.1.1.0. The behavior prior to 2.1.1.0 was equivalent to TagDomain.Reachable." ) diff --git a/plugin/src/main/scala/io/isomarcte/sbt/version/scheme/enforcer/plugin/SbtVersionSchemeEnforcerPlugin.scala b/plugin/src/main/scala/io/isomarcte/sbt/version/scheme/enforcer/plugin/SbtVersionSchemeEnforcerPlugin.scala index c6840ba..fadf242 100644 --- a/plugin/src/main/scala/io/isomarcte/sbt/version/scheme/enforcer/plugin/SbtVersionSchemeEnforcerPlugin.scala +++ b/plugin/src/main/scala/io/isomarcte/sbt/version/scheme/enforcer/plugin/SbtVersionSchemeEnforcerPlugin.scala @@ -53,7 +53,16 @@ object SbtVersionSchemeEnforcerPlugin extends AutoPlugin { .flatMap(_.lastOption) .fold(initialValue)(previousTag => Some(previousTag.value)) ) + .map(versionSchemeEnforcerPreviousVCSTagStringTransformer.value) } + }, + versionSchemeEnforcerPreviousVCSTagStringTransformer := { + versionSchemeEnforcerPreviousVCSTagStringTransformer + .? + .value + .getOrElse { + _.stripPrefix("v").stripPrefix("V") + } } ) diff --git a/vcs-tests/git/correct-value-tests.sh b/vcs-tests/git/correct-value-tests.sh index 5fd4d45..cdfa390 100755 --- a/vcs-tests/git/correct-value-tests.sh +++ b/vcs-tests/git/correct-value-tests.sh @@ -99,15 +99,23 @@ rm initial.sbt # One tag, no new commits -git tag '0.0.0.1' @ +git tag -m "" '0.0.0.1' @ check_result 'Some(0.0.0.1)' -# Two tags, should only find the most recent one +# Tag transform test add_commit -git tag '0.0.0.2' @ +git tag -m "" 'v0.0.0.2-M1' + +check_result 'Some(0.0.0.2-M1)' + +# Two or more tags, should only find the most recent one + +add_commit + +git tag -m "" '0.0.0.2' @ check_result 'Some(0.0.0.2)' @@ -115,13 +123,13 @@ check_result 'Some(0.0.0.2)' add_commit -git tag '0.0.0.3-M1' +git tag -m "" '0.0.0.3-M1' check_result 'Some(0.0.0.3-M1)' add_commit -git tag '0.0.0.3-M2' +git tag -m "" '0.0.0.3-M2' check_result 'Some(0.0.0.3-M2)' @@ -145,7 +153,7 @@ git checkout branchB add_commit -git tag '0.0.0.4' +git tag -m "" '0.0.0.4' check_result 'Some(0.0.0.4)'