phillipuniverse / githook-maven-plugin

Maven plugin to install local git hooks
MIT License
28 stars 1 forks source link

Create the .git/hooks directory if it does not exist #9

Closed phillipuniverse closed 5 years ago

phillipuniverse commented 5 years ago

Due do this bug of cloning from SourceTree sometimes the .git/hooks directory is not created. If .git/hooks does not exist, this plugin fails with the following exception:

Caused by: java.nio.file.NoSuchFileException: /Users/..../ARepository/.git/hooks/pre-commit
    at sun.nio.fs.UnixException.translateToIOException (UnixException.java:86)
    at sun.nio.fs.UnixException.rethrowAsIOException (UnixException.java:102)
    at sun.nio.fs.UnixException.rethrowAsIOException (UnixException.java:107)
    at sun.nio.fs.UnixFileSystemProvider.newByteChannel (UnixFileSystemProvider.java:214)
    at java.nio.file.spi.FileSystemProvider.newOutputStream (FileSystemProvider.java:434)
    at java.nio.file.Files.newOutputStream (Files.java:216)
    at java.nio.file.Files.write (Files.java:3292)
    at org.sandbox.GitHookInstallMojo.writeFile (GitHookInstallMojo.java:85)
    at org.sandbox.GitHookInstallMojo.execute (GitHookInstallMojo.java:77)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)

The NoSuchFileException is misleading, it's really caused by the fact that .git/hooks doesn't exist, and thus cannot write the pre-commit file into it.