8000 Feature/do not write hooks if target does not exist by randomcoder · Pull Request #1 · randomcoder/sbt-git-hooks · GitHub
[go: up one dir, main page]

Skip to content

Feature/do not write hooks if target does not exist #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ the hooks that are available.

### How to use

`sbt-git-hooks` is an auto plugin for SBT 1.0.
`sbt-git-hooks` is an auto plugin for SBT 1.1.x

Add the plugin to your build with the following in `project/plugins.sbt`:

```
addSbtPlugin("uk.co.randomcoding" % "sbt-git-hooks" % "0.1.0")
addSbtPlugin("uk.co.randomcoding" % "sbt-git-hooks" % "0.2.0")
```

Then run the task `writeHooks` to copy the hooks into `.git/hooks`
Expand Down
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name := "sbt-git-hooks"

version := "0.1.0"
version := "0.2.0"

scalaVersion := "2.12.3"
scalaVersion := "2.12.6"

organization := "uk.co.randomcoding"

Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version = 1.0.1
sbt.version = 1.1.6
16 changes: 9 additions & 7 deletions src/main/scala/uk/co/randomcoding/sbt/GitHooks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ object GitHooks extends AutoPlugin {
object WriteGitHooks {

def apply(hooksSourceDir: File, hooksTargetDir: File, log: ManagedLogger): Unit = {
log.info(s"Copying hooks from ${hooksSourceDir.getAbsolutePath} into ${hooksTargetDir.getAbsolutePath}")
Option(hooksSourceDir.listFiles).map(_.toList).getOrElse(Nil).foreach { hook =>
val hookTarget = hooksTargetDir.toPath.resolve(hook.getName)
log.info(s"Copying ${hook.getName} to $hookTarget")
Files.copy(hook.toPath, hookTarget, StandardCopyOption.REPLACE_EXISTING)
if (!Properties.isWin) Files.setPosixFilePermissions(hookTarget, PosixFilePermissions.fromString("rwxr-xr-x"))
}
if (hooksTargetDir.exists()) {
log.info(s"Copying hooks from ${hooksSourceDir.getAbsolutePath} into ${hooksTargetDir.getAbsolutePath}")
Option(hooksSourceDir.listFiles).map(_.toList).getOrElse(Nil).foreach { hook =>
val hookTarget = hooksTargetDir.toPath.resolve(hook.getName)
log.info(s"Copying ${hook.getName} to $hookTarget")
Files.copy(hook.toPath, hookTarget, StandardCopyOption.REPLACE_EXISTING)
if (!Properties.isWin) Files.setPosixFilePermissions(hookTarget, PosixFilePermissions.fromString("rwxr-xr-x"))
}
} else log.info(s"${hooksTargetDir.getPath} does not exist (possibly within a submodule). Not writing any hooks.")
}
}
0