Create pre-push hook to lint/test
up vote
7
down vote
favorite
I was wondering what is the best way to create a pre-push hook (in a git repo) which does the following:
- Run JSHint / JSLint
- Run Unit and functional tests
- If everything is ok then accept the update
- Otherwise refuse the update
git hook
add a comment |
up vote
7
down vote
favorite
I was wondering what is the best way to create a pre-push hook (in a git repo) which does the following:
- Run JSHint / JSLint
- Run Unit and functional tests
- If everything is ok then accept the update
- Otherwise refuse the update
git hook
2
Github (the git hosting service) doesn't let you add arbitrary hooks to the hosted copies of your repos. Setting hooks on the local version of your repositories is certainly possible, but then the question isn't Github-specific :)
– Gareth
Sep 4 '13 at 15:19
2
So, the only way to add a hook is using the pre-defined ones by GitHub?
– Lt.
Sep 4 '13 at 15:44
Well first, be aware that pre-push is run on the machine doing the pushing, and that will never be Github. The 'push' event that Github offers a Web Hook for is actually triggered as a post-receive, as it says at the top of the page you linked to. So, it can only really be used for notifications
– Gareth
Sep 4 '13 at 15:51
related: stackoverflow.com/questions/31681746
– tkruse
Jul 26 at 10:11
add a comment |
up vote
7
down vote
favorite
up vote
7
down vote
favorite
I was wondering what is the best way to create a pre-push hook (in a git repo) which does the following:
- Run JSHint / JSLint
- Run Unit and functional tests
- If everything is ok then accept the update
- Otherwise refuse the update
git hook
I was wondering what is the best way to create a pre-push hook (in a git repo) which does the following:
- Run JSHint / JSLint
- Run Unit and functional tests
- If everything is ok then accept the update
- Otherwise refuse the update
git hook
git hook
edited Sep 4 '13 at 15:22
Gareth
88.8k29136148
88.8k29136148
asked Sep 4 '13 at 15:08
Lt.
795826
795826
2
Github (the git hosting service) doesn't let you add arbitrary hooks to the hosted copies of your repos. Setting hooks on the local version of your repositories is certainly possible, but then the question isn't Github-specific :)
– Gareth
Sep 4 '13 at 15:19
2
So, the only way to add a hook is using the pre-defined ones by GitHub?
– Lt.
Sep 4 '13 at 15:44
Well first, be aware that pre-push is run on the machine doing the pushing, and that will never be Github. The 'push' event that Github offers a Web Hook for is actually triggered as a post-receive, as it says at the top of the page you linked to. So, it can only really be used for notifications
– Gareth
Sep 4 '13 at 15:51
related: stackoverflow.com/questions/31681746
– tkruse
Jul 26 at 10:11
add a comment |
2
Github (the git hosting service) doesn't let you add arbitrary hooks to the hosted copies of your repos. Setting hooks on the local version of your repositories is certainly possible, but then the question isn't Github-specific :)
– Gareth
Sep 4 '13 at 15:19
2
So, the only way to add a hook is using the pre-defined ones by GitHub?
– Lt.
Sep 4 '13 at 15:44
Well first, be aware that pre-push is run on the machine doing the pushing, and that will never be Github. The 'push' event that Github offers a Web Hook for is actually triggered as a post-receive, as it says at the top of the page you linked to. So, it can only really be used for notifications
– Gareth
Sep 4 '13 at 15:51
related: stackoverflow.com/questions/31681746
– tkruse
Jul 26 at 10:11
2
2
Github (the git hosting service) doesn't let you add arbitrary hooks to the hosted copies of your repos. Setting hooks on the local version of your repositories is certainly possible, but then the question isn't Github-specific :)
– Gareth
Sep 4 '13 at 15:19
Github (the git hosting service) doesn't let you add arbitrary hooks to the hosted copies of your repos. Setting hooks on the local version of your repositories is certainly possible, but then the question isn't Github-specific :)
– Gareth
Sep 4 '13 at 15:19
2
2
So, the only way to add a hook is using the pre-defined ones by GitHub?
– Lt.
Sep 4 '13 at 15:44
So, the only way to add a hook is using the pre-defined ones by GitHub?
– Lt.
Sep 4 '13 at 15:44
Well first, be aware that pre-push is run on the machine doing the pushing, and that will never be Github. The 'push' event that Github offers a Web Hook for is actually triggered as a post-receive, as it says at the top of the page you linked to. So, it can only really be used for notifications
– Gareth
Sep 4 '13 at 15:51
Well first, be aware that pre-push is run on the machine doing the pushing, and that will never be Github. The 'push' event that Github offers a Web Hook for is actually triggered as a post-receive, as it says at the top of the page you linked to. So, it can only really be used for notifications
– Gareth
Sep 4 '13 at 15:51
related: stackoverflow.com/questions/31681746
– tkruse
Jul 26 at 10:11
related: stackoverflow.com/questions/31681746
– tkruse
Jul 26 at 10:11
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
You could use a Git pre commit hook to do this. I've set up pre commit hooks to check for debug statements, etc.
Client side hooks like this belong in the .git/hooks folder. But since you can't commit anything in the .git repo into version control you're kind of stuck.
What you need to do then is to keep your shell command that checks correctness in some folder in your git repo, say a top level tools
directory.
Then "just" tell people to install it via:
chmod u+x tools/precommit-checks.sh
ln -s $PWD/tools/precommit-checks.sh .git/hooks/pre-commit
and, assuming that everyone installs it, you can have checking like you ask.
Probably a better way is to just catch this server side: have some kind of continuous integration server pulling the latest commits from your Github repo and checking the codebase.
No, it won't give you the "deny a push" capabilities you'd like.
Assuming you were to host your git repo yourself, there's also another wrinkle: I thought pre-receive hooks on the server would hang the clients for as long as the hook takes. (This is documented to be true for post-recieve hooks, so I'm guessing it's true here too). So if the CI tests take 2 minutes some developer is typing git push
and waiting 2 minutes for their console to do anything again.
So probably better to do post push analysis using a CI server or other quality tests.
2
why make this is a pre-commit instead of a pre-push hook? As a pre-push hook, it would give the option to deny a push -- git-scm.com/docs/githooks#_pre-push
– Mike 'Pomax' Kamermans
Nov 7 '13 at 17:31
If pre-push happens on the client machine, then it might be a good idea. If it happens on the server, like pre-recieve, then see my problem about it hanging. But pre-push might be interesting: I know I do a bunch of work, then make a bunch of commits extracting the different pieces out. pre-push could avoid "Yes, I know the unit tests fail for this commit, gimme a second". Unless you want that feature (aka: your team uses git-bisect a lot, so unit tests have to pass)
– RyanWilcox
Nov 7 '13 at 18:38
1
if you add it to your local .git/hooks dir, all hooks are local. pre-push will kick in just before the push is allowed through, and if whatever script(s) run return something other than 0, the push gets cancelled.
– Mike 'Pomax' Kamermans
Nov 7 '13 at 22:46
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
You could use a Git pre commit hook to do this. I've set up pre commit hooks to check for debug statements, etc.
Client side hooks like this belong in the .git/hooks folder. But since you can't commit anything in the .git repo into version control you're kind of stuck.
What you need to do then is to keep your shell command that checks correctness in some folder in your git repo, say a top level tools
directory.
Then "just" tell people to install it via:
chmod u+x tools/precommit-checks.sh
ln -s $PWD/tools/precommit-checks.sh .git/hooks/pre-commit
and, assuming that everyone installs it, you can have checking like you ask.
Probably a better way is to just catch this server side: have some kind of continuous integration server pulling the latest commits from your Github repo and checking the codebase.
No, it won't give you the "deny a push" capabilities you'd like.
Assuming you were to host your git repo yourself, there's also another wrinkle: I thought pre-receive hooks on the server would hang the clients for as long as the hook takes. (This is documented to be true for post-recieve hooks, so I'm guessing it's true here too). So if the CI tests take 2 minutes some developer is typing git push
and waiting 2 minutes for their console to do anything again.
So probably better to do post push analysis using a CI server or other quality tests.
2
why make this is a pre-commit instead of a pre-push hook? As a pre-push hook, it would give the option to deny a push -- git-scm.com/docs/githooks#_pre-push
– Mike 'Pomax' Kamermans
Nov 7 '13 at 17:31
If pre-push happens on the client machine, then it might be a good idea. If it happens on the server, like pre-recieve, then see my problem about it hanging. But pre-push might be interesting: I know I do a bunch of work, then make a bunch of commits extracting the different pieces out. pre-push could avoid "Yes, I know the unit tests fail for this commit, gimme a second". Unless you want that feature (aka: your team uses git-bisect a lot, so unit tests have to pass)
– RyanWilcox
Nov 7 '13 at 18:38
1
if you add it to your local .git/hooks dir, all hooks are local. pre-push will kick in just before the push is allowed through, and if whatever script(s) run return something other than 0, the push gets cancelled.
– Mike 'Pomax' Kamermans
Nov 7 '13 at 22:46
add a comment |
up vote
2
down vote
accepted
You could use a Git pre commit hook to do this. I've set up pre commit hooks to check for debug statements, etc.
Client side hooks like this belong in the .git/hooks folder. But since you can't commit anything in the .git repo into version control you're kind of stuck.
What you need to do then is to keep your shell command that checks correctness in some folder in your git repo, say a top level tools
directory.
Then "just" tell people to install it via:
chmod u+x tools/precommit-checks.sh
ln -s $PWD/tools/precommit-checks.sh .git/hooks/pre-commit
and, assuming that everyone installs it, you can have checking like you ask.
Probably a better way is to just catch this server side: have some kind of continuous integration server pulling the latest commits from your Github repo and checking the codebase.
No, it won't give you the "deny a push" capabilities you'd like.
Assuming you were to host your git repo yourself, there's also another wrinkle: I thought pre-receive hooks on the server would hang the clients for as long as the hook takes. (This is documented to be true for post-recieve hooks, so I'm guessing it's true here too). So if the CI tests take 2 minutes some developer is typing git push
and waiting 2 minutes for their console to do anything again.
So probably better to do post push analysis using a CI server or other quality tests.
2
why make this is a pre-commit instead of a pre-push hook? As a pre-push hook, it would give the option to deny a push -- git-scm.com/docs/githooks#_pre-push
– Mike 'Pomax' Kamermans
Nov 7 '13 at 17:31
If pre-push happens on the client machine, then it might be a good idea. If it happens on the server, like pre-recieve, then see my problem about it hanging. But pre-push might be interesting: I know I do a bunch of work, then make a bunch of commits extracting the different pieces out. pre-push could avoid "Yes, I know the unit tests fail for this commit, gimme a second". Unless you want that feature (aka: your team uses git-bisect a lot, so unit tests have to pass)
– RyanWilcox
Nov 7 '13 at 18:38
1
if you add it to your local .git/hooks dir, all hooks are local. pre-push will kick in just before the push is allowed through, and if whatever script(s) run return something other than 0, the push gets cancelled.
– Mike 'Pomax' Kamermans
Nov 7 '13 at 22:46
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
You could use a Git pre commit hook to do this. I've set up pre commit hooks to check for debug statements, etc.
Client side hooks like this belong in the .git/hooks folder. But since you can't commit anything in the .git repo into version control you're kind of stuck.
What you need to do then is to keep your shell command that checks correctness in some folder in your git repo, say a top level tools
directory.
Then "just" tell people to install it via:
chmod u+x tools/precommit-checks.sh
ln -s $PWD/tools/precommit-checks.sh .git/hooks/pre-commit
and, assuming that everyone installs it, you can have checking like you ask.
Probably a better way is to just catch this server side: have some kind of continuous integration server pulling the latest commits from your Github repo and checking the codebase.
No, it won't give you the "deny a push" capabilities you'd like.
Assuming you were to host your git repo yourself, there's also another wrinkle: I thought pre-receive hooks on the server would hang the clients for as long as the hook takes. (This is documented to be true for post-recieve hooks, so I'm guessing it's true here too). So if the CI tests take 2 minutes some developer is typing git push
and waiting 2 minutes for their console to do anything again.
So probably better to do post push analysis using a CI server or other quality tests.
You could use a Git pre commit hook to do this. I've set up pre commit hooks to check for debug statements, etc.
Client side hooks like this belong in the .git/hooks folder. But since you can't commit anything in the .git repo into version control you're kind of stuck.
What you need to do then is to keep your shell command that checks correctness in some folder in your git repo, say a top level tools
directory.
Then "just" tell people to install it via:
chmod u+x tools/precommit-checks.sh
ln -s $PWD/tools/precommit-checks.sh .git/hooks/pre-commit
and, assuming that everyone installs it, you can have checking like you ask.
Probably a better way is to just catch this server side: have some kind of continuous integration server pulling the latest commits from your Github repo and checking the codebase.
No, it won't give you the "deny a push" capabilities you'd like.
Assuming you were to host your git repo yourself, there's also another wrinkle: I thought pre-receive hooks on the server would hang the clients for as long as the hook takes. (This is documented to be true for post-recieve hooks, so I'm guessing it's true here too). So if the CI tests take 2 minutes some developer is typing git push
and waiting 2 minutes for their console to do anything again.
So probably better to do post push analysis using a CI server or other quality tests.
answered Sep 5 '13 at 2:04
RyanWilcox
11.8k12545
11.8k12545
2
why make this is a pre-commit instead of a pre-push hook? As a pre-push hook, it would give the option to deny a push -- git-scm.com/docs/githooks#_pre-push
– Mike 'Pomax' Kamermans
Nov 7 '13 at 17:31
If pre-push happens on the client machine, then it might be a good idea. If it happens on the server, like pre-recieve, then see my problem about it hanging. But pre-push might be interesting: I know I do a bunch of work, then make a bunch of commits extracting the different pieces out. pre-push could avoid "Yes, I know the unit tests fail for this commit, gimme a second". Unless you want that feature (aka: your team uses git-bisect a lot, so unit tests have to pass)
– RyanWilcox
Nov 7 '13 at 18:38
1
if you add it to your local .git/hooks dir, all hooks are local. pre-push will kick in just before the push is allowed through, and if whatever script(s) run return something other than 0, the push gets cancelled.
– Mike 'Pomax' Kamermans
Nov 7 '13 at 22:46
add a comment |
2
why make this is a pre-commit instead of a pre-push hook? As a pre-push hook, it would give the option to deny a push -- git-scm.com/docs/githooks#_pre-push
– Mike 'Pomax' Kamermans
Nov 7 '13 at 17:31
If pre-push happens on the client machine, then it might be a good idea. If it happens on the server, like pre-recieve, then see my problem about it hanging. But pre-push might be interesting: I know I do a bunch of work, then make a bunch of commits extracting the different pieces out. pre-push could avoid "Yes, I know the unit tests fail for this commit, gimme a second". Unless you want that feature (aka: your team uses git-bisect a lot, so unit tests have to pass)
– RyanWilcox
Nov 7 '13 at 18:38
1
if you add it to your local .git/hooks dir, all hooks are local. pre-push will kick in just before the push is allowed through, and if whatever script(s) run return something other than 0, the push gets cancelled.
– Mike 'Pomax' Kamermans
Nov 7 '13 at 22:46
2
2
why make this is a pre-commit instead of a pre-push hook? As a pre-push hook, it would give the option to deny a push -- git-scm.com/docs/githooks#_pre-push
– Mike 'Pomax' Kamermans
Nov 7 '13 at 17:31
why make this is a pre-commit instead of a pre-push hook? As a pre-push hook, it would give the option to deny a push -- git-scm.com/docs/githooks#_pre-push
– Mike 'Pomax' Kamermans
Nov 7 '13 at 17:31
If pre-push happens on the client machine, then it might be a good idea. If it happens on the server, like pre-recieve, then see my problem about it hanging. But pre-push might be interesting: I know I do a bunch of work, then make a bunch of commits extracting the different pieces out. pre-push could avoid "Yes, I know the unit tests fail for this commit, gimme a second". Unless you want that feature (aka: your team uses git-bisect a lot, so unit tests have to pass)
– RyanWilcox
Nov 7 '13 at 18:38
If pre-push happens on the client machine, then it might be a good idea. If it happens on the server, like pre-recieve, then see my problem about it hanging. But pre-push might be interesting: I know I do a bunch of work, then make a bunch of commits extracting the different pieces out. pre-push could avoid "Yes, I know the unit tests fail for this commit, gimme a second". Unless you want that feature (aka: your team uses git-bisect a lot, so unit tests have to pass)
– RyanWilcox
Nov 7 '13 at 18:38
1
1
if you add it to your local .git/hooks dir, all hooks are local. pre-push will kick in just before the push is allowed through, and if whatever script(s) run return something other than 0, the push gets cancelled.
– Mike 'Pomax' Kamermans
Nov 7 '13 at 22:46
if you add it to your local .git/hooks dir, all hooks are local. pre-push will kick in just before the push is allowed through, and if whatever script(s) run return something other than 0, the push gets cancelled.
– Mike 'Pomax' Kamermans
Nov 7 '13 at 22:46
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f18617472%2fcreate-pre-push-hook-to-lint-test%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Github (the git hosting service) doesn't let you add arbitrary hooks to the hosted copies of your repos. Setting hooks on the local version of your repositories is certainly possible, but then the question isn't Github-specific :)
– Gareth
Sep 4 '13 at 15:19
2
So, the only way to add a hook is using the pre-defined ones by GitHub?
– Lt.
Sep 4 '13 at 15:44
Well first, be aware that pre-push is run on the machine doing the pushing, and that will never be Github. The 'push' event that Github offers a Web Hook for is actually triggered as a post-receive, as it says at the top of the page you linked to. So, it can only really be used for notifications
– Gareth
Sep 4 '13 at 15:51
related: stackoverflow.com/questions/31681746
– tkruse
Jul 26 at 10:11