Last active
March 15, 2024 10:55
-
-
Save arteymix/03702e3eb05c2c161a86b49d4626d21f to your computer and use it in GitHub Desktop.
Archive HEAD and its submodules recursively
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env sh | |
| if [ -z $1 ]; then | |
| echo "You must specify a super-archive name." | |
| exit 1 | |
| fi | |
| git archive --prefix "$1/" -o "$1.tar" HEAD | |
| git submodule foreach --recursive "git archive --prefix=$1/\$path/ --output=\$sha1.tar HEAD && tar --concatenate --file=$(pwd)/$1.tar \$sha1.tar && rm \$sha1.tar" | |
| gzip "$1.tar" |
Author
I just fixed it. It will effectively create two archive instead of concatenating into the main TAR.
found a problem when using this on https://github.com/jaiminpan/pg_jieba which has a recursive submodule,
pg_jieba
libjieba @ 391121d <= submodule here which has another submodule under
deps/
limonp @ a269e34
the current using of \$path would cause deps/libmonp being put at top directory instead of libjieba/ 's subdirectory,
debugging showing of these variables as:
ubuntu@Ubuntu:~/src/github.com/jaiminpan/pg_jieba$ git submodule foreach --recursive 'echo variables $name, $sm_path, $displaypath, $sha1 and $toplevel `git rev-parse HEAD`'
Entering 'libjieba'
variables libjieba, libjieba, libjieba, 391121d5db0f31dd5ce9795d4d34812f20eeb25c and /home/ubuntu/src/github.com/jaiminpan/pg_jieba 391121d5db0f31dd5ce9795d4d34812f20eeb25c
Entering 'libjieba/deps/limonp'
variables deps/limonp, deps/limonp, libjieba/deps/limonp, a269e34dc4948d5a9209e21a7887b52daa0d3e78 and /home/ubuntu/src/github.com/jaiminpan/pg_jieba/libjieba a269e34dc4948d5a9209e21a7887b52daa0d3e78you can see $displaypath showing the correct libjieba/deps/limonp with $path would mean deps/limonp cause being put to the top directory,
Changing your $path to $displaypath resolved this problem.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you !
I found a "typo":
git submodule foreach --recursive "git archive --prefix=\$path/ --output=\$sha1.tar HEAD && tar --concatenate --file=$(pwd)/$1.tar \$sha1.tar && rm \$sha1.tar"<-- Note the missing.tarin --file=$(pwd)/$1.tar