wecodemore / grunt-githooks

A Grunt plugin to help bind Grunt tasks to Git hooks
https://npmjs.org/package/grunt-githooks
MIT License
317 stars 24 forks source link

When using the option `dest` the grunt calls in the hook script doesn't work #4

Closed barbogast closed 11 years ago

barbogast commented 11 years ago

When using the option 'dest' the grunt calls in the hook script doesn't work. The reason is that git hooks are executed from the directory that contains the .git directory. The dest option is used when .git is not in the same directory as Gruntfile.js. Therefore the grunt calls in the generated hook file cannot be executed because the Gruntfile.js is missing.

I generated a custom template file in which a call process.chdir('path') to the path where my Gruntfile.js is. A more elegant solution could be to automatically insert the process.chdir() call into the hook file. The target path could be retrieved by process.cwd() while writing the hook file.

romaricpascal commented 11 years ago

Good point! To be fair, I had just planned the dest option as a way to place the test files in separate directories to avoid putting them in the .git while developing. Didn't think of the other way around, to put the hooks in the proper folder when the Gruntfile is not at the root of the project :s

I agree the default templates should handle the situation. I think passing a new gruntfileDirectory variable to the templates so they can chose the way they want to chdir and updating the default templates should do the trick there.