sbt-git icon indicating copy to clipboard operation
sbt-git copied to clipboard

Multiple labeled tags leads to NumberFormatException during project load

Open fcv opened this issue 3 years ago • 3 comments

In case of multiple tags on HEAD, if any of them is labeled, then a NumberFormatException is thrown and project can't be loaded.

For example, let's say I have v1.0.0 and v1.0.1-alpha, an exception like the one below is thrown:

java.lang.NumberFormatException: For input string: "1-alpha"
	at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
	at java.base/java.lang.Integer.parseInt(Integer.java:652)
	at java.base/java.lang.Integer.valueOf(Integer.java:983)
	at versionsort.VersionHelper.compare(VersionHelper.java:32)
	at com.typesafe.sbt.SbtGit$git$.$anonfun$releaseVersion$3(SbtGit.scala:266)
	at com.typesafe.sbt.SbtGit$git$.$anonfun$releaseVersion$3$adapted(SbtGit.scala:266)
	at scala.math.Ordering$$anon$4.compare(Ordering.scala:234)
	at java.base/java.util.TimSort.countRunAndMakeAscending(TimSort.java:355)
	at java.base/java.util.TimSort.sort(TimSort.java:220)
	at java.base/java.util.Arrays.sort(Arrays.java:1441)
	at scala.collection.SeqLike.sorted(SeqLike.scala:659)
	at scala.collection.SeqLike.sorted$(SeqLike.scala:647)
	at scala.collection.AbstractSeq.sorted(Seq.scala:45)
	at scala.collection.SeqLike.sortWith(SeqLike.scala:612)
	at scala.collection.SeqLike.sortWith$(SeqLike.scala:612)
	at scala.collection.AbstractSeq.sortWith(Seq.scala:45)
	at com.typesafe.sbt.SbtGit$git$.releaseVersion(SbtGit.scala:266)
	at com.typesafe.sbt.SbtGit$.$anonfun$versionWithGit$8(SbtGit.scala:196)
	at scala.Function1.$anonfun$compose$1(Function1.scala:49)
	at sbt.internal.util.EvaluateSettings$MixedNode.evaluate0(INode.scala:228)
	at sbt.internal.util.EvaluateSettings$INode.evaluate(INode.scala:170)
	at sbt.internal.util.EvaluateSettings.$anonfun$submitEvaluate$1(INode.scala:87)
	at sbt.internal.util.EvaluateSettings.sbt$internal$util$EvaluateSettings$$run0(INode.scala:99)
	at sbt.internal.util.EvaluateSettings$$anon$3.run(INode.scala:94)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)
[error] java.lang.NumberFormatException: For input string: "1-alpha"
[error] Use 'last' for the full log.

From what I could check it's related to https://github.com/sbt/sbt-git/pull/162 and the fact that versionsort.VersionHelper expects tags to strictly follow a pattern like \d(\.\d)+ failing otherwise.

Affected version: 1.0.1.

In order to support projects using different tagging patterns would it be possible to make the tag ordering configurable or disable it altogether?

Ps.: I would be willing to contribute.

fcv avatar Sep 30 '21 06:09 fcv

For the next person that hits this.

It looks to be caused by https://github.com/sbt/sbt-git/blob/v1.0.2/src/main/scala/com/typesafe/sbt/SbtGit.scala#L266

Which looks to be fixed in the 2.0 version https://github.com/sbt/sbt-git/blob/main/src/main/scala/com/github/sbt/git/GitPlugin.scala#L303

You can get around it in 1.x by relying on git describe versioning and disabling tag versioning by filtering all tags:

git.useGitDescribe := true
git.gitDescribePatterns := Seq("v[0-9]*")
git.gitTagToVersionNumber := { _: String => None }

spangaer avatar Jul 05 '22 09:07 spangaer

Dang. I just now discovered that that omits dropping the v-prefix. So it looks 2.0 is a better way forward.

spangaer avatar Sep 06 '22 15:09 spangaer

Ok, I found a similar but not the same problem that bubbles up in a multi tag context.

https://github.com/sbt/sbt-git/blob/v2.0.0/src/main/scala/com/github/sbt/git/GitPlugin.scala#L275

If this needs to sort x.y.z-alpha-1, you also get a number format exception.

As with the previous problem, it only surfaces if you have multiple results that need sorting.

spangaer avatar Dec 06 '22 12:12 spangaer