本文介绍了Git远程/共享预先提交钩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用一个官方存储库作为远程存储库,并从中克隆多个本地存储库,可以在该主存储库上编写预提交钩子,并在其所有克隆上执行?

可能是钩子脚本本身是版本化的,然后链接到(符号链接)在克隆服务器(提供他们的操作系统支持链接功能)。

或者,如果钩子是,用于创建克隆(这只会确保它们的存在在克隆回购中,这并不能保证它们实际上被使用和执行)。

但我认为没有任何中心方式来强制执行提交。




正如Jefromi在评论中更加清楚地解释(重点是我):


我认为这确实违背了git存储库的想法,使强制挂钩与repo分发。

我的克隆是我的存储库。我应该可以在其上使用git,但是我喜欢,包括选择是否运行钩子。

(从安全角度来看,这确实有点吓人 - 没有人应该拥有当我运行某些git命令时,这种能力迫使我执行某些脚本。)


我同意这个评论,并且只能看到一些方法例如,您不会直接推送到中央仓库,而是首先推送到质量保证仓库,只有在遵循以下条件时才会接受您的提交一定的规则。如果确实如此,那么质量保证回购会将您的承诺推向中央回购。



另一个直接来自我刚刚提到的例子是,一种强制本地 / em>在将它们推到任何地方之前可以使用的私人版本。


With a one official repository as the remote, and multiple local repositories cloned from it, can a pre-commit hook be scripted on that main repository and be enforced on all clones of it?

解决方案

I don't think so, as hooks are not cloned.
May be if that hook script is itself versioned, and then link to (symbolic link) in the clone servers (provided their OS support that link feature).

Or maybe if the hooks are part of a git template directory used for creating the clones (that would only ensure their presences in the clone repo, that would not guarantee they are actually used and executed).

But I don't think there is any "central" way to enforce a commit.


As Jefromi explains even more clearly in the comments (emphasis mine):

I agree with that comment, and have only seen ways to enforce rules applied locally, in a given specialized repo.
For instance, you wouldn't push to the central repo directly, but would first push to a QA repo which would accept your commit only if it follows certain rules. If it does, then the QA repo will push your commit to the central repo.

Another illustration directly derived from what I just mentioned would be "Serverless Continuous Integration with Git", a way to enforce locally private build that works before pushing them anywhere.

这篇关于Git远程/共享预先提交钩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 08:01