简体   繁体   English

如何使用git-archive包含裸存储库中的子模块

[英]How can I use git-archive to include submodules from a bare repository

I'm in the process of setting up a deployment script. 我正在设置部署脚本。 The basic process is: 基本过程是:

  1. Push changes to a bare repository on the server 将更改推送到服务器上的裸存储库
  2. Then based on new tags will create a new folder for the release. 然后基于新标签将为该版本创建一个新文件夹。
  3. Use git archive to move the files into the release directory 使用git archive将文件移动到release目录中
  4. Runs some migrations scripts and puts it live (if all is successful). 运行一些迁移脚本并将其置于活动状态(如果一切都成功)。

The issue is my repository contains a submodule, which doesn't get put in the archive, and therefore doesn't get put in the release directory. 问题是我的存储库包含一个子模块,它不会被放入存档中,因此不会被放入发布目录中。

I've seen git-archive-all , but that doesn't work on a bare repository. 我见过git-archive-all ,但这不适用于裸存储库。

If its not possible, I'm considering, 如果不可能,我正在考虑,

  1. making the repository not bare, and updating the working copy, which would allow me to use git-archive-all. 使存储库不是裸露的,并更新工作副本,这将允许我使用git-archive-all。 Or 要么
  2. having a second bare repository of the submodule on the server, which I could get an archive from (would have to look into this to make sure I'm getting the right revision). 在服务器上有一个子模块的第二个裸存储库,我可以从中获取存档(必须查看这个以确保我得到正确的修订)。

I use this python package https://github.com/Kentzo/git-archive-all . 我使用这个python包https://github.com/Kentzo/git-archive-all You can install it by using 您可以使用安装它

pip install git-archive-all

On OSX, you can install it also using brew install git-archive-all 在OSX上,您也可以使用brew install git-archive-all安装它

If your submodule is in a repo accessible from the server, I would rather have a post-receive hook which would 如果您的子模块位于可从服务器访问的repo中,我宁愿使用post-receive hook

  • update a full non-bare repo (so a second repo beside your original bare one), including the submodule ( git submodule update --init ) 更新一个完整的非裸仓库(所以在你的原始裸git submodule update --init旁边的第二个git submodule update --init ),包括子模块( git submodule update --init
  • git archive from that second repo (you would be sure to get the right version since the non-bare repo would reference the right version of the submodule) 来自第二个仓库的git archive (你肯定会得到正确的版本,因为非裸仓库将引用正确版本的子模块)
    Since the non-bare repo would contain the parent repo and its submodules, git archive-all would be able to detect the .git subdirectories and would archive everything . 由于非裸露的回购协议将包含母公司回购其子模块, git archive-all将能够检测到.git子目录和归档会一切

If the submodule isn't accessible from the server, that means: 如果无法从服务器访问子模块,则表示:

  • it needs to be pushed in its own repo on the server 它需要在服务器上推送自己的repo
  • the submodule in the parent repo needs to be reference with a relative path, in order for the parent repo to still be able to retrieve said submodule once pushed on the server. 父repo中的子模块需要使用相对路径进行引用,以便父repo在服务器上推送后仍然能够检索所述子模块。

Here it is as a few-liner: 这里只是几个班轮:

prefix=$(basename "$(pwd -P)")
{
  git ls-files
  git submodule foreach --recursive --quiet \
                'git ls-files --with-tree="$sha1" | sed "s#^#$path/#"'
} | sed "s#^#$prefix/#" | xargs tar -c -C.. -f "$prefix.tar.xz" --

Run the following after the regular archive command: 在常规归档命令之后运行以下命令:
git submodule foreach 'cd REPO_ROOT/$path && git archive HEAD | tar -x -C TARGET_ROOT/$path'

Here the REPO_ROOT is where your repo stands and the TARGET_ROOT is where you put your archived version. 这里REPO_ROOT是您的仓库所在的位置,TARGET_ROOT是您存档的版本。 (I assume that you have a TARGET_ROOT folder where the expanded version of the first git archive call. If you want a final zip/tar, you can tar/zip the final folder) (我假设您有一个TARGET_ROOT文件夹,其中第一个git archive调用的扩展版本。如果您想要最终的zip / tar,您可以tar / zip最终文件夹)

git submodule foreach provides the $path variable. git submodule foreach提供了$path变量。 See git help submodule foreach section for more details. 有关更多详细信息,请参阅git help submodule foreach部分。

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

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