Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

modular-git-hooks

Build Status

Sometimes, you want to perform several different actions in one git hook. For example, you might find several useful pre-commit hooks online, all of which you would like to enable in your git repository.

One fragile way to accomplish this is to copy-and-paste all of the code from those various pre-commit hooks into the single hook that git requires, named hooks/pre-commit. This is, of course, impossible if some of those hooks are implemented in differing languages.

A slightly less-horrible but still-unpleasant mechanism is to create a hooks/pre-commit dispatching script which explicitly invokes each of the hooks you have downloaded and stored in separate files. But then you have to modify that dispatcher every time you update, deal with passing arguments and standard-input to the sub-hooks, and handle their exit statuses correctly.

This repository provides a general-purpose dispatch tool that does all that for you and requires no modification when you add or remove hooks. It gives you a separate directory for each type of git hook, allowing you to keep each hook in its own file. Toss as many hooks as you like into the appropriate directory and they will all be executed, in alphanumeric order, without editing configuration files or launcher-scripts. It uses git config for any configuration needs. It is implemented in dash- and bash-compatible shell script, which, granted, isn't the most pleasant or elegant, but on the other hand means you don't have to worry about your hooks breaking for lack of the correct version of Python, Ruby, or some other language du jour.

BeforeAfter
.git/
└── hooks/
    └── pre-commit*

(Where pre-commit performs formatting, linking, unit testing, and frobnicating)

.git/
└── hooks/
    ├── pre-commit.d/
    │   ├── format-code.sh*
    │   ├── run-linter.py*
    │   ├── unit-tests*
    │   └── frobnicate.rb*
    └── pre-commit -> /path/to/dispatch*

Most hooks intended for standalone use should work, unmodified, when placed within a hook-type directory.

This project contains:

  • The executable script dispatch, which is all that is needed from this project to enable the use of multiple git hooks per git hook type.
  • install-dispatch, which is a little helper script that will get dispatch set up for you.
  • tests/, a set of functional tests to prevent me from breaking this code.
  • hooks/, a collection of optional hooks that work well with dispatch, that you may install where useful. For more information, see the hooks README

Contents

License

Copyright 2014 Michael F. Lamb. This software is released under the terms of the GNU General Public License, version 3 or any later version.

About

A tool for organizing git hooks into directories of modular files.

Topics

Resources

License

Releases

No releases published

Packages

No packages published
You can’t perform that action at this time.