Repository: scala-steward-org/scala-steward
Pull request #2367 (2021-11-20 13:14:56)

Do not select versions with a "smaller" pre-release identifier
Prevents PRs like https://github.com/VirtusLab/scala-cli/pull/407.

codecov[bot]: # [Codecov](https://codecov.io/gh/scala-steward-org/scala-steward/pull/2367?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scala-steward-org) Report
> Merging [#2367](https://codecov.io/gh/scala-steward-org/scala-steward/pull/2367?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scala-steward-org) (98f02c0) into [master](https://codecov.io/gh/scala-steward-org/scala-steward/commit/a520abaa166477aea97ece2bcbab56cd6d397e72?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scala-steward-org) (a520aba) will **increase** coverage by `0.03%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/scala-steward-org/scala-steward/pull/2367/graphs/tree.svg?width=650&height=150&src=pr&token=udzMsc1Dne&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scala-steward-org)](https://codecov.io/gh/scala-steward-org/scala-steward/pull/2367?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scala-steward-org)

```diff
@@            Coverage Diff             @@
##           master    #2367      +/-   ##
==========================================
+ Coverage   80.27%   80.31%   +0.03%     
==========================================
  Files         139      138       -1     
  Lines        2388     2387       -1     
  Branches       55       58       +3     
==========================================
  Hits         1917     1917              
+ Misses        471      470       -1     
```


| [Impacted Files](https://codecov.io/gh/scala-steward-org/scala-steward/pull/2367?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scala-steward-org) | Coverage Δ | |
|---|---|---|
| [...ain/scala/org/scalasteward/core/data/Version.scala](https://codecov.io/gh/scala-steward-org/scala-steward/pull/2367/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scala-steward-org#diff-bW9kdWxlcy9jb3JlL3NyYy9tYWluL3NjYWxhL29yZy9zY2FsYXN0ZXdhcmQvY29yZS9kYXRhL1ZlcnNpb24uc2NhbGE=) | `97.59% <100.00%> (ø)` | |
| [...la-2.12/org/scalasteward/mill/plugin/package.scala](https://codecov.io/gh/scala-steward-org/scala-steward/pull/2367/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scala-steward-org#diff-bW9kdWxlcy9taWxsLXBsdWdpbi9zcmMvbWFpbi9zY2FsYS0yLjEyL29yZy9zY2FsYXN0ZXdhcmQvbWlsbC9wbHVnaW4vcGFja2FnZS5zY2FsYQ==) | | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/scala-steward-org/scala-steward/pull/2367?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scala-steward-org).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scala-steward-org)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/scala-steward-org/scala-steward/pull/2367?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scala-steward-org). Last update [a520aba...98f02c0](https://codecov.io/gh/scala-steward-org/scala-steward/pull/2367?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scala-steward-org). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scala-steward-org).


Patch:
diff --git a/.scalafmt.conf b/.scalafmt.conf
index aecb0023..fff12fe9 100644
--- a/.scalafmt.conf
+++ b/.scalafmt.conf
@@ -1,4 +1,4 @@
-version = 3.1.1
+version = 3.1.2
 runner.dialect = scala213
 assumeStandardLibraryStripMargin = true
 align.openParenCallSite = false
diff --git a/modules/core/src/main/scala/org/scalasteward/core/data/Version.scala b/modules/core/src/main/scala/org/scalasteward/core/data/Version.scala
index 23dea24b..feb3319b 100644
--- a/modules/core/src/main/scala/org/scalasteward/core/data/Version.scala
+++ b/modules/core/src/main/scala/org/scalasteward/core/data/Version.scala
@@ -53,9 +53,9 @@ final case class Version(value: String) {
           // Do not select pre-releases of the same series if this is not a pre-release.
           (v.isPreRelease && !isPreRelease && sameSeries) ||
           // Do not select versions with pre-release identifiers whose order is smaller
-          // than the order of pre-release identifiers in this version. This, for example,
-          // prevents updates from 2.1.4.0-RC17 to 2.1.4.0-RC17+1-307f2f6c-SNAPSHOT.
-          ((minAlphaOrder < 0) && (v.minAlphaOrder < minAlphaOrder)) ||
+          // than the order of possible pre-release identifiers in this version. This,
+          // for example, prevents updates from 2.1.4.0-RC17 to 2.1.4.0-RC17+1-307f2f6c-SNAPSHOT.
+          v.minAlphaOrder < minAlphaOrder ||
           // Do not select versions that are identical up to the hashes.
           v.alnumComponents === alnumComponents ||
           // Do not select a version with hash if this version contains no hash.
diff --git a/modules/core/src/main/scala/org/scalasteward/core/git/FileGitAlg.scala b/modules/core/src/main/scala/org/scalasteward/core/git/FileGitAlg.scala
index 98e57cb5..941dd5eb 100644
--- a/modules/core/src/main/scala/org/scalasteward/core/git/FileGitAlg.scala
+++ b/modules/core/src/main/scala/org/scalasteward/core/git/FileGitAlg.scala
@@ -68,6 +68,9 @@ final class FileGitAlg[F[_]](config: GitCfg)(implicit
     git("rev-parse", "--abbrev-ref", Branch.head.name)(repo)
       .map(lines => Branch(lines.mkString.trim))
 
+  override def deleteLocalBranch(repo: File, branch: Branch): F[Unit] =
+    git("branch", "--delete", "--force", branch.name)(repo).void
+
   override def deleteRemoteBranch(repo: File, branch: Branch): F[Unit] =
     git("push", "origin", "--delete", branch.name)(repo).void
 
diff --git a/modules/core/src/main/scala/org/scalasteward/core/git/GenGitAlg.scala b/modules/core/src/main/scala/org/scalasteward/core/git/GenGitAlg.scala
index 3a61c1e6..6f570a6d 100644
--- a/modules/core/src/main/scala/org/scalasteward/core/git/GenGitAlg.scala
+++ b/modules/core/src/main/scala/org/scalasteward/core/git/GenGitAlg.scala
@@ -44,6 +44,8 @@ trait GenGitAlg[F[_], Repo] {
 
   def currentBranch(repo: Repo): F[Branch]
 
+  def deleteLocalBranch(repo: Repo, branch: Branch): F[Unit]
+
   def deleteRemoteBranch(repo: Repo, branch: Branch): F[Unit]
 
   /** Discards unstaged changes. */
@@ -114,6 +116,9 @@ trait GenGitAlg[F[_], Repo] {
       override def currentBranch(repo: A): F[Branch] =
         f(repo).flatMap(self.currentBranch)
 
+      override def deleteLocalBranch(repo: A, branch: Branch): F[Unit] =
+        f(repo).flatMap(self.deleteLocalBranch(_, branch))
+
       override def deleteRemoteBranch(repo: A, branch: Branch): F[Unit] =
         f(repo).flatMap(self.deleteRemoteBranch(_, branch))
 
diff --git a/modules/core/src/main/scala/org/scalasteward/core/git/package.scala b/modules/core/src/main/scala/org/scalasteward/core/git/package.scala
index 7d8a4fcf..c56c84f0 100644
--- a/modules/core/src/main/scala/org/scalasteward/core/git/package.scala
+++ b/modules/core/src/main/scala/org/scalasteward/core/git/package.scala
@@ -25,9 +25,11 @@ import org.scalasteward.core.vcs.data.Repo
 package object git {
   type GitAlg[F[_]] = GenGitAlg[F, Repo]
 
+  val updateBranchPrefix = "update"
+
   def branchFor(update: Update, baseBranch: Option[Branch]): Branch = {
     val base = baseBranch.fold("")(branch => s"${branch.name}/")
-    Branch(s"update/$base${update.name}-${update.nextVersion}")
+    Branch(s"$updateBranchPrefix/$base${update.name}-${update.nextVersion}")
   }
 
   def commitMsgFor(
diff --git a/modules/core/src/main/scala/org/scalasteward/core/vcs/VCSRepoAlg.scala b/modules/core/src/main/scala/org/scalasteward/core/vcs/VCSRepoAlg.scala
index 62c24404..85cd0f6d 100644
--- a/modules/core/src/main/scala/org/scalasteward/core/vcs/VCSRepoAlg.scala
+++ b/modules/core/src/main/scala/org/scalasteward/core/vcs/VCSRepoAlg.scala
@@ -21,7 +21,7 @@ import cats.syntax.all._
 import org.http4s.Uri
 import org.http4s.Uri.UserInfo
 import org.scalasteward.core.application.Config
-import org.scalasteward.core.git.GitAlg
+import org.scalasteward.core.git.{updateBranchPrefix, Branch, GitAlg}
 import org.scalasteward.core.util
 import org.scalasteward.core.util.logger._
 import org.scalasteward.core.vcs.VCSType.GitHub
@@ -58,9 +58,20 @@ final class VCSRepoAlg[F[_]](config: Config)(implicit
   private def syncFork(repo: Repo, repoOut: RepoOut): F[Unit] =
     repoOut.parentOrRaise[F].flatMap { parent =>
       logger.info(s"Synchronize with ${parent.repo.show}") >>
-        gitAlg.syncFork(repo, withLogin(parent.clone_url), parent.default_branch)
+        gitAlg.syncFork(repo, withLogin(parent.clone_url), parent.default_branch) >>
+        deleteUpdateBranch(repo)
     }
 
+  // We use "update" as prefix for our branches but Git doesn't allow branches named
+  // "update" and "update/..." in the same repo. We therefore delete the "update" branch
+  // in our fork if it exists.
+  private def deleteUpdateBranch(repo: Repo): F[Unit] = {
+    val local = Branch(updateBranchPrefix)
+    val remote = local.withPrefix("origin/")
+    gitAlg.branchExists(repo, local).ifM(gitAlg.deleteLocalBranch(repo, local), F.unit) >>
+      gitAlg.branchExists(repo, remote).ifM(gitAlg.deleteRemoteBranch(repo, remote), F.unit)
+  }
+
   private def initSubmodules(repo: Repo): F[Unit] =
     logger.attemptWarn.log_("Initializing and cloning submodules failed") {
       gitAlg.initSubmodules(repo)


Test patch:
diff --git a/modules/core/src/test/scala/org/scalasteward/core/data/VersionTest.scala b/modules/core/src/test/scala/org/scalasteward/core/data/VersionTest.scala
index 808f49d2..477e64b8 100644
--- a/modules/core/src/test/scala/org/scalasteward/core/data/VersionTest.scala
+++ b/modules/core/src/test/scala/org/scalasteward/core/data/VersionTest.scala
@@ -214,6 +214,7 @@ class VersionTest extends DisciplineSuite {
         Some("1.0.0-20201208-143052-2c1b1172")
       ),
       ("0.27.0-RC1", List("0.27.0-bin-20200826-2e58a66-NIGHTLY"), None),
+      ("2.0.16-200-ge888c6dea", List("2.0.16-200-ge888c6dea-14-c067d59f0-SNAPSHOT"), None),
       ("17.0.0.1", List("18-ea+4"), None),
       ("", List("", ".", "1", "a"), Some("1"))
     )
diff --git a/modules/core/src/test/scala/org/scalasteward/core/git/FileGitAlgTest.scala b/modules/core/src/test/scala/org/scalasteward/core/git/FileGitAlgTest.scala
index a23d1623..8dbfc1f2 100644
--- a/modules/core/src/test/scala/org/scalasteward/core/git/FileGitAlgTest.scala
+++ b/modules/core/src/test/scala/org/scalasteward/core/git/FileGitAlgTest.scala
@@ -34,7 +34,10 @@ class FileGitAlgTest extends CatsEffectSuite {
       _ <- ioGitAlg.createBranch(repo, foo)
       b1 <- ioGitAlg.branchExists(repo, foo)
       b2 <- ioGitAlg.branchExists(repo, bar)
-      _ = assertEquals((b1, b2), (true, false))
+      _ <- ioGitAlg.checkoutBranch(repo, master)
+      _ <- ioGitAlg.deleteLocalBranch(repo, foo)
+      b3 <- ioGitAlg.branchExists(repo, foo)
+      _ = assertEquals((b1, b2, b3), (true, false, false))
     } yield ()
   }
 
diff --git a/modules/core/src/test/scala/org/scalasteward/core/vcs/VCSRepoAlgTest.scala b/modules/core/src/test/scala/org/scalasteward/core/vcs/VCSRepoAlgTest.scala
index 1f9a98d2..c73b1ff9 100644
--- a/modules/core/src/test/scala/org/scalasteward/core/vcs/VCSRepoAlgTest.scala
+++ b/modules/core/src/test/scala/org/scalasteward/core/vcs/VCSRepoAlgTest.scala
@@ -45,6 +45,8 @@ class VCSRepoAlgTest extends CatsEffectSuite {
         Cmd(gitCmd(repoDir), "checkout", "-B", "main", "--track", "upstream/main"),
         Cmd(gitCmd(repoDir), "merge", "upstream/main"),
         Cmd(gitCmd(repoDir), "push", "--force", "--set-upstream", "origin", "main"),
+        Cmd(gitCmd(repoDir), "branch", "--list", "--no-color", "--all", "update"),
+        Cmd(gitCmd(repoDir), "branch", "--list", "--no-color", "--all", "origin/update"),
         Cmd(gitCmd(repoDir), "submodule", "update", "--init", "--recursive")
       )
     )