GIT post-receive hook不检出子模块 [英] GIT post-receive hook not checking out submodules

查看:267
本文介绍了GIT post-receive hook不检出子模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究Kohana 3项目,我之前使用下载的zip文件进行安装。我在远程服务器project.git上有一个git存储库,它将检查最新的提交到我测试应用程序的工作目录public_html。

接收钩子文件

  GIT_WORK_TREE = / var / www / public_html; 
git checkout -f;

这个工作了几个月,直到我决定删除一些kohana文件夹并使用git子模块,所以我可以通过git进行更新。



现在问题是子模块不在工作目录中。我试着在那里添加子模块,但public_html目录不是存储库。在project.git目录中,git命令会抛出一个错误,我必须在工作目录中执行它们。



如何修改我的钩子以检出子模块按照@ manojlds的建议:
$ b

p> $ b我将它添加到钩子中,现在看起来像这样:
$ b

GIT_WORK_TREE = / var /网络/的public_html;
git submodule init;
git子模块更新;
git checkout -f;

但是我得到这个信息,

  remote:您需要从工作树的顶层运行此命令

并且没有对中的子模块进行更改

  public_html 


解决方案

这是我的post-receive hook:
将WORK_DIR替换为您想要签出的位置。这是我的案例中的主要网站目录。它被初始化为一个git仓库,并且简单地从这个钩子运行的git裸仓库中取出。这样可以解决检出速度问题(git比cp-R更快地检查出另一个答案),并且保持子模块正确同步。

 #!/ bin / sh 
未设置GIT_DIR
echo结帐
(cd $ WORK_DIR&&git pull --recurse-submodules = yes --force)
echoSubmodule update ...
(cd $ WORK_DIR&& git --work- tree =$ WORK_DIRsubmodule update --init --recursive --force)


I have been working on a Kohana 3 project that I installed using the downloaded zip file awhile ago. I have a git repository on my remote server "project.git" which checks out the latest commits to the working directory "public_html" where I test the application

My post-receive hook file

GIT_WORK_TREE=/var/www/public_html;
git checkout -f;

which was working for a couple of months until I decided to remove some kohana folders and use git submodule instead, so I can do updates via git.

Now the problem is that the submodules are not in the working directory. I tried going in there to add the submodules but the "public_html" directory isn't a repository. In the "project.git" directory, git commands throw an error that I must perform them in the working directory.

How do I modify my hook to checkout submodules when I do a commit?

Update

As per @manojlds's suggestion: I added it to the hook and now it looks like this:

GIT_WORK_TREE=/var/www/public_html;
git submodule init;
git submodule update; 
git checkout -f;

But I get this message,

remote: You need to run this command from the Top level of the working tree

and no changes to the submodules in

public_html

解决方案

This is my post-receive hook: Replace WORK_DIR with a location where you want to checkout to. This is a main web directory in my case. It is initialized as a git repository and simply pulls from the git bare repository this hooks runs in. This solves both the checkout speed (git is much faster in checking out than cp -R from the other answer is) and also keeps submodules properly synced.

#!/bin/sh
unset GIT_DIR
echo "Checking out"
(cd $WORK_DIR && git pull --recurse-submodules=yes --force)
echo "Submodule update..."
(cd $WORK_DIR && git --work-tree="$WORK_DIR" submodule update --init --recursive --force)

这篇关于GIT post-receive hook不检出子模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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