Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
CamdenSegal opened this issue Apr 25, 2014 · 4 comments
Open

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

CamdenSegal opened this issue Apr 25, 2014 · 4 comments

Comments

@CamdenSegal
Copy link

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:

  • First checking for the existence of the Gruntfile
    • If no Gruntfile exists exit the hook without blocking.
  • Then checking the Gruntfile to see if githooks is configured
    • If githooks is not configured in the gruntfile then exit the hook without blocking.
  • Then checking and running the tasks assigned to the current hook in the Gruntfile.

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
Copy link
Member

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

@franz-josef-kaiser
Copy link
Member

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
Copy link
Author

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
Copy link
Member

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.

👍 Thank you in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants