Cross-platform, configurable, git hook utility geared for Go codebases.
****** Functional, but still in Beta ******
Git hooks are scripts/commands that git can execute on certain events which helps you automate tasks, enforce quality and consistency in your code, and more. captain-githook
allows you to utilize any and all git hooks in your repository (commit-msg
, pre-commit
, pre-push
, etc.) via a simple configuration file.
Yes, there are other git hook utilities out there (in fact we love, recommend, and use husky in our JavaScript/TypeScript projects that use npm). However, we made captain-githook
because we wanted a git hook utility for our Go codebases that was cross-platform, easily configurable, and that wasn't dependent on another, non-Go framework/runtime.
We'll be adding binary releases shortly, but for now you'll need to have your Go environment setup and use go get
i.e.:
go get -u github.com/swellaby/captain-githook
Note that the latest captain-githook
version requires Go 1.12 or higher. If you need to use captain-githook
on Go 1.11 and earlier, make sure you use the v0.0.7
tag:
go get -u github.com/swellaby/captain-githook@v0.0.7
This will ensure that the captain-githook executable is available on your system for initializing your repositories (creating git hook and config files) as well as for executing your defined hook scripts.
Run the init
sub-command within a git repository to create the git hook files and create the captain-githook
config file:
captain-githook init
If you'd prefer to use a different name for the config file, you can specify your desired config file name as a flag (--config-filename
or --f
) on the init
command. For example:
captain-githook init --config-filename .captain-githookrc.json
See allowed config file names below for info on what config file names you can use.
You specify which scripts/commands you want to run for each git hook in the captain-githook
configuration file included in your repository.
The captain-githook config is a json formatted file (we'll consider supporting other formats like yaml or toml if there's enough interest) and must be named with one of the allowed file names.
Just ensure there's a hooks
object key, and then for every git hook you want to run, add a key with the hook name (see supported hooks for allowed hook names) and the script/command you want to run.
// captaingithook.json
{
"hooks": {
"pre-commit": "golint ./...",
"pre-push": "go test ./..."
}
}
captain-githook
supports all the below git hooks:
applypatch-msg
pre-applypatch
post-applypatch
pre-commit
prepare-commit-msg
commit-msg
post-commit
pre-rebase
post-checkout
post-merge
pre-receive
update
post-receive
post-update
pre-auto-gc
post-rewrite
pre-push
There are several supported names you can use for your config file:
captaingithook.json
.captaingithook.json
captaingithookrc
.captaingithookrc
captaingithookrc.json
.captaingithookrc.json
captain-githook.json
.captain-githook.json
captain-githookrc
.captain-githookrc
captain-githookrc.json
.captain-githookrc.json
Not yet implemented