简体   繁体   English

来自钩子脚本的 GIT 克隆导致空目录

[英]GIT clone from hook script results in empty directory

I don't really know where to go with this one and have tried everything I can think of.我真的不知道用这个去哪里,并尝试了我能想到的一切。

I have a GitLab server running on Ubuntu 14.04.我有一个在 Ubuntu 14.04 上运行的 GitLab 服务器。 I've creating a post-receive hook script (bash) that clones the repo to a new folder in the /tmp directory and then copies the files out to a mounted remote directory.我创建了一个接收后挂钩脚本 (bash),它将 repo 克隆到 /tmp 目录中的一个新文件夹,然后将文件复制到已安装的远程目录中。 If I run the script while logged into the git user the script runs fine, but when it runs as the hook-script it does not.如果我在登录 git 用户时运行脚本,脚本运行良好,但当它作为钩子脚本运行时,它不会。 The script starts running fine but the result of the git clone command is a totally empty folder.脚本开始运行良好,但 git clone 命令的结果是一个完全空的文件夹。 Not even any repo files.甚至没有任何回购文件。 Also, I don't get any error from the clone command.另外,我没有从克隆命令中得到任何错误。 The clone command only returns a single line: clone 命令只返回一行:

(my command) git clone file:///var/opt/gitlab/git-data/..../999.git 999 (我的命令)git clone file:///var/opt/gitlab/git-data/..../999.git 999

(return) Cloning into '999' (返回)克隆到'999'

Again, if I run the same clone command from the command line from the same user I don't have this issue, so I don't think it's a permission thing.同样,如果我从同一用户的命令行运行相同的克隆命令,我就没有这个问题,所以我认为这不是权限问题。

Any pointers on where I can go from here?关于我可以从这里去哪里的任何指示?

Thanks!谢谢!

I cannot reproduce this problem, but that may be because your Git version is older than mine (mine is 2.8.1 and 2.6 added new options for separate work directories that changed a lot of the code in question; I don't know what version you have, but I am betting it predates 2.6).我无法重现此问题,但这可能是因为您的 Git 版本比我的旧(我的 2.8.1 和 2.6 为单独的工作目录添加了新选项,这些选项更改了很多相关代码;我不知道是什么版本你有,但我打赌它早于 2.6)。 So this may not be the correct solution, but then again, it might.所以这可能不是正确的解决方案,但话又说回来,它可能。 :-) :-)

When hook scripts run, they have an environment variable, GIT_DIR , set to the path containing the repository.当钩子脚本运行时,它们有一个环境变量GIT_DIR ,设置为包含存储库的路径。 For post-receive s this is always just .对于post-receive s,这总是 just . (the post-receive hook runs in the repository directory). (post-receive 钩子在存储库目录中运行)。 It seems likely that this is causing your clone to fail.这似乎很可能导致您的克隆失败。

If so, simply unset GIT_DIR in your script before doing the git clone .如果是这样,只需在执行git clone之前在脚本中unset GIT_DIR即可。

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

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