Makefile: add pickrand
[cmccabe-bin] / export-git-tree.sh
1 #!/usr/bin/env bash
2
3 WORK_DIR=""
4
5 die() {
6     echo $@
7     exit 1
8 }
9
10 cleanup() {
11     if [ -z ${WORK_DIR} ]; then
12         echo "nothing to clean up."
13     else
14         rm -rf "${WORK_DIR}"
15     fi
16 }
17
18 if [[ $# != 1 ]]; then
19     die "You must supply one argument: the full path of the tar.gz file to create."
20 else
21     OUTPUT_TARGET="$1"
22     echo "Output target: $OUTPUT_TARGET"
23 fi
24
25 git status &>/dev/null || die "git status failed in the current directory."
26 git status | grep modified && die "git status showed some modified files."
27
28 GIT_DIR="$(pwd -P)"
29 WORK_DIR="$(mktemp -d)"
30 #trap cleanup EXIT
31
32 set -xe
33 pushd "${WORK_DIR}" &> /dev/null
34 git clone --bare "${GIT_DIR}" ./out
35 cp -f "${GIT_DIR}/.git/config" "./out/config"
36 tar cvzf ./out.tar.gz ./out
37 cp -f ./out.tar.gz "${OUTPUT_TARGET}"
38 set +xe
39 popd &> /dev/null