rudikershaw / git-build-hook

A maven plugin for managing client side (local) git configuration for those working on your project. Including but not limited to setting git config, installing hooks, validating the local repository.
MIT License
138 stars 20 forks source link

Could not write hooks if .git/hooks directory does not exists #56

Open jogerj opened 1 week ago

jogerj commented 1 week ago

When the folder .git/hooks does not exist, then the plugin will fail to install the git hook. By default the directory is non-existent

Actual behavior: The plugin fails to write the git hook into the directory. Expected behavior: The plugin should resolve it automatically and create the directory if it doesn't exist.

pom.xml ```xml com.rudikershaw.gitbuildhook git-build-hook-maven-plugin 3.5.0 scripts/pre-commit.sh install-git-hooks validate install ```
Logs output in CI/CD ``` $ ./mvnw verify -s ci_settings.xml --no-transfer-progress [INFO] Scanning for projects... [INFO] [INFO] ----------------------< com.acme.example:backend >----------------------- [INFO] Building backend 0.1.0-SNAPSHOT [INFO] from pom.xml [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] --- git-build-hook:3.5.0:install (install-git-hooks) @ backend --- [WARNING] Could not move file into .git/hooks directory java.nio.file.NoSuchFileException: /builds/acme/example/backend/.git/hooks/pre-commit at sun.nio.fs.UnixException.translateToIOException (UnixException.java:92) at sun.nio.fs.UnixException.rethrowAsIOException (UnixException.java:106) at sun.nio.fs.UnixException.rethrowAsIOException (UnixException.java:111) at sun.nio.fs.UnixFileSystem.copyFile (UnixFileSystem.java:668) at sun.nio.fs.UnixFileSystem.copy (UnixFileSystem.java:1060) at sun.nio.fs.UnixFileSystemProvider.copy (UnixFileSystemProvider.java:300) at java.nio.file.Files.copy (Files.java:1304) at com.rudikershaw.gitbuildhook.InstallMojo.copyFromFile (InstallMojo.java:91) at com.rudikershaw.gitbuildhook.InstallMojo.installGitHook (InstallMojo.java:76) at com.rudikershaw.gitbuildhook.InstallMojo.execute (InstallMojo.java:58) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126) at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328) at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174) at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75) at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162) at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173) at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101) at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906) at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283) at org.apache.maven.cli.MavenCli.main (MavenCli.java:206) at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103) at java.lang.reflect.Method.invoke (Method.java:580) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:255) at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:201) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:361) at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:314) ```
Logs output on Windows ``` [INFO] Scanning for projects... [INFO] [INFO] ----------------------< com.acme.example:backend >----------------------- [INFO] Building backend 0.1.0-SNAPSHOT [INFO] from pom.xml [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] --- git-build-hook:3.5.0:install (install-git-hooks) @ backend --- [WARNING] Could not move file into .git/hooks directory java.nio.file.NoSuchFileException: scripts\pre-commit.sh -> C:\Users\foouser\acme\example\backend\.git\hooks\pre-commit at sun.nio.fs.WindowsException.translateToIOException (WindowsException.java:85) at sun.nio.fs.WindowsException.rethrowAsIOException (WindowsException.java:103) at sun.nio.fs.WindowsFileCopy.copy (WindowsFileCopy.java:220) at sun.nio.fs.WindowsFileSystemProvider.copy (WindowsFileSystemProvider.java:282) at java.nio.file.Files.copy (Files.java:1304) at com.rudikershaw.gitbuildhook.InstallMojo.copyFromFile (InstallMojo.java:91) at com.rudikershaw.gitbuildhook.InstallMojo.installGitHook (InstallMojo.java:76) at com.rudikershaw.gitbuildhook.InstallMojo.execute (InstallMojo.java:58) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126) at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328) at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174) at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75) at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162) at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173) at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101) at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906) at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283) at org.apache.maven.cli.MavenCli.main (MavenCli.java:206) at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103) at java.lang.reflect.Method.invoke (Method.java:580) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:255) at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:201) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:361) at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:314) at org.codehaus.classworlds.Launcher.main (Launcher.java:41) ```
rudikershaw commented 1 week ago

Hi there, thanks for your contribution.

I assume then, this is an issue for when SourceTree creates a git repository? I would be very surprised if git itself would create a repository without the hooks directory.

Thanks also for the pull request, I'll review that shortly.

jogerj commented 1 week ago

When running git clone with --bare option, the hooks directory is not created. This seems to be the default behavior in CI pipelines, namely in GitLab

rudikershaw commented 1 week ago

Didn't mean to close this issue. I'll re-open it and close it once 3.5.1 has been released.