#!/bin/bash # Archive a git tag including submodules if [ $# -eq 0 ] then echo "No arguments supplied" echo "Usage: $0 " exit 0 fi prefix=$1 tag=$2 tempdir=$(mktemp -d -t $prefix-XXXXXX) set -e set -C # noclobber echo "> creating root archive" # create root archive git archive --verbose --prefix "$prefix-$tag/" --format "tar" --output "$tempdir/$prefix-$tag.tar" "$tag" echo "> appending submodule archives" # for each of git submodules append to the root archive git submodule foreach --recursive "git archive --verbose --prefix=$prefix-$tag/\$displaypath/ --format tar --output $tempdir/$prefix-sub-\$sha1.tar HEAD" exit 0 if [[ $(ls $tempdir/$prefix-sub-*.tar | wc -l) != 0 ]]; then # combine all archives into one tar echo "> combining all tars" for archive in $tempdir/$prefix-sub-*.tar; do tar --concatenate --file $tempdir/$prefix-$tag.tar $archive; done # remove sub tars echo "> removing all sub tars" rm -f $tempdir/$prefix-sub-*.tar fi # gzip the tar echo "> gzipping final tar" gzip --force --verbose $tempdir/$prefix-$tag.tar echo "> moving output file to $OUTPUT_FILE" mv $tempdir/$prefix-$tag.tar.gz . echo "> git-archive-all done"