简体   繁体   中英

Run a pre-commit hook if the file is modified under a specific directory

My project has client code and server code in one project

I want to run the test code through the pre-commit hook only when the client code has been modified.

Is there a way to run a pre-commit hook only when a file is modified under a specific folder?

The hook cannot be prevented from executing, but you can prevent the bulk of the script from running using a conditional.

git diff --cached --name-only --diff-filter=ACM src/ will return the list of files added, copied or modified in the src/ folder.

In your hook script, check the number of lines that are output from the git diff command using wc -l , and exit the hook early if the output is "0".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM