如何强制GIT post-receive hook不被客户端执行 [英] How to force GIT post-receive hook not to be executed by the client

查看:125
本文介绍了如何强制GIT post-receive hook不被客户端执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我们的本地办公室设置使用Apache,Linux等共享的Debian Samba磁盘。因此,我们克隆了来自 w:/webs/site.com/site.git 这是BARE回购。



我们已经创建了一个bash脚本作为位于 w:/webs/site.com/site.git/hooks/post-receive 上的post-receive挂钩,我们认为这个挂钩会被执行linuxgit,如`/home/samba/webs/site.com/hooks ...包含一个条件脚本,取决于分支承诺结账类似于:

  GIT_WORK_TREE = / home / samba / webs / site.com / html git checkout -f $ BRANCH 

问题在于,当我们从我们的tortoiseGIT本地副本到原始分支的PUSH时,钩子失败,出现:


remote:fatal:无法切换到'C:/ Program Files
(x86)/Git/home/samba/webs/site.com/html':没有这样的文件或
目录到w:/webs/site.com/site.git


我们理解的意思是WORK_TREE或整个钩子脚本正在被客户端GIT执行。



问题是我们打算通过SSH和其他方式访问repos,所以如果我们使用Windows本地路径,当我们从非Windows本地网络客户端推送时失败。替代方案可能是通过SSH即使在本地提交回购协议,但我们认为这样做效率很低,只会在挂钩问题上需要。



任何建议和/或我们可以使用的GIT变量可以兼容吗?感谢。

解决方案

这个问题真的与GIT_WORK_TREE的路径有关,而不是解释器本身。
$ b

现在我们已经知道使用:GIT_WORK_TREE =../ html可以完美地兼容Windows客户端通过Samba或SSH访问git通过Linux进行访问。



显然,GIT 钩子在存储库根目录本身 (不是钩子目录之一)中执行。



现在,我们的其他问题与符号链接有关......如果推送过程是从Windows客户端完成的,则符号链接将作为文件出现在自动生成的(结帐)HTML目录中,而不像原始文件符号链接。



我们终于决定出于这个原因通过SSH访问repos,即使是本地的。 ;(

New to GIT trying to implement a workflow.

Our local office setup uses a shared Debian Samba disk with Apache, Linux, etc. We therefore clone projects from a "local path" of type w:/webs/site.com/site.git This are BARE repos.

We've created a bash script as a "post-receive" hook located on w:/webs/site.com/site.git/hooks/post-receive wich we thought would be executed by the "linux" git at something like `/home/samba/webs/site.com/hooks... that includes a conditional script depending on the branch commited to checkout similar to:

GIT_WORK_TREE=/home/samba/webs/site.com/html git checkout -f $BRANCH

The problem is that when we PUSH from our tortoiseGIT local copy to the origin branch the hook fails with a:

remote: fatal: Could not switch to 'C:/Program Files (x86)/Git/home/samba/webs/site.com/html': No such file or directory To w:/webs/site.com/site.git

Which we understand means the WORK_TREE or whole hook script is being executed by the clients GIT.

The problem is that we plan to open SSH and other access to the repos, so if we used Windows local paths those would fail when we push from a non Windows local network client. The alternative might be to PULL the repos via SSH even if locally but we feel this is rather inefficient and would only be required for this hook issue.

Any suggestions and/or GIT variables we could use that can be compatible with both? Thanks.

解决方案

The issue is really related to the path for the GIT_WORK_TREE rather than the interpreter itself.

We've now figured that using: GIT_WORK_TREE="../html" works perfectly either from Windows clients accessing via Samba or SSH git pushes via Linux.

Apparently GIT hooks are executed within the repository root directory itself (not the hook directory one) where the .git exists.

Our "other" issues now are related to symlinks... if the push process is done from the Windows client the symlinks appear in the autogenerated (checkout) HTML dir as files instead as like the original symlinks.

We've finally decided for this reason to access the repos via SSH even if local. ;(

这篇关于如何强制GIT post-receive hook不被客户端执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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