Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
*~
target/
.idea/
.bsp/
/bin/
/.settings/
/.cache
/.classpath
/.project
metals.sbt
12 changes: 11 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ startYear := Some(2011)
homepage := scmInfo.value map (_.browseUrl)
scmInfo := Some(ScmInfo(url("https://github.com/sbt/sbt-git"), "scm:git:[email protected]: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"
Expand All @@ -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}"
11 changes: 6 additions & 5 deletions src/main/scala/com/github/sbt/git/ConsoleGitRunner.scala
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Terminal.console can throw an IllegalStateException here so it should be wrapped with try catch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used monadic Try, lemme know if you prefer try/catch for some reason. There's a few other places where Try is used in the plugin, but it's certainly not uniform.

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)
Expand Down
3 changes: 1 addition & 2 deletions src/main/scala/com/github/sbt/git/GitPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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[_] =
Expand Down
16 changes: 8 additions & 8 deletions src/main/scala/com/github/sbt/git/JGit.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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._
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is repeated 6 times. I suggest to move the import to the top of the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll get right on that.

I was thinking the same thing as I was making this conversion. I didn't do this because I haven't worked on the internals here, and wasn't sure if this was a runtime optimization or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

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 = {
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions src/main/scala/com/github/sbt/git/NullLogger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ()
}
Loading