git post-receive hook 没有运行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8206023/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 12:22:17  来源:igfitidea点击:

git post-receive hook not running

githook

提问by Nick F

I have a bare repo server-side, and I am able to successfully commit and push from my local machine. However, the post-receive hook is not running. Details:

我有一个裸仓库服务器端,我能够从我的本地机器成功提交和推送。但是,post-receive 钩子没有运行。细节:

  • Using SSH as protocol
  • I have renamed the standard "post-receive.sample" to "post-receive"
  • This file has -rwxr-xr-xpermissions
  • The file is owned by the same user that owns the repo, which is the same SSH user that logs in and pushes
  • The actual pushing goes fine; files are updated - it's just the hook that does not run
  • I tried putting echo "Some text"before and after the hook, but this is not shown (see: Post Commit Hook Not Running).
  • Hook script is included below, although this appears not to be causing the problem
  • Using git 1.7.0.4 on Ubuntu 10.04
  • 使用 SSH 作为协议
  • 我已将标准“post-receive.sample”重命名为“post-receive”
  • 这个文件有-rwxr-xr-x权限
  • 该文件由拥有 repo 的同一用户拥有,即登录和推送的同一 SSH 用户
  • 实际的推动很顺利;文件已更新 - 只是未运行的钩子
  • 我尝试echo "Some text"在钩子前后放置,但这没有显示(请参阅:Post Commit Hook Not Running)。
  • 钩子脚本包含在下面,虽然这似乎不会导致问题
  • 在 Ubuntu 10.04 上使用 git 1.7.0.4

.

.

user@server:/home/repos/project1/hooks# cat post-receive
#!/bin/sh
echo "Hook is running..."
export GIT_WORK_TREE=/home/web/project1/www/
git checkout -f
rm -rf /home/web/project1/www/temp/

采纳答案by dericbytes

The issue was related to the mounting of the filesystem. The partition was mounted as noexec, and therefore no files could be executed. This caused the hook not to run. I removed the noexecflag and it now works just fine.

该问题与文件系统的安装有关。该分区已挂载为noexec,因此无法执行任何文件。这导致钩子无法运行。我删除了noexec标志,现在工作正常。

回答by Nick F

In order for a Git hook to run, it needs to have permissions set to allow it to be executable. If a hook doesn't seem to be running, check the permissions, and make sure it's executable. If it isn't you can make all hooks executable like this:

为了让 Git 钩子运行,它需要设置权限以允许它是可执行的。如果钩子似乎没有运行,请检查权限,并确保它是可执行的。如果不是,您可以像这样使所有钩子可执行:

chmod ug+x .git/hooks/*

...or if you want to make a single hook (eg. post-receive) executable:

...或者如果你想让单个钩子(例如post-receive)可执行:

chmod ug+x .git/hooks/post-receive

(Thanks to this post)

(感谢这篇文章

回答by dericbytes

I had this problem. I had a typo in my script filename.

我有这个问题。我的脚本文件名中有一个错字。

post-recieve instead of post-receive

后接收而不是后接收

回答by Rakesh

Seems GIT will NOT run the post-receivehook if there are nochanges to the code base.

如果代码库没有变化,似乎 GIT 不会运行post-receive钩子。

In my case,

就我而言,

The post hook was not getting executed, but the "push" operation kept returning the following message.

post 钩子没有被执行,但“推送”操作不断返回以下消息。

Everything up-to-date

一切都是最新的

So I just created an empty file in my code, did commit and then pushed to remote. On which the post-receivehook got executed.

所以我只是在我的代码中创建了一个空文件,提交了然后推送到远程。在其上执行post-receive钩子。

回答by micha137

I had the same problem on a Centos 6 system, where it turned out that SELinux prevented hooks scripts from running. Turning httpd_git_script_tinto a permissive domain helped here (since "sesearch -A -s httpd_git_script_t -p exec" yielded nothing, ie. no process running in the httpd_git_script_t domain was allowed exec permission):

我在 Centos 6 系统上遇到了同样的问题,结果是 SELinux 阻止了钩子脚本的运行。将httpd_git_script_t转换为一个许可域在这里有帮助(因为“sesearch -A -s httpd_git_script_t -p exec”没有产生任何结果,即没有允许在 httpd_git_script_t 域中运行的进程具有 exec 权限):

semanage permissive -a httpd_git_script_t

回答by Andrew Kolesnikov

Are you sure it's not running? It must be running, you just can't see it. My guess is that there is not stdout set to your ssh session at the time it's executed, so you won't ever see the output of your echo. The link suggests testing it locally, not via ssh.

你确定它没有运行?它一定在运行,你只是看不到它。我的猜测是在执行 ssh 会话时没有为您的 ssh 会话设置标准输出,因此您永远不会看到回声的输出。该链接建议在本地进行测试,而不是通过 ssh。