8000 Check for target directory existing before writing hooks · randomcoder/sbt-git-hooks@9fbe462 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 9fbe462

Browse files
author
Tim Sheppard
committed
Check for target directory existing before writing hooks
1 parent d016414 commit 9fbe462

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

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