我怎样才能自动拉git子模块? [英] How can I pull git submodule automatically?

查看:176
本文介绍了我怎样才能自动拉git子模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被分配了一个项目,在那里我将进行后端开发,另一个人将处理前端开发。要求前端开发人员无权访问开发服务器和项目代码。因此,我们决定为前端创建另一个存储库。



问题是,我不知道如何让子模块立即从远程服务器拉出来,致力于远程回购。我需要开发人员提交并立即查看前端中的更改。

我一直在阅读关于git钩子的知识,并且我发现我可以使用 post-receive 钩子来完成。但是,它似乎并不奏效。这是我做的:


  1. 从主项目的根目录中,我找到了以下目录/.git/modules/submodule-directory/钩子

  2. 我创建了 post-receive 文件,其中包含可执行权限

  3. post-receive 文件的内容:

     #!/ bin / sh 
    git pull


  4. 从我的本地机器推送到子模块回购什么都没有发生。


我做错了什么?

编辑:我要澄清一些关于我的问题的观点。



我有两个存储库:main存储库,它是整个项目;和另一个存储库,这是前端的东西(视图,资产等)。我们称之为前端存储库。



在我的主存储库中,我将前端回购添加为位于/ submodules / frontend内的子模块。这样,外包前端开发人员将无法看到有关实际项目的任何信息。他们只会看到他们在做什么。



这实际上在访问控制方面非常完美,我可以轻松地从项目中单独监控前端开发的进度。但有一个问题我不知道该怎么做。

我们的项目有两个独立的服务器 - 一个开发服务器和一个生产服务器。开发服务器需要始终在主分支中,用于主仓库和前端仓库。这样,前端团队和后端团队都将能够看到他们的更新。尽管前端团队主要使用模板,但模板可以访问存储在数据库中的数据,并且使用了很多集成到后端的内容(例如模型)。



为了使这个系统能够正常工作,我需要前端回购在前端远程回购协议中提交新的提交时始终进行提取和合并。换句话说,如果前端团队执行 git commit git push ,开发中的前端回购子模块服务器需要立即 git pull 。所以,当前端人员测试他们的东西时,他们会立即看到最新的变化。



我读了 post-receive 钩子可以做到这一点,但我需要这个钩子只存在于子模块中。所以,在挖掘之后,我发现所有的子模块钩子都存在于 / .git / modules / submodules / frontend / hooks 中。因此,我使用下面的代码在该目录中创建了 post-receive 钩子:

 #!/ bin / sh 
git pull

但这不起作用。我的问题是如何使钩子与post-receive内部子模块一起工作?



我知道我采用的路线远非完美,但这是唯一的方法在允许开发人员只访问一个目录而无需访问开发服务器的情况下,这对我来说很有意义。



我希望这是有道理的。

解决方案

当你 git pull ,这(基本上)等于 git fetch&& git merge 。这不会更新子模块。



如果我理解您的需求,您可以使用命令 git submodule update (或 git submodule foreach'git pull')在您的post-receive钩子中(在主.git /钩子目录中)。

ADD(基于您的版本):根据我的理解,您需要在gitlab前端存储库中添加 post-receive 钩子,并且你的钩子必须执行命令 git submodule update (或者可能是 git submodule foreach'git fetch&& git merge'在开发服务器(使用ssh命令或其他)。



但重新考虑开发服务器的安装方式可能更容易,您可以将2 repos安装为完全分开(而不是前端作为子模块),并且可能将子模块/前端添加到.gitignore目录。这不一定意味着您必须从子模块中删除 frontend ,但只是不在开发服务器中使用它。


I am assigned a project, where I will be doing backend development and another person will be handling frontend development. There is a requirement that the frontend developer does not have access to the development server, nor the project code. So, we decided to create another repository just for frontend.

The problem is that I don't know how to make submodule to immediately pull from the remote server when something is committed to the remote repo. I need the developer to commit and immediately see the change in the frontend.

I have been reading about git hooks and I have found that I can do this using post-receive hook. However, it doesn't seem to work. Here is what I did:

  1. From the main project's root directory, I found the following directory /.git/modules/submodule-directory/hooks
  2. I created post-receive file with executable permission allowed.
  3. Contents of post-receive file:

    #!/bin/sh
    git pull
    

  4. Pushed a change from my local machine to the submodule repo but nothing happened.

What am I doing wrong?

EDIT: I am going to clarify some points regarding my question.

I have two repositories: The "main" repository, which is the entire project; and another repository, which is frontend stuff (views, assets etc). Let's call this "frontend" repository.

To my main repository, I added frontend repo as a submodule, located inside /submodules/frontend. This way, the outsourced frontend developers will not be able to see anything about the actual project. They will only see what they are working on.

This actually works perfectly in terms of access control and I can easily monitor the frontend development's progress separately from project. But there is one problem that I don't know how to do.

Our project has two separate servers - a development server and a production server. The development server needs to always be in the master branch for both main repo and frontend repo. This way, both frontend team and the backend team will be able to see their updates. Even though frontend team mainly works with templates, the templates have access to data that is stored in the database and are using a lot of stuff that are integrated to backend (e.g models).

In order for this "system" to work, I need the frontend repo to always fetch and merge whenever there is a new commit in "frontend" remote repo. In other words, if the frontend team does git commit and git push, the "frontend" repo submodule in the development server needs to immediately git pull. So, when the frontend guys go test their stuff, they will immediately see the latest changes.

I read that post-receive hook can do that but I need this hook to exist only for submodule. So, after some digging I found that all the submodule hooks exist in /.git/modules/submodules/frontend/hooks. So, I created post-receive hook in that directory with the following code:

#!/bin/sh
git pull

But this didn't work. My question is how to make the hooks work with post-receive inside submodule?

I know the route that I have taken is far from perfect but this is the only way that makes sense to me when it comes to allowing devs to only access one directory without having access to the development server.

I hope this makes sense.

解决方案

When you git pull, this is (basically) equivalent to git fetch && git merge. This will not update submodules.

If I understand your needs, What you want can be done with the commands git submodule update (or git submodule foreach 'git pull') in your post-receive hooks (in the main .git/hooks directory).

ADD (based on your editions): based on what I understood, you need to add the post-receive hook on the gitlab frontend repository, and your hook must execute the command git submodule update (or maybe git submodule foreach 'git fetch && git merge' in the development server (with a ssh command or something).

But it may be easier to rethink how your development server is installed, you can install the 2 repos as totally separated (not frontend being a submodule), and maybe adding the submodule/frontend to your .gitignore directory. This not necessarily means you have to remove frontend from the submodule, but just not using it in your development server.

这篇关于我怎样才能自动拉git子模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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