Git hooks in sub-directory

Viewed 1196

I have one repo that contains several React projects in different directories. For the structure

> Repo Root
  > .git
  > CRA Project1
  > CRA Project2

There are git hooks defined in the .git in the repo root for global things.
But I want to add hooks specifically for each project. Say, running custom linter with pre-commit in CRA Project1 but not in CRA Project2.

How can I add hooks per project if global hook are already defined?

1 Answers

Git doesn't have a notion of subprojects. From Git point of view the entire working tree with .git/ repository at the top is just a single project with one set of hooks in .git/hooks/.

Said that, you could implement subproject hooks yourself with help from the global hooks. Every hook in .git/hooks/ must determine if it's being run on global branches/commits/files or on subproject(s) and for subproject(s) it calls subproject hooks.

Related