Reputation: 37
i need to do like this post: Git commit hook - How to use the commit-msg hook to check for string in message?
But i need to check if the commit message has an issue number or not. My goal is to only allow commits associated with issues on my github project.
How do i test if the commit-msg file is working? It is on .git folder on my computer, but i cannot push it to repository and i don´t know how to test if it is working. There are no great tutorial on web about git hooks... Any help?
Also: I sthere any way to make git hooks execute on github for windows?
Upvotes: 2
Views: 1539
Reputation: 1712
A git hook is just a shell script that runs when an action is taken on the repo.
If the shell script returns 0, there are no errors, if it returns another number, an error was encountered. If the hook is pre-
hook, returning an error will prevent the action from happening. Post happen after an event, and if they fail the event still occured. So, you could prevent a push, but not a commit, if you need to do stuff with the commit message. Moreover, if you notice a bug and want to patch it, this forces you to create a issue before you can commit it.
The hard part is figuring out how to check to see if there is an open issue number in the commit message. You'd have to scrape github's site or get the issues through the api. Which could be done in a shell script, but you'd probably be better off writing a small program.
github is an internet site, it isn't "on windows". git hooks execute on the repo they are associated with, and they work in Windows, Mac, and Linux environments. They are bash scripts in Windows, and will execute inside the MingW Bash shell that is packaged with Windows Git.
So in the .git file there will be a folder called hooks. In that there will be sample hooks. Rename one of the files taking off the .sample
(in the case of post-commit there isn't a sample file, so you'll just create a post-commit
file in the hooks directory). Edit it in a text editor, and add shell commands to do what you would do from the command line. Shell scripting is a deep topic with much literature.
Upvotes: 2