[英]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. git diff --cached --name-only --diff-filter=ACM src/
将返回在src/
文件夹中添加、复制或修改的文件列表。
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".在钩子脚本中,使用wc -l
检查git diff
命令输出的行数,如果输出为“0”,则提前退出钩子。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.