
| Current Path : /bin/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : //bin/git-archive-file |
#!/usr/bin/env bash
# reset environment variables that could interfere with normal usage
unset GREP_OPTIONS
# put all utility functions here
# make a temporary file
git_extra_mktemp() {
mktemp -t "$(basename "$0")".XXXXXXX
}
#
# check whether current directory is inside a git repository
#
is_git_repo() {
git rev-parse --show-toplevel > /dev/null 2>&1
result=$?
if test $result != 0; then
>&2 echo 'Not a git repo!'
exit $result
fi
}
is_git_repo
# extract current branch name
BRANCH=$(git rev-parse --abbrev-ref HEAD 2> /dev/null)
# 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`\)