I\'m in the process of setting up a deployment script. The basic process is:
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. (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)
git submodule foreach
provides the $path
variable. See git help submodule
foreach section for more details.
I use this python package 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
If your submodule is in a repo accessible from the server, I would rather have a post-receive hook which would
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-all
would be able to detect the .git
subdirectories and would archive everything.If the submodule isn't accessible from the server, that means:
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" --
This should do the trick: https://github.com/meitar/git-archive-all.sh/wiki