summaryrefslogtreecommitdiffstats
path: root/test.sh
blob: cc65c641eeb5c0a4b43459b574d32b15fa309abd (plain) (blame)
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
set -e

scriptDir="$( dirname "$0" )"

source "$scriptDir/git-base.sh"

echo "\n---------------------------"
echo "\n In a git repo"
echo "\n---------------------------"

echo "\nTest: Root of this git repo"
echo "$(git_root)"

echo "\nTest: Location of .git"
echo "$(dot_git)"

echo "\nTest: is_repo should be false"
if is_repo; then
  echo "is repo"
else
  echo "not repo"
fi

echo "\nTest: Record the timestamp"
record_timestamp
echo "Timestamp = $(timestamp)"
echo "Time now = $(time_now)"

echo "\nTest: Time to update when just recorded"
if time_to_update; then
  echo "time to update"
else
  echo "not time yet"
fi

echo "\nTest: Don't fetch if it's not time to update"
fetch_async "debug"

echo "\nTest: Time to update when timestamp 5 mins ago"
touch -A "-010000" "$(dot_git)/lastupdatetime"
if time_to_update; then
  echo "time to update"
else
  echo "not time yet"
fi

echo "\nTest: Do a non-blocking git fetch"
fetch_async "debug"
echo "Did I block?"


echo "\n---------------------------"
echo "\n Not in a git repo"
echo "\n---------------------------"

mkdir -p /tmp/git-base-tests
cd /tmp/git-base-tests

echo "\nTest: Root of this git repo"
echo "git_root is:$(git_root) (empty means no root)"

echo "\nTest: Location of .git"
echo "dot_git is:$(dot_git) (empty means no root)"

echo "\nTest: is_repo should be false"
if is_repo; then
  echo "is repo"
else
  echo "not repo"
fi

echo "\nTest: Record the timestamp"
record_timestamp
echo "no output should be seen"

echo "\nTest: Check the timestamp"
echo "timestamp is:$(timestamp) (empty means not in dir)"

echo "\nTest: Is it time to update?"
if time_to_update; then
  echo "time to update"
else
  echo "not time yet"
fi

echo "\nTest: Try to fetch"
fetch_async "debug"