简体   繁体   English

如何自动化符号链接脚本

[英]How to automate symlink script

Everyone knows you cannot commit anything in .git/hooks because it's not a git repository. 每个人都知道您无法在.git/hooks提交任何内容,因为它不是git存储库。

So I wrote a script to symlink all hooks in .git/hooks to point to all of my hooks located in my_repo/hooks/driver . 因此,我编写了一个脚本以符号链接.git/hooks所有钩子,以指向位于my_repo/hooks/driver所有my_repo/hooks/driver Now I can track and commit my hooks, as I please. 现在,我可以根据需要跟踪并提交我的钩子。 This was recommended by several stack overflow users across many threads (see link below). 跨多个线程的几个堆栈溢出用户建议这样做(请参见下面的链接)。

Putting git hooks into repository 将git钩子放入存储库

The problem is I don't want other developers (who work on the same repository) to manually run my script, it should just run automatically run when they pull or init the repository (assuming they did not run it once already). 问题是我不希望其他开发人员(在同一个存储库上工作)手动运行我的脚本,当他们拉动或初始化存储库时,它应该自动运行(假设他们没有一次运行过该脚本)。

Anyone have any ideas? 有人有想法么? Tons of threads on tracking git hooks, none on automating it once the script is written (ie like I have). 跟踪git钩子的线程数不多,一旦脚本编写完成就没有使线程自动化的能力(即像我一样)。 :( :(

Git has no facility for automatically running a script on your local system when you first clone a repository. 当您第一次克隆存储库时,Git无法自动在本地系统上运行脚本。 This would present a substantial security issue. 这将带来严重的安全问题。

Your best course of action is probably to provide a set-up-hooks command of some sort that will install the necessary symlinks into a local repository, and include instructions for running this script in your README or equivalent documentation for new developers. 最好的做法可能是提供某种set-up-hooks命令,该命令会将必要的符号链接安装到本地存储库中,并在README文件或新开发者的等效文档中包含有关运行此脚本的说明。

Depending on the technology you are using, there might be ways to hook this into a build or dependency management tool. 根据您使用的技术,可能有多种方法可以将其挂接到构建或依赖项管理工具中。

In the Node.js world, some thing people use are 在Node.js世界中,人们使用的一些东西是

  • npm 's install/postinstall script ( https://docs.npmjs.com/misc/scripts ): You would add your script command in the package.json file as npminstall/postinstall脚本( https://docs.npmjs.com/misc/scripts ):您可以将package.json文件中的脚本命令添加为

     "scripts": { "install": "link-my-git-hooks" } 

    This would ensure that your script is run anytime someone runs npm install locally. 这样可以确保您的脚本可以在有人在本地运行npm install运行。

  • Grunt: If you're using Grunt (or a similar build tool), you could use something along the lines of https://www.npmjs.com/package/grunt-githooks , which will install the hooks as part of the build process. Grunt:如果您使用的是Grunt(或类似的构建工具),则可以使用类似于https://www.npmjs.com/package/grunt-githooks的内容 ,它将在构建过程中安装这些钩子处理。 When someone runs grunt locally to build the project, your Git-Hooks would be installed/verified/updated. 当有人在本地运行grunt构建项目时,将安装/验证/更新您的Git-Hooks。

So the general idea here is that you should integrate the process of installing the hooks with something that developers run on a regular basis anyway. 因此,这里的总体思路是,您应该将钩子的安装过程与开发人员定期运行的东西集成在一起。 I completely agree that it shouldn't be an additional step that people usually forget about - add it to something that they're already using every day. 我完全同意,这不应该是人们通常会忘记的附加步骤-将其添加到他们每天已经在使用的内容中。

The above examples are just ideas - there are probably similar tools/approaches for other technologies. 以上示例仅是想法-其他技术可能也有类似的工具/方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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