8000 Merge pull request #1 from randomcoder/feature/do-not-write-hooks-if-… · randomcoder/sbt-git-hooks@f824621 · GitHub
[go: up one dir, main page]

Skip to content

Commit f824621

Browse files
authored
Merge pull request #1 from randomcoder/feature/do-not-write-hooks-if-target-does-not-exist
Feature/do not write hooks if target does not exist
2 parents d016414 + 173c699 commit f824621

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

Readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ the hooks that are available.
1010

1111
### How to use
1212

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

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

1717
```
18-
addSbtPlugin("uk.co.randomcoding" % "sbt-git-hooks" % "0.1.0")
18+
addSbtPlugin("uk.co.randomcoding" % "sbt-git-hooks" % "0.2.0")
1919
```
2020

2121
Then run the task `writeHooks` to copy the hooks into `.git/hooks`

build.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
name := "sbt-git-hooks"
22

3-
version := "0.1.0"
3+
version := "0.2.0"
44

5-
scalaVersion := "2.12.3"
5+
scalaVersion := "2.12.6"
66

77
organization := "uk.co.randomcoding"
88

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version = 1.0.1
1+
sbt.version = 1.1.6

src/main/scala/uk/co/randomcoding/sbt/GitHooks.scala

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,14 @@ object GitHooks extends AutoPlugin {
5656
object WriteGitHooks {
5757

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

0 commit comments

Comments
 (0)
0