]> git.scottworley.com Git - pinch/blame - tests/lib/test-setup.sh
README is markdown
[pinch] / tests / lib / test-setup.sh
CommitLineData
a2290fb1
SW
1set -e
2
36b163ac
SW
3export BACKOFF_MAX_TIME=0
4
1b48018c
SW
5export GIT_AUTHOR_NAME=automation
6export GIT_COMMITTER_NAME=automation
7export GIT_AUTHOR_EMAIL=auto@mati.on
8export GIT_COMMITTER_EMAIL=auto@mati.on
9
78c89e6e 10cache_dir=$(mktemp -d)
9eecb073 11data_dir=$(mktemp -d)
78c89e6e 12export XDG_CACHE_HOME=$cache_dir
9eecb073 13export XDG_DATA_HOME=$data_dir
78c89e6e 14
4af9966c
SW
15nix_store=$(mktemp -d)
16nix_state=$(mktemp -d)
17export NIX_STORE_DIR=$nix_store
18export NIX_STATE_DIR=$nix_state
19
a2290fb1
SW
20foo_setup() {
21
22 repo_dir="`mktemp -d`"
23 repo="$repo_dir/repo"
ba23f997 24 git -c init.defaultBranch=master init "$repo"
a2290fb1
SW
25 (
26 cd "$repo"
27 echo Contents > test-file
28 git add test-file
29 git commit -m 'Commit message'
30 )
31
32 conf="`mktemp`"
33 cat > "$conf" <<EOF
34[foo]
7f4c3ace 35type = git
a2290fb1
SW
36git_repo = file://$repo
37git_ref = master
38EOF
39
40}
41
d9a1088a
SW
42test_cleanup() {
43 if [ "$repo_dir" ];then rm -rf "$repo_dir"; fi
44 if [ "$conf" ];then rm "$conf"; fi
78c89e6e 45 if [ "$cache_dir" ];then rm -rf "$cache_dir"; fi
9eecb073 46 if [ "$data_dir" ];then rm -rf "$data_dir"; fi
4af9966c
SW
47 if [ "$nix_store" ];then rm -rf "$nix_store"; fi
48 if [ "$nix_state" ];then rm -rf "$nix_state"; fi
a2290fb1 49}
d9a1088a
SW
50
51trap test_cleanup EXIT INT TERM