From: Colin P. McCabe Date: Wed, 6 Sep 2023 18:05:11 +0000 (-0700) Subject: add export-git-tree.sh X-Git-Url: http://www.club.cc.cmu.edu/~cmccabe/cgi-bin/gitweb.cgi?p=cmccabe-bin;a=commitdiff_plain;h=ef32118a10785fe6792d3bad1d4b11590460bffe add export-git-tree.sh --- diff --git a/export-git-tree.sh b/export-git-tree.sh new file mode 100755 index 0000000..5399fc3 --- /dev/null +++ b/export-git-tree.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +WORK_DIR="" + +die() { + echo $@ + exit 1 +} + +cleanup() { + if [ -z ${WORK_DIR} ]; then + echo "nothing to clean up." + else + rm -rf "${WORK_DIR}" + fi +} + +if [[ $# != 1 ]]; then + die "You must supply one argument: the full path of the tar.gz file to create." +else + OUTPUT_TARGET="$1" + echo "Output target: $OUTPUT_TARGET" +fi + +git status &>/dev/null || die "git status failed in the current directory." +git status | grep modified && die "git status showed some modified files." + +GIT_DIR="$(pwd -P)" +WORK_DIR="$(mktemp -d)" +#trap cleanup EXIT + +set -xe +pushd "${WORK_DIR}" &> /dev/null +git clone --bare "${GIT_DIR}" ./out +cp -f "${GIT_DIR}/.git/config" "./out/config" +tar cvzf ./out.tar.gz ./out +cp -f ./out.tar.gz "${OUTPUT_TARGET}" +set +xe +popd &> /dev/null