Skip to content

azu/git-hooks

Repository files navigation

@azu/git-hooks Actions Status

@azu's global git hooks.

Features

  • Global Git Hooks collection
  • If project has set up local git hook, call local hooks too
    • Order: local hooks -> global hooks
  • Define ignoring project by IGNORE_GLOBAL_HOOKS file

Hooks

  • pre-commit

Installation

Requirement:

  • Node.js 16+
  • Git 2.9+
  • 1Password CLI

Check if you already have any global git hooks:

git config --global core.hooksPath

If output is not empty, run following steps:

# clone this repository
git clone https://github.com/azu/git-hooks.git git-hooks
cd git-hooks
# Install Dependencies
yarn install
# setup git config
git config --global core.hooksPath $(pwd)/hooks

Load env using 1Password CLI

op inject --in-file .env.local.template --out-file .env

Zsh Integration

Some project have defined core.hooksPath in git config.

Git prefer to use local core.hooksPath than global core.hooksPath.

So, I've overridden the local core.hooksPath with global hooks paths.

# Override <project>/.githook → <global>/git-hooks/hooks/
function preexec_git_global_hooks() {
  inside_git_repo="$(git rev-parse --is-inside-work-tree 2>/dev/null)"
  if [ "$inside_git_repo" ]; then
      githooksDir=$(git rev-parse --show-toplevel)"/.githooks"
      if [ -d "${githooksDir}" ]; then
        git config --local core.hooksPath "/path/to/git-hooks/hooks"
      fi;
  fi
}
autoload -Uz add-zsh-hook
add-zsh-hook preexec preexec_git_global_hooks

Options

You have set up, then bootstrap script create IGNORE_GLOBAL_HOOKS file. It is collection of absolute path to ignore global hooks.

IGNORE_GLOBAL_HOOKS:

/path/to/my-project-a
/path/to/my-project-b

If the project path is included in IGNORE_GLOBAL_HOOKS, global git hook does not run.

FAQ

Want to ignore pre-commit hook

Use --no-verify options.

git commit --no-verify

Contributing

Pull requests and stars are always welcome.

For bugs and feature requests, please create an issue.

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Author

License

MIT © azu

Acknowledgement