Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.
/ Git-Hooks Public archive
forked from bleis-tift/Git-Hooks

Git hooks that assist TiDD(Ticket-Driven Development) with Git.

Notifications You must be signed in to change notification settings

murank/Git-Hooks

 
 

Repository files navigation

Git Hooks

What's this

Git hooks that assist TiDD(Ticket-Driven Development) with Git.

Contents

Hook scripts

  • 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.

Installation script

  • git-hooks:
    Help to install above hook scripts in repositories, and to update git-hooks itself.

Instalation

  1. 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`
  2. 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'.

Cofiguration

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'.

Usage

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'.

License

Test scripts (test_*) and files in 'shunit2' directory are distributed under the LGPL(v2.1), and others are under the NYSL(0.9982).

About

Git hooks that assist TiDD(Ticket-Driven Development) with Git.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 94.2%
  • Perl 5.8%