From afefba74886f27d3767d48e0be86d97dbeaceb07 Mon Sep 17 00:00:00 2001 From: Philipp Klose Date: Fri, 15 Feb 2013 05:35:06 +0100 Subject: [PATCH] import from https://github.com/TheHippo/git-archive-file --- bin/git-archive-file | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 bin/git-archive-file diff --git a/bin/git-archive-file b/bin/git-archive-file new file mode 100755 index 0000000..e9dca7d --- /dev/null +++ b/bin/git-archive-file @@ -0,0 +1,34 @@ +#!/bin/bash + +# extract current branch name +BRANCH=$(git name-rev HEAD 2> /dev/null | awk "{ print \$2 }") + +# get name of the most top folder of current directory, used for the +# output filename +ARCHIVE_NAME=$(basename $(pwd)) + +if [[ $BRANCH = tags* ]]; then + BRANCH=$(git describe) + echo Building for tag \"$BRANCH\" + FILENAME=$ARCHIVE_NAME.$BRANCH.zip +else + echo Building archive on branch \"$BRANCH\" + # get a version string, so archives will not be overwritten when creating + # many of them + VERSION=$(git describe --always --long) + # if not on master append branch name into the filename + if [ "$BRANCH" = "master" ]; then + FILENAME=$ARCHIVE_NAME.$VERSION.zip + else + FILENAME=$ARCHIVE_NAME.$VERSION.$BRANCH.zip + fi +fi + +# combine path and filename +OUTPUT=$(pwd)/$FILENAME + +# building archive +git archive --format zip --output $OUTPUT $BRANCH + +# also display size of the resulting file +echo Saved to \"$FILENAME\" \(`du -h $OUTPUT | cut -f1`\) \ No newline at end of file