Skip to content

Commit

Permalink
Add scripts to copy scalafmt git hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
jvican committed Apr 25, 2017
1 parent 512a2b9 commit 9c05c1a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 21 deletions.
70 changes: 49 additions & 21 deletions build.sbt
Expand Up @@ -3,6 +3,18 @@ import com.typesafe.tools.mima.core._, ProblemFilters._

def baseVersion = "1.0.0"

onLoad in Global := { (state: State) =>
// Set up the pre-commit hook to format sbt sources
val rootDir = (baseDirectory in ThisBuild).value
val hook = rootDir / ".git" / "hooks" / "pre-commit"
if (!hook.canExecute) {
IO.copyFile(rootDir / "scripts" / "pre-commit-hook", hook)
hook.setExecutable(true)
sLog.value.success("Scalafmt pre-commit hook was set up.")
}
(onLoad in Global).value.apply(state)
}

def commonSettings: Seq[Setting[_]] = Seq(
scalaVersion := scala212,
// publishArtifact in packageDoc := false,
Expand All @@ -28,16 +40,18 @@ def commonSettings: Seq[Setting[_]] = Seq(
}
)

lazy val lmRoot = (project in file(".")).
aggregate(lm).
settings(
inThisBuild(Seq(
homepage := Some(url("https://github.com/sbt/librarymanagement")),
description := "Library management module for sbt",
scmInfo := Some(ScmInfo(url("https://github.com/sbt/librarymanagement"), "git@github.com:sbt/librarymanagement.git")),
bintrayPackage := "librarymanagement",
git.baseVersion := baseVersion
)),
lazy val lmRoot = (project in file("."))
.aggregate(lm)
.settings(
inThisBuild(
Seq(
homepage := Some(url("https://github.com/sbt/librarymanagement")),
description := "Library management module for sbt",
scmInfo := Some(ScmInfo(url("https://github.com/sbt/librarymanagement"),
"git@github.com:sbt/librarymanagement.git")),
bintrayPackage := "librarymanagement",
git.baseVersion := baseVersion
)),
commonSettings,
name := "LM Root",
publish := {},
Expand All @@ -47,14 +61,23 @@ lazy val lmRoot = (project in file(".")).
customCommands
)

lazy val lm = (project in file("librarymanagement")).
settings(
lazy val lm = (project in file("librarymanagement"))
.settings(
commonSettings,
name := "librarymanagement",
libraryDependencies ++= Seq(
ivy, jsch, scalaReflect.value, launcherInterface, sjsonnewScalaJson % Optional),
libraryDependencies ++= Seq(ivy,
jsch,
scalaReflect.value,
launcherInterface,
sjsonnewScalaJson % Optional),
libraryDependencies ++= scalaXml.value,
resourceGenerators in Compile += Def.task(Util.generateVersionFile(version.value, resourceManaged.value, streams.value, (compile in Compile).value)).taskValue,
resourceGenerators in Compile += Def
.task(
Util.generateVersionFile(version.value,
resourceManaged.value,
streams.value,
(compile in Compile).value))
.taskValue,
mimaBinaryIssueFilters ++= Seq(),
contrabandFormatsForType in generateContrabands in Compile := DatatypeConfig.getFormats,
// WORKAROUND sbt/sbt#2205 include managed sources in packageSrc
Expand All @@ -64,16 +87,21 @@ lazy val lm = (project in file("librarymanagement")).
val base = baseDirectory.value
(((srcs --- sdirs --- base) pair (relativeTo(sdirs) | relativeTo(base) | flat)) toSeq)
}
).
configure(addSbtIO, addSbtUtilLogging, addSbtUtilTesting, addSbtUtilCollection, addSbtUtilCompletion, addSbtUtilCache).
enablePlugins(ContrabandPlugin, JsonCodecPlugin)
)
.configure(addSbtIO,
addSbtUtilLogging,
addSbtUtilTesting,
addSbtUtilCollection,
addSbtUtilCompletion,
addSbtUtilCache)
.enablePlugins(ContrabandPlugin, JsonCodecPlugin)

def customCommands: Seq[Setting[_]] = Seq(
commands += Command.command("release") { state =>
// "clean" ::
"so compile" ::
"so publishSigned" ::
"reload" ::
state
"so publishSigned" ::
"reload" ::
state
}
)
4 changes: 4 additions & 0 deletions scripts/pre-commit-hook
@@ -0,0 +1,4 @@
#!/bin/sh
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
BASE_DIR=$(git rev-parse --show-toplevel)
exec "$BASE_DIR"/scalafmt --diff-branch "$CURRENT_BRANCH"

0 comments on commit 9c05c1a

Please sign in to comment.