如何仅在子目录中运行赫斯基预提交 [英] How to run husky pre-commit in child directory only

查看:75
本文介绍了如何仅在子目录中运行赫斯基预提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个企业应用程序,其文件夹结构如下:

We have an enterprise application with a folder structure like the following:


/project
  .git
  /sub1
    ...Java project
  /sub2
    package.json
    ...Javascript Backbone project
  /sub3
    ...Java project
  /sub4
    ...Java project
  /sub5
    package.json
    ...Javascript React project

我目前在sub2和sub5项目中都设置了Husky,这会引起冲突(每次切换项目时都需要安装npm).此外,Java开发人员报告说,当他们在项目sub1,sub3和sub4中提交代码时,正在执行Husky git钩子.

I currently have Husky set up both in sub2 and sub5 projects, which causes conflicts (requires an npm install whenever I switch projects). Also, the Java developers are reporting that when they commit code in projects sub1, sub3 and sub4, the Husky git hooks are being executed.

如果您在提交时位于某个文件夹中,是否只能运行挂钩?

Is it possible to only have the hooks run if you are IN a certain folder when you commit?

推荐答案

如果您在提交时位于某个文件夹中,是否只能运行挂钩?

Is it possible to only have the hooks run if you are IN a certain folder when you commit?

否,但是挂钩本身可以确定运行时所在的目录.这没有正确记录,但是在Git chdir -s之前的环境中将 GIT_PREFIX 设置为 $ GIT_WORK_TREE $ GIT_DIR 目录.(自Git 1.7.8版以来就是这种情况.)

No, but the hook itself can determine which directory it was in when it was run. This is not properly documented, but GIT_PREFIX is set in the environment before Git chdir-s to the $GIT_WORK_TREE or $GIT_DIR directory. (This has been the case since Git version 1.7.8.)

这篇关于如何仅在子目录中运行赫斯基预提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆