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 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/build.sbt b/build.sbt index d563b68..11efbcc 100644 --- a/build.sbt +++ b/build.sbt @@ -8,7 +8,10 @@ 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") +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 +22,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}" diff --git a/src/main/scala/com/github/sbt/git/ConsoleGitRunner.scala b/src/main/scala/com/github/sbt/git/ConsoleGitRunner.scala index a471e82..8fc671d 100644 --- a/src/main/scala/com/github/sbt/git/ConsoleGitRunner.scala +++ b/src/main/scala/com/github/sbt/git/ConsoleGitRunner.scala @@ -1,31 +1,37 @@ package com.github.sbt.git -import sbt._ -import Keys._ -import sys.process.{ Process, ProcessLogger } +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(ConsoleLogger.formatEnabled) 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 + "$ " + full.mkString(" ")) - val code = Process(full, cwd, colorSupport :_*) ! gitLogger + log.debug(cwd.toString + "$ " + full.mkString(" ")) + val code = Process(full, cwd, colorSupport *) ! gitLogger val result = gitLogger.flush(code) if(code != 0) throw new MessageOnlyException("Nonzero exit code (" + code + ") running git.") @@ -37,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/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[_] = diff --git a/src/main/scala/com/github/sbt/git/JGit.scala b/src/main/scala/com/github/sbt/git/JGit.scala index c580884..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,13 +30,11 @@ 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 + porcelain.branchList.call.asScala.toSeq } def tags: Seq[Ref] = { - import collection.JavaConverters._ - porcelain.tagList.call().asScala + porcelain.tagList.call().asScala.toSeq } def checkoutBranch(branch: String): Unit = { @@ -59,7 +58,6 @@ final class JGit(val repo: Repository) extends GitReadonlyInterface { headCommit map (_.name) def currentTags: Seq[String] = { - import collection.JavaConverters._ 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 collection.JavaConverters._ 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._ 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()}) } diff --git a/src/main/scala/com/github/sbt/git/NullLogger.scala b/src/main/scala/com/github/sbt/git/NullLogger.scala index 1ba74cd..3e76fb5 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 = () -} \ No newline at end of file + override def success(message: => String): Unit = () + override def trace(t: => Throwable): Unit = () +}