2

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?

nrofis
  • 8,975
  • 14
  • 58
  • 113

1 Answers1

0

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.

phd
  • 82,685
  • 13
  • 120
  • 165
  • Yes, I'm aware to that. In my question I meant if there is a way to add register hooks in sub-directory. Similar concept of `.gitignore` file that can be defined in sub-directories and has the directory scope – nrofis Nov 18 '20 at 09:58
  • "*if there is a way to add register hooks in sub-directory*" There is no until you implement it yourself. Something like [`husky`](https://stackoverflow.com/q/53869155/7976758) – phd Nov 18 '20 at 10:22