Git pre-commit hooks only for a specific subfolder?

Currently, I have one repo with two projects, each of which is in its own subfolder: one in C # and one in Javascript. I want to have a pre-commit binding that will run jshint, but only if any of the staged files are in the Javascript folder. If the phased files are located only in the C # folder, the pre-commit hook will not be launched.

Is this even possible? Or is my only decision to split the two projects into my own repositories?

+4
source share
1 answer

Git hooks are scripts that Git runs before or after performing certain actions.

If you write a script and save it as <repository_name>/.git/hooks/pre-commit, then Git will run it before committing. Therefore, write a simple script for the operating system you are using, which runs jshint against this subfolder and saves it along the way.

Git does not start your pre-commit hook with any arguments. You can use the Git commands to find out the status of your repository (changes added as part of the commit are still just delivered and available via --cached). If you make any changes and want them to become part of the commit, you need to add them before the script exits.

You work with C #, so you should be aware that git hooks on windows are a bit fancy: Doing Git hooks on Windows

0

All Articles