什么用户运行git钩子? [英] What user runs the git hook?

查看:155
本文介绍了什么用户运行git钩子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在服务器上有一个post-update钩子,这样当我

  git push 

code>

它会在实时网页目录上执行操作。然而,尽管推送总是成功,但更新后的钩子有时会失败。



钩子很简单:

 #!/ bin / sh 

#一个示例钩子脚本,用于准备打包存储库以用于
#dumb传输。

#要启用此挂钩,请将此文件重命名为post-update。
cd / var / www
env -i git pull

我是推送来自不同地方的更新,但有时我必须在服务器上以root用户身份登录,并手动执行

  env -i git pull 

我只需要在20%的时间内完成。任何想法为什么它会随机失败?另外,如何让它记录错误信息,因为它可能是以无法写入文件系统的人的身份运行的? 解决方案

挂钩在用户进行推送时运行。如果您有某种预先设置的设置,可能是像 git gitosis 这样的用户,或者它可能是你。只要看看你如何配置远程。 ( git远程显示<远程名称> 或者只是检查.git / config,如果你不知道)推测你是通过SSH推送的,主机名。



PS这很快就能证明这一点 - 只需在本地克隆一个回购站点,用 echo $ USER 或类似的方法抛出一个更新后的钩子,然后尝试按自己或别的用户(直接或通过ssh)。


I have a post-update hook on my server, such that when I

git push

it does a pull on the live web directory. However, while the push always succeeds, the post-update hook sometimes fails.

The hook is pretty simple:

#!/bin/sh
#
# An example hook script to prepare a packed repository for use over
# dumb transports.
#
# To enable this hook, rename this file to "post-update".
cd /var/www
env -i git pull

I'm pushing updates from a variety of places, but sometimes I have to login as root on the server and manuall do a

env -i git pull

I only have to do it 20% of the time though. Any ideas why it would fail randomly? Also, how would I get it to log error messages, since it might be running as someone who can't write to the file system?

解决方案

The hooks are run as the user doing the push. If you have some kind of pre-made setup, that may be a user like git or gitosis, or it may be you. Just look at how you have the remote configured. (git remote show <remote-name> or just examine .git/config if you don't know) Presumably you're pushing via SSH, and there's a username@hostname in the URL.

P.S. It's pretty quick to demonstrate this - just clone a repo locally, throw a post-update hook in with an echo $USER or something similar, and try pushing as yourself or a different user (directly or through ssh).

这篇关于什么用户运行git钩子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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