commit 636208156b4f43f556edc35d6819ff3f9191651d parent 0ad9d8ce6511c6072d17b1b77af3c57523dceae2 Author: JayVii <jayvii[AT]posteo[DOT]de> Date: Sat, 15 Jun 2024 19:45:32 +0200 feat: parse inputs from post-update hook Diffstat:
M | bin/git_export_tarball.sh | | | 48 | ++++++++++++++++++++++++++++++++++-------------- |
M | bin/git_post_push.sh | | | 2 | +- |
2 files changed, 35 insertions(+), 15 deletions(-)
diff --git a/bin/git_export_tarball.sh b/bin/git_export_tarball.sh @@ -12,7 +12,8 @@ if [ -z "$3" ]; then git_export_tarball.sh \\ \"/var/www/git.example.git\" \\ \"pub\" \\ - \"stagit-jayvii.de\" + \"stagit-jayvii.de\" \\ + \$@ # optional parameters given by post-update hook " exit 1; fi @@ -20,19 +21,38 @@ fi # Git-Repository cd "${1}/${2}/${3}.git" || exit 1; -# Get current branch name -BRANCH=`git branch --show-current || echo "HEAD"` +for REF in $@; do -# Retrieve URL if set -if [ -f "${1}/url" ]; then - URL=`cat ${1}/url` -else - URL="" -fi + # skip first three parameters + if [ "$REF" = "$1" ] || [ "$REF" = "$2" ] || [ "$REF" = "$3" ]; then + continue + fi + + # fetch branches and tags from given ref + BRANCHES=" + `git branch -a --contains $REF | awk '{ print $NF }'` + `git tag --contains $REF | awk '{ print $NF }'` + " + + # cycle through branches and tags + for BRANCH in $BRANCHES; do + + # create archive + git archive ${BRANCH} . \ + --format=tar.gz \ + -o "${BRANCH}.tar.gz" + + # create sha256 sum + sha256sum "${BRANCH}.tar.gz" | \ + tee "${1}/${2}/${3}/exports/${BRANCH}.tar.gz.sha256" > /dev/null + + # move archive into exports folder + mv "${BRANCH}.tar.gz" "${1}/${2}/${3}/exports/${BRANCH}.tar.gz" + + # Output for user + echo "Archive can be retrieved from ${URL}/${2}/${3}/exports/${BRANCH}.tar.gz" + + done -# Create tarball and sha256. place them in the export-directory -git archive --format=tar.gz -o "${BRANCH}.tar.gz" ${BRANCH} && -sha256sum "${BRANCH}.tar.gz" > "${1}/${2}/${3}/exports/${BRANCH}.tar.gz.sha256" && -mv "${BRANCH}.tar.gz" "${1}/${2}/${3}/exports/${BRANCH}.tar.gz" && -echo "Archive can be retrieved from ${URL}/${2}/${3}/exports/${BRANCH}.tar.gz" +done diff --git a/bin/git_post_push.sh b/bin/git_post_push.sh @@ -18,7 +18,7 @@ git_post_push.sh \\ fi . $HOME/bin/git_update_repo.sh "${1}" "${2}" "${3}" -. $HOME/bin/git_export_tarball.sh "${1}" "${2}" "${3}" +. $HOME/bin/git_export_tarball.sh "${1}" "${2}" "${3}" $@ . $HOME/bin/git_update_repo_html.sh "${1}" "${2}" "${3}" . $HOME/bin/git_update_index_html.sh "${1}" "${2}"