add export-git-tree.sh
authorColin P. McCabe <cmccabe@apache.org>
Wed, 6 Sep 2023 18:05:11 +0000 (11:05 -0700)
committerColin P. McCabe <cmccabe@apache.org>
Wed, 6 Sep 2023 18:05:11 +0000 (11:05 -0700)
export-git-tree.sh [new file with mode: 0755]

diff --git a/export-git-tree.sh b/export-git-tree.sh
new file mode 100755 (executable)
index 0000000..5399fc3
--- /dev/null
@@ -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