From ef32118a10785fe6792d3bad1d4b11590460bffe Mon Sep 17 00:00:00 2001 From: Colin P. McCabe Date: Wed, 6 Sep 2023 11:05:11 -0700 Subject: [PATCH] add export-git-tree.sh --- export-git-tree.sh | 39 +++++++++++++++++++++++++++++++++++++++ 1 files changed, 39 insertions(+), 0 deletions(-) create mode 100755 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 -- 1.6.6.rc1.39.g9a42