Skip to content

Instantly share code, notes, and snippets.

@fkirc
Created September 23, 2019 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fkirc/e4f9fbbb06cea7809a69deb2a4fd33fe to your computer and use it in GitHub Desktop.
Save fkirc/e4f9fbbb06cea7809a69deb2a4fd33fe to your computer and use it in GitHub Desktop.
git repo to zip
#!/usr/bin/env bash
set -x
set -e
usage() {
echo "Usage: $0 <output name> <git repo path>"
exit 1
}
[[ $# -eq 2 ]] || {
usage
}
ARCHIVE_NAME=$1
REPO_PATH=$2
# Enforce that the "release repo" is clean
if [ -z "$(cd $REPO_PATH && git status --porcelain)" ]; then
echo "Pass: Release directory clean"
else
echo "Release directory not clean - abort"
exit 1
fi
# Checkout release branch
cd $REPO_PATH && git checkout master
# Cleanup all stuff that is not checked in
cd $REPO_PATH && git clean -xfd
# Remove any unreferenced tree objects for security reasons
cd $REPO_PATH && git gc --aggressive --prune=all
# Zip it
zip -r $ARCHIVE_NAME $REPO_PATH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment