Created
September 23, 2019 14:09
-
-
Save fkirc/e4f9fbbb06cea7809a69deb2a4fd33fe to your computer and use it in GitHub Desktop.
git repo to zip
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 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