Git hooks that assist TiDD(Ticket-Driven Development) with Git.
-
pre-commit (for normal repository):
Just deny commit on master branch. -
commit-msg (for normal repository):
Extract ticket ID from the name of the current branch, and insert it to the first line of a commit message. The formats of a branch name and a message to be inserted are configurable. -
prepare-commit-msg (for normal repository):
Show diff of the current commit when editing its commit message.
NB: the messages of the commits with -c or -C options won't include the diff, since we cannot distinguish the options (one can ignore the additional information but the other cannot).
-
common.sh (for normal repository):
Common functions for pre-commit and commit-msg. -
update (for bare repository):
Deny push with commits that don't have a ticket ID in their commit messages.
- git-hooks:
Help to install above hook scripts in repositories, and to update git-hooks itself.
-
Download git-hooks and place it in the same directory as other git commands:
- /usr/bin
- /usr/local/bin
- or you may get the suitable direcotry by `which git`
-
Run `__git hooks install https://github.com/murank/Git-Hooks/raw/master__\` in a repository (NB: it requires curl).
If you get SSL certificate problem of curl, set 'http.sslVerify' to 'false' (`git config --global http.sslVerify false`) or install CA certificates.
If you want to use bash-completion of git-hooks, install git-completion and place git-hooks-completion.bash in a 'bash-completion.d' directory:
- /etc/bash-completion.d
- /usr/local/etc/bash-completion.d
- ~/bash-completion.d
To update git-hooks, Run 'git hooks update https://github.com/murank/Git-Hooks/raw/master'.
These scripts use some git-config:
-
hook.remoteURL (used by git-hooks):
A default url that git-hooks gets hook scripts and git-hooks itself from (git-hooks will download script from ${hook.remoteURL}/script). -
hook.topicBranchFormat (used by commit-msg):
commit-msg will extract ticket ID from the name of topic branches within this format (by default, it's 'id/%ID%).Indicate the position of ticket ID by '%ID%' (it will replaced '[0-9][0-9]*'). And you can also use regex of sed to specify the format (but you shouldn't use brackets'()').
e.g. If hook.topicBranchFormat is 'id/%ID%/[a-z]*', then the ticket ID of the topic branch 'id/12/work' is 12. -
hook.msg4TopicBranch (used by commit-msg):
A format of the message to be inserted into a commit message (by default, it's 'refs #%ID%').Indicate the position to insert ticket ID by '%ID%' (it will replaced '\1').
e.g. If hook.msg4TopicBranch is '#%ID%', then the message to be inserted with ticket ID 13 is '#13'.
git hooks <command> [remoteURL]
Available commands are:
install Install hooks into the current git repository
update Update this script
And git-hooks will download scripts from remoteURL. If you want to skip passing the parameter, set 'hook.remoteURL'.
Test scripts (test_*) and files in 'shunit2' directory are distributed under the LGPL(v2.1), and others are under the NYSL(0.9982).