#git-hook #git #directory #changed #monorepo #root-directory #execute

app git-hooks-dispatch

Run hooks only in a directory where files are changed. Useful for monorepo.

6 releases (3 breaking)

0.4.2 Aug 31, 2021
0.4.1 Aug 23, 2021
0.3.0 Aug 4, 2021
0.2.0 Aug 2, 2021
0.1.0 Aug 1, 2021

#1861 in Development tools

Download history 2/week @ 2024-02-21 3/week @ 2024-02-28 15/week @ 2024-03-27 36/week @ 2024-04-03

51 downloads per month

MIT license

19KB
398 lines

git-hooks-dispatch

Run hooks only in a directory where files are changed. Useful for monorepo.

Crates.io test

Install

cargo install git-hooks-dispatch

Setting up

Set up hooks you want as the following:

Hook file (e.g. .git/hooks/pre-commit)

#!/bin/sh
git-hooks-dispatch $(basename $0) -- "$@"

Make sure the file has permission to execute.

Then, in the child directories, you can set up hooks as they are in the project root directory.

For example:

./sub-project1/git-hooks/pre-commit

#!/bin/sh
npm run lint-staged

./sub-project2/git-hooks/pre-commit

#!/bin/sh
mvn antrun:run@ktlint-format

Hooks are executed recursively

In the below example, if ./foo/bar/B is changed, pre-commit hooks are executed recursively in the following order:

  1. ./foo/bar/git-hooks/pre-commit
  2. ./foo/git-hooks/pre-commit
.
├── .git
│  └── hooks
│     └── pre-commit
└── foo
   ├── A
   ├── git-hooks
   │  └── pre-commit
   └── bar
      ├── B
      └── git-hooks
         └── pre-commit

Hooks dir name

git-hooks-dispatch searches a hook dir which name is hooks-dir or .hooks-dir by default. You can change it by --hooks-dir option.

git config core.hooksPath git-hooks

Print logs

Setting RUST_LOG environment variable turns logging on.

RUST_LOG=debug git commit ...

Dependencies

~16–28MB
~450K SLoC