Simple git-hook integration for your gulp workflows.
guppy streamlines and extends your git-hooks by integrating them with your gulp workflow. This enables you to have gulp tasks that run when triggered by a git-hook, which means you can do cool things like abort a commit if your tests are failing. Git-hooks can now be managed through npm, allowing them to automatically be installed and updated. And because they integrate with gulp, it's easy to modify the workflow and even combine hooks with your other gulp tasks.
guppy leverages these powerful existing systems as its backbone, allowing guppy (and therefore your git-hooks) to remain as simple and lightweight as possible through interfaces you're already familiar with.
A git-hook that lint-checks your code and makes sure your unit tests pass before committing could be as simple as
npm i git-guppy --save-dev
The actual scripts that git will run to trigger guppy's hooks will be automatically
installed to your
.git/hooks/ directory. These are just a wrapper for invoking
the gulp tasks that guppy registers.
Typically, a workflow can be added to your gulp tasks via a guppy-hook. A guppy-hook is like a git-hook preconfigured for specific gulp workflows.
You can install guppy-hooks via
npm just like any other package. For every valid
git-hook name, there exists a "guppy-[hookname]" package that automatically installs
the related hook to your
.git/hooks dir, e.g. "guppy-pre-commit" or "guppy-post-update".
Just add the guppy-hook you need as a dev-dependency in your project.
Search "guppy-hook" on npm to find all
guppy-hook packages. Or run
npm search guppy-hook from the commandline.
⚠️ Stop! If you are using a guppy-hook package, refer to the documentation for that package. You do not need the steps below unless you are adding custom guppy integration to your gulpfile or authoring your own guppy-hook package.
guppy exposes a few simple methods to help you superpower your git-hooks with gulp tasks.
Before you dive in, initialize guppy by passing in your gulp reference:
var gulp = ;var guppy = gulp;
Then simply define some gulp tasks in your
gulpfile.js whose names match
whichever git-hooks you want to be triggerable by git.
Note: if you are working directly with guppy rather than installing a guppy-hook you will need to manually install the associated git-hooks using the guppy-cli commandline tool.
Pass in the name of the desired git-hook and get back the related filenames. This allows you to work with the source file directly, for example to modify a commit-msg programmatically or lint changed files.
Note for pre-commit and pre-applypatch this will give you the working-copy,
not the indexed (staged) changes. If you want the indexed changes, use
// contrived examplegulp;
Supported hooks: all
If you pass the optional
fn argument, it will be passed to
gulp.task() as the
task callback, but the first argument will be the related filenames (or
if none) and a second optional argument may also be supplied (when applicable)
with any additional arguments received from the git-hook as an array. gulp will
provide its callback as the last argument.
// less contrived examplegulp;// another contrived examplegulp;
Pass in the name of the git-hook to produce a stream of the related files. You can pass options as a second argument, please refer to the docs for gulp.src for more information on available options.
Note that depending on the git-hook, you may be acting on files that differ from
your working copy, such as those staged for commit (as with 'pre-commit' for
example), rather than the working copy. If you need to act on the working-copy
For many git-hooks there are no files associated, so for those it makes sense
to only add other gulp tasks as dependencies to invoke a workflow, however some
will still receive some arguments (passed in by
guppy.src() when used as a
callback) for more advanced use cases.
For details on what arguments each git-hook receives and what result a non-zero exit status would have, check the git-scm docs.
MIT © Kevin Lanni