forked from kernc/myba
-
Notifications
You must be signed in to change notification settings - Fork 0
/
smoke-test.sh
executable file
·98 lines (79 loc) · 2.29 KB
/
smoke-test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/sh
# shellcheck disable=SC2064,SC2139
set -eux
export LC_ALL=C
myba () { "$(dirname "$0")/myba.sh" "$@"; }
disk_usage () { du -h "$HOME" | sort -h; }
export KDF_ITERS=100 # Much faster encryption
# Prepare test
# $HOME is the default WORK_TREE dir
HOME="$(mktemp -d -t myba-test-XXXXXXX)"
export HOME
trap 'rm -fr "$HOME"; trap - INT HUP EXIT' INT HUP EXIT
if [ ! "${CI:-}" ]; then case "$HOME" in /tmp*|/var/*) ;; *) exit 9 ;; esac; fi
mkdir "$HOME/foo"
echo 'foo' > "$HOME/foo/.dotfile"
dd if=/dev/random bs=1000000 count=1 of="$HOME/foo/other.file"
touch "$HOME/untracked.file"
touch "$HOME/ignored_by_default.so"
# Create mock git remote (i.e. GitHub)
create_mock_remote () {
git init --bare "$1"
rm "$1/hooks"/*.sample # Don't pollute du output
# Must be set on the remote server to support our `git clone --filter=`
git -C "$1" config uploadpack.allowFilter true
}
remote_git="$HOME/remote"
remote_git2="$HOME/remote2"
create_mock_remote "$remote_git"
create_mock_remote "$remote_git2"
# Here we go, user ...
VERBOSE=1 myba init
myba add "$HOME/foo/.dotfile"
myba add "$HOME/foo/other.file"
myba git status
export PASSWORD=secret
myba commit -m "message"
myba remote add origin "$remote_git"
myba remote add origin2 "$remote_git2"
#myba push origin # XXX: Fails on CI but wfm
myba push
export PAGER=
myba log
# Somewhere else, much, much later ...
WORK_TREE="$HOME/restore" # From here on, $WORK_TREE overrides $HOME
export WORK_TREE
myba clone "file://$(readlink -f "$remote_git")" # Clone by uri as non-local
myba checkout HEAD
myba checkout "foo/.dotfile"
# No overwrite existing file unless forced
if myba checkout "foo/.dotfile"; then exit 2; fi
YES_OVERWRITE=1 myba checkout "foo/.dotfile"
unset YES_OVERWRITE # Fix for buggy macOS shell
myba restore
if myba restore; then exit 3; fi
YES_OVERWRITE=1 myba restore --squash
myba log
# Another commit from this side
touch "$WORK_TREE/bar"
myba add "$WORK_TREE/bar"
myba rm foo/other.file
myba commit -m 'add bar'
myba push
disk_usage
myba gc
disk_usage
# foo + .myba + remote + remote2 + restore + overhead
test "$(du -sm "$HOME" | cut -f1)" -le 6
myba log
cat "$WORK_TREE/foo/.dotfile"
test "$(cat "$WORK_TREE/foo/.dotfile")" = "foo"
test "$(ls -a "$WORK_TREE")" = "\
.
..
.myba
bar
foo"
#bash # Inspect/debug test
set +x
echo "$0: Done ok"