From 6379f73b5447a1c42123bc36715d40948e1d5352 Mon Sep 17 00:00:00 2001 From: Billy Autrey <40704452+BillyAutrey@users.noreply.github.com> Date: Mon, 7 Oct 2024 15:38:18 -0500 Subject: [PATCH 1/9] Fix Scala 3 errors, sbt deprecation warnings --- .../scala/com/github/sbt/git/ConsoleGitRunner.scala | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/scala/com/github/sbt/git/ConsoleGitRunner.scala b/src/main/scala/com/github/sbt/git/ConsoleGitRunner.scala index a471e82..b953fdb 100644 --- a/src/main/scala/com/github/sbt/git/ConsoleGitRunner.scala +++ b/src/main/scala/com/github/sbt/git/ConsoleGitRunner.scala @@ -1,8 +1,9 @@ package com.github.sbt.git -import sbt._ -import Keys._ -import sys.process.{ Process, ProcessLogger } +import sbt.* +import sbt.internal.util.Terminal + +import sys.process.{Process, ProcessLogger} /** A mechanism of running git that simply shells out to the console. */ object ConsoleGitRunner extends GitRunner { @@ -17,14 +18,14 @@ object ConsoleGitRunner extends GitRunner { // in order to enable colors we trick git into thinking we're a pager, because it already knows we're not a tty val colorSupport: Seq[(String, String)] = - if(ConsoleLogger.formatEnabled) Seq("GIT_PAGER_IN_USE" -> "1") + if(Terminal.console.isAnsiSupported) Seq("GIT_PAGER_IN_USE" -> "1") else Seq.empty override def apply(args: String*)(cwd: File, log: Logger = ConsoleLogger()): String = { val gitLogger = new GitLogger(log) IO.createDirectory(cwd) val full = cmd ++ args - log.debug(cwd + "$ " + full.mkString(" ")) + log.debug(cwd.toString + "$ " + full.mkString(" ")) val code = Process(full, cwd, colorSupport :_*) ! gitLogger val result = gitLogger.flush(code) if(code != 0) From 6d5b9120e1be77902b68f455b0a19f31fddd8bdc Mon Sep 17 00:00:00 2001 From: Billy Autrey <40704452+BillyAutrey@users.noreply.github.com> Date: Mon, 7 Oct 2024 15:59:26 -0500 Subject: [PATCH 2/9] Clean up deprecation of unicode arrow --- .gitignore | 2 ++ src/main/scala/com/github/sbt/git/NullLogger.scala | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index ed0977b..a1961e8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,10 @@ *~ target/ .idea/ +.bsp/ /bin/ /.settings/ /.cache /.classpath /.project +metals.sbt diff --git a/src/main/scala/com/github/sbt/git/NullLogger.scala b/src/main/scala/com/github/sbt/git/NullLogger.scala index 1ba74cd..e61c3f4 100644 --- a/src/main/scala/com/github/sbt/git/NullLogger.scala +++ b/src/main/scala/com/github/sbt/git/NullLogger.scala @@ -5,9 +5,9 @@ import sbt.Level import sbt.ControlEvent object NullLogger extends sbt.BasicLogger { - override def control(event: ControlEvent.Value, message: ⇒ String): Unit = () - override def log(level: Level.Value, message: ⇒ String): Unit = () + override def control(event: ControlEvent.Value, message: => String): Unit = () + override def log(level: Level.Value, message: => String): Unit = () override def logAll(events: Seq[LogEvent]): Unit = () - override def success(message: ⇒ String): Unit = () - override def trace(t: ⇒ Throwable): Unit = () + override def success(message: => String): Unit = () + override def trace(t: => Throwable): Unit = () } \ No newline at end of file From a5dd8f92f9198a3fb110d5a265a27f27af9c05ed Mon Sep 17 00:00:00 2001 From: Billy Autrey <40704452+BillyAutrey@users.noreply.github.com> Date: Mon, 7 Oct 2024 16:14:10 -0500 Subject: [PATCH 3/9] Use slash format, clean imports --- src/main/scala/com/github/sbt/git/GitPlugin.scala | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/scala/com/github/sbt/git/GitPlugin.scala b/src/main/scala/com/github/sbt/git/GitPlugin.scala index 1d99387..613a348 100644 --- a/src/main/scala/com/github/sbt/git/GitPlugin.scala +++ b/src/main/scala/com/github/sbt/git/GitPlugin.scala @@ -2,7 +2,6 @@ package com.github.sbt.git import sbt._ import Keys._ -import sys.process.Process /** This plugin has all the basic 'git' functionality for other plugins. */ object SbtGit { @@ -170,7 +169,7 @@ object SbtGit { def useJGit: Setting[_] = ThisBuild / gitRunner := JGitRunner /** Setting to use console git for readable ops, to allow working with git worktrees */ - def useReadableConsoleGit: Setting[_] = useConsoleForROGit in ThisBuild := true + def useReadableConsoleGit: Setting[_] = ThisBuild / useConsoleForROGit := true /** Adapts the project prompt to show the current project name *and* the current git branch. */ def showCurrentGitBranch: Setting[_] = From 8937212557a5882f887f40d1fbdcf65110530188 Mon Sep 17 00:00:00 2001 From: Billy Autrey <40704452+BillyAutrey@users.noreply.github.com> Date: Mon, 7 Oct 2024 16:17:21 -0500 Subject: [PATCH 4/9] Update to newer JavaConverters, fix type error in Scala3 --- src/main/scala/com/github/sbt/git/JGit.scala | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/scala/com/github/sbt/git/JGit.scala b/src/main/scala/com/github/sbt/git/JGit.scala index c580884..fff4b30 100644 --- a/src/main/scala/com/github/sbt/git/JGit.scala +++ b/src/main/scala/com/github/sbt/git/JGit.scala @@ -29,13 +29,13 @@ final class JGit(val repo: Repository) extends GitReadonlyInterface { def branch: String = repo.getBranch private def branchesRef: Seq[Ref] = { - import collection.JavaConverters._ - porcelain.branchList.call.asScala + import scala.jdk.CollectionConverters._ + porcelain.branchList.call.asScala.toSeq } def tags: Seq[Ref] = { - import collection.JavaConverters._ - porcelain.tagList.call().asScala + import scala.jdk.CollectionConverters._ + porcelain.tagList.call().asScala.toSeq } def checkoutBranch(branch: String): Unit = { @@ -59,7 +59,7 @@ final class JGit(val repo: Repository) extends GitReadonlyInterface { headCommit map (_.name) def currentTags: Seq[String] = { - import collection.JavaConverters._ + import scala.jdk.CollectionConverters._ for { hash <- headCommit.map(_.name).toSeq unpeeledTag <- tags @@ -96,14 +96,14 @@ final class JGit(val repo: Repository) extends GitReadonlyInterface { override def branches: Seq[String] = branchesRef.filter(_.getName.startsWith("refs/heads")).map(_.getName.drop(11)) override def remoteBranches: Seq[String] = { - import collection.JavaConverters._ + import scala.jdk.CollectionConverters._ import org.eclipse.jgit.api.ListBranchCommand.ListMode - porcelain.branchList.setListMode(ListMode.REMOTE).call.asScala.filter(_.getName.startsWith("refs/remotes")).map(_.getName.drop(13)) + porcelain.branchList.setListMode(ListMode.REMOTE).call.asScala.filter(_.getName.startsWith("refs/remotes")).map(_.getName.drop(13)).toSeq } override def remoteOrigin: String = { // same functionality as Process("git ls-remote --get-url origin").lines_!.head - import collection.JavaConverters._ + import scala.jdk.CollectionConverters._ porcelain.remoteList().call.asScala .filter(_.getName == "origin") .flatMap(_.getURIs.asScala) From e72135a5984ae9fbf8ada58476324304c471c529 Mon Sep 17 00:00:00 2001 From: Billy Autrey <40704452+BillyAutrey@users.noreply.github.com> Date: Mon, 7 Oct 2024 16:18:17 -0500 Subject: [PATCH 5/9] Add scala3/sbt2 crossbuild, raise 2.12 sbt minversion --- build.sbt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index d563b68..c5e1806 100644 --- a/build.sbt +++ b/build.sbt @@ -8,7 +8,12 @@ startYear := Some(2011) homepage := scmInfo.value map (_.browseUrl) scmInfo := Some(ScmInfo(url("https://github.com/sbt/sbt-git"), "scm:git:git@github.com:sbt/sbt-git.git")) -crossSbtVersions := List("1.3.13") +crossSbtVersions := List("1.5.8") + +lazy val scala212 = "2.12.20" +lazy val scala3 = "3.3.4" + +crossScalaVersions := Seq(scala212, scala3) enablePlugins(GitVersioning, SbtPlugin) git.baseVersion := "1.0" @@ -19,4 +24,11 @@ libraryDependencies ++= Seq( "org.scalameta" %% "munit" % "1.0.2" % Test ) +(pluginCrossBuild / sbtVersion) := { + scalaBinaryVersion.value match { + case "2.12" => "1.5.8" + case _ => "2.0.0-M2" + } +} + scriptedLaunchOpts += s"-Dproject.version=${version.value}" From 930a4a57c13493ecbac8bd4bd2b744da84b647bd Mon Sep 17 00:00:00 2001 From: Billy Autrey <40704452+BillyAutrey@users.noreply.github.com> Date: Mon, 7 Oct 2024 16:20:44 -0500 Subject: [PATCH 6/9] Newline --- src/main/scala/com/github/sbt/git/NullLogger.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/com/github/sbt/git/NullLogger.scala b/src/main/scala/com/github/sbt/git/NullLogger.scala index e61c3f4..3e76fb5 100644 --- a/src/main/scala/com/github/sbt/git/NullLogger.scala +++ b/src/main/scala/com/github/sbt/git/NullLogger.scala @@ -10,4 +10,4 @@ object NullLogger extends sbt.BasicLogger { override def logAll(events: Seq[LogEvent]): Unit = () override def success(message: => String): Unit = () override def trace(t: => Throwable): Unit = () -} \ No newline at end of file +} From f7e97212308f1f51ea6198202f3380908cd533dd Mon Sep 17 00:00:00 2001 From: Billy Autrey <40704452+BillyAutrey@users.noreply.github.com> Date: Mon, 7 Oct 2024 16:24:37 -0500 Subject: [PATCH 7/9] Remove redundant crossbuild --- build.sbt | 2 -- 1 file changed, 2 deletions(-) diff --git a/build.sbt b/build.sbt index c5e1806..11efbcc 100644 --- a/build.sbt +++ b/build.sbt @@ -8,8 +8,6 @@ startYear := Some(2011) homepage := scmInfo.value map (_.browseUrl) scmInfo := Some(ScmInfo(url("https://github.com/sbt/sbt-git"), "scm:git:git@github.com:sbt/sbt-git.git")) -crossSbtVersions := List("1.5.8") - lazy val scala212 = "2.12.20" lazy val scala3 = "3.3.4" From 3de9c10d15605020fa035c1212aa18102a068c32 Mon Sep 17 00:00:00 2001 From: Billy Autrey <40704452+BillyAutrey@users.noreply.github.com> Date: Mon, 7 Oct 2024 16:45:42 -0500 Subject: [PATCH 8/9] Update CI to prep for matrix crossbuilds --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0da59c7..d9507c1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: - name: Build and test run: | gpg --import test-key.gpg - sbt -v clean ^test ^scripted + sbt -v clean test scripted rm -rf "$HOME/.ivy2/local" || true find $HOME/Library/Caches/Coursier/v1 -name "ivydata-*.properties" -delete || true find $HOME/.ivy2/cache -name "ivydata-*.properties" -delete || true From f13720e0bfd282b537de2683ca4bad5c88c0c7e5 Mon Sep 17 00:00:00 2001 From: Billy Autrey <40704452+BillyAutrey@users.noreply.github.com> Date: Tue, 8 Oct 2024 08:21:11 -0500 Subject: [PATCH 9/9] Feedback from PR, fix more Scala3 syntax hints --- .../com/github/sbt/git/ConsoleGitRunner.scala | 25 +++++++++++-------- src/main/scala/com/github/sbt/git/JGit.scala | 20 ++++++--------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/main/scala/com/github/sbt/git/ConsoleGitRunner.scala b/src/main/scala/com/github/sbt/git/ConsoleGitRunner.scala index b953fdb..8fc671d 100644 --- a/src/main/scala/com/github/sbt/git/ConsoleGitRunner.scala +++ b/src/main/scala/com/github/sbt/git/ConsoleGitRunner.scala @@ -3,30 +3,35 @@ package com.github.sbt.git import sbt.* import sbt.internal.util.Terminal +import scala.util.Try import sys.process.{Process, ProcessLogger} /** A mechanism of running git that simply shells out to the console. */ object ConsoleGitRunner extends GitRunner { // TODO - Something less lame here. - def isWindowsShell = { - val ostype = System.getenv("OSTYPE") - val isCygwin = ostype != null && ostype.toLowerCase.contains("cygwin") - val isWindows = System.getProperty("os.name", "").toLowerCase.contains("windows") - isWindows && !isCygwin - } + def isWindowsShell: Boolean = { + val ostype = System.getenv("OSTYPE") + val isCygwin = ostype != null && ostype.toLowerCase.contains("cygwin") + val isWindows = System.getProperty("os.name", "").toLowerCase.contains("windows") + isWindows && !isCygwin + } private lazy val cmd = if(isWindowsShell) Seq("cmd", "/c", "git") else Seq("git") // in order to enable colors we trick git into thinking we're a pager, because it already knows we're not a tty val colorSupport: Seq[(String, String)] = - if(Terminal.console.isAnsiSupported) Seq("GIT_PAGER_IN_USE" -> "1") - else Seq.empty + Try{ + if(Terminal.console.isAnsiSupported) + Seq("GIT_PAGER_IN_USE" -> "1") + else + Seq.empty + }.getOrElse(Seq.empty) override def apply(args: String*)(cwd: File, log: Logger = ConsoleLogger()): String = { val gitLogger = new GitLogger(log) IO.createDirectory(cwd) val full = cmd ++ args log.debug(cwd.toString + "$ " + full.mkString(" ")) - val code = Process(full, cwd, colorSupport :_*) ! gitLogger + val code = Process(full, cwd, colorSupport *) ! gitLogger val result = gitLogger.flush(code) if(code != 0) throw new MessageOnlyException("Nonzero exit code (" + code + ") running git.") @@ -38,7 +43,7 @@ object ConsoleGitRunner extends GitRunner { // reduce log level for git process private class GitLogger(log: Logger) extends ProcessLogger { import scala.collection.mutable.ListBuffer - import Level.{ Debug, Info, Warn, Error, Value => LogLevel } + import Level.{ Debug, Info, Error, Value as LogLevel } private val msgs: ListBuffer[(LogLevel, String)] = new ListBuffer() diff --git a/src/main/scala/com/github/sbt/git/JGit.scala b/src/main/scala/com/github/sbt/git/JGit.scala index fff4b30..e36aa3d 100644 --- a/src/main/scala/com/github/sbt/git/JGit.scala +++ b/src/main/scala/com/github/sbt/git/JGit.scala @@ -2,7 +2,7 @@ package com.github.sbt.git import org.eclipse.jgit.lib.Repository import org.eclipse.jgit.storage.file.FileRepositoryBuilder -import org.eclipse.jgit.api.{Git => PGit} +import org.eclipse.jgit.api.Git as PGit import java.io.File import java.text.SimpleDateFormat import java.util.Date @@ -11,6 +11,7 @@ import org.eclipse.jgit.lib.ObjectId import org.eclipse.jgit.lib.Ref import org.eclipse.jgit.revwalk.{RevCommit, RevWalk} +import scala.jdk.CollectionConverters.* import scala.util.Try @@ -29,12 +30,10 @@ final class JGit(val repo: Repository) extends GitReadonlyInterface { def branch: String = repo.getBranch private def branchesRef: Seq[Ref] = { - import scala.jdk.CollectionConverters._ porcelain.branchList.call.asScala.toSeq } def tags: Seq[Ref] = { - import scala.jdk.CollectionConverters._ porcelain.tagList.call().asScala.toSeq } @@ -59,7 +58,6 @@ final class JGit(val repo: Repository) extends GitReadonlyInterface { headCommit map (_.name) def currentTags: Seq[String] = { - import scala.jdk.CollectionConverters._ for { hash <- headCommit.map(_.name).toSeq unpeeledTag <- tags @@ -71,7 +69,7 @@ final class JGit(val repo: Repository) extends GitReadonlyInterface { } - def tagHash(tag: Ref) = { + def tagHash(tag: Ref): String = { // Annotated (signed) and plain tags work differently, // plain ones have the null PeeledObjectId val peeled = repo.getRefDatabase.peel(tag) @@ -88,7 +86,7 @@ final class JGit(val repo: Repository) extends GitReadonlyInterface { Try(Option(porcelain .describe() .setTags(true) - .setMatch(patterns:_*) + .setMatch(patterns *) .call())).getOrElse(None) override def hasUncommittedChanges: Boolean = porcelain.status.call.hasUncommittedChanges @@ -96,14 +94,12 @@ final class JGit(val repo: Repository) extends GitReadonlyInterface { override def branches: Seq[String] = branchesRef.filter(_.getName.startsWith("refs/heads")).map(_.getName.drop(11)) override def remoteBranches: Seq[String] = { - import scala.jdk.CollectionConverters._ import org.eclipse.jgit.api.ListBranchCommand.ListMode porcelain.branchList.setListMode(ListMode.REMOTE).call.asScala.filter(_.getName.startsWith("refs/remotes")).map(_.getName.drop(13)).toSeq } override def remoteOrigin: String = { // same functionality as Process("git ls-remote --get-url origin").lines_!.head - import scala.jdk.CollectionConverters._ porcelain.remoteList().call.asScala .filter(_.getName == "origin") .flatMap(_.getURIs.asScala) @@ -130,12 +126,12 @@ final class JGit(val repo: Repository) extends GitReadonlyInterface { object JGit { /** Creates a new git instance from a base directory. */ - def apply(base: File) = - try (new JGit({ + def apply(base: File): JGit = + try new JGit({ new FileRepositoryBuilder().findGitDir(base).build - })) catch { + }) catch { // This is thrown if we never find the git base directory. In that instance, we'll assume root is the base dir. - case e: IllegalArgumentException => + case _: IllegalArgumentException => val defaultGitDir = new File(base, ".git") new JGit({ new FileRepositoryBuilder().setGitDir(defaultGitDir).build()}) }