aboutsummaryrefslogtreecommitdiff
path: root/README
blob: 2adefcfc8899c5d49f12012ae58df6c6d1fe4a59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
git-hooks - A tool to manage Git hooks for multiple git repositories.

Hooks can be very powerful and useful.  Some common hooks include:

- Spell check the commit message.
- Check that the code builds.
- Verify that any new files contain a copyright with the current year in it.

Hooks can also be very project specific such as:

- Pre-populate the commit message with the 'standard' format.
- Verify that any new code follows the 'standard' coding style.

or very specific to one person such as:

- Don't allow a push to a remote repository after 1am in case I break something and will be asleep.
- Don't let me commit between 9-5 for projects in ~/personal/ as I shouldn't be working on them during work hours.

git-hooks provide a way to manage and share your hooks by allowing for the installation of hooks in three locations:
 - User hooks that are installed in ~/.git_hooks/
 - Project hooks that are installed in the git_hooks directory inside of each project.
 - Global hooks that are specified with the environment variable GLOBAL_GIT_HOOKS.
 
When GLOBAL_GIT_HOOKS is not set it defaults to the git-hooks /contrib/ folder.
Multiple global hooks directories can be specified by using a space between each path.

For more details on Git Hooks checkout the online documentation at http://www.kernel.org/pub/software/scm/git/docs/githooks.html

--- Creating hooks

To keep things organized git-hooks looks for scripts in sub directories named after the git hook name.  For example this project has the following pre-commit script in the following location:

git_hooks/pre-commit/bsd

When you run 'git hooks' with no arguments it will list all of the hooks installed on the system.  It will run the hooks with the --about argument to generate the description that is shown.  Checkout the hooks in contrib for some examples.

-- Install

Clone the git-hooks repository and add the directory to your PATH environment variable so git-hooks will be detected.

Inside a project's directory run 'git hooks --install' to change that projects git hooks to use git-hooks hooks.  'git hooks --uninstall' can be run at any time to go back to the old hooks that were installed before (usually the default which does nothing).