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

Breaks if grunt isn't setup on every branch #21

Open CamdenSegal opened 10 years ago

CamdenSegal commented 10 years ago

I've setup a pre-commit hook using grunt-githooks on a branch of my repository. If I switch to a branch that is not configured with a gruntfile it blocks me from committing with the error "Fatal error: Unable to find Gruntfile."

It seems like it could be a good practice change the hook script from binding into specific grunt tasks to instead:

This will allow for changing the tasks to be run per hook by just modifying the gruntfile, and also allow for different tasks, or no tasks, to be run on different branches.

franz-josef-kaiser commented 10 years ago

@CamdenSegal Could you elaborate this with an additional PR for the current template?

franz-josef-kaiser commented 10 years ago

I guess I got your problem: You have some task running in your git hook/file that requires the Gruntfile. Please remove that. In case I misunderstood you, please simply add your file and explain what you are doing (in code). We can then reopen that issue.

CamdenSegal commented 10 years ago

As it stands the hook files just try to run grunt with the tasks given at the time of running grunt githooks.

Let's say you have a three branches in your repo:

  1. Branch with pre-commit git hook calling qunit task
  2. Branch with pre-commit git hook calling clean task and no qunit task
  3. Branch with no Gruntfile.js

If you were to run grunt githooks while in branch 1, then switch to branch 2 and try to commit it will fail and not allow you to commit because it will try to run the non-existant qunit task, and will not run the proper clean pre-commit task for this branch.

If you were to run grunt githooks on either branch 1 or 2 and then switch to branch 3 it would fail to commit because the attempt to run any grunt task would fail without a Gruntfile.js.

My proposed solution is to include a check for the existance of the Gruntfile.js before any hook tasks are run, then to run something like grunt githooks:pre-commit which will run the task currently assigned to that git hook. This solution could bind to every git hook at the start and never need to be rebound if the tasks or branches ever change.

Does that make sense? Is there a better way to approach this issue? If you think that is a worthwhile change I can work on a PR.

franz-josef-kaiser commented 10 years ago

Does that make sense?

Yes, it perfectly makes sense.

Is there a better way to approach this issue? If you think that is a worthwhile change I can work on a PR.

:+1: Thank you in advance!