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
|
test_description='Check the date display options'
. ./setup.sh
test_expect_success 'set up a dated repo' '
mkrepo repos/dated 1 &&
(
cd repos/dated &&
GIT_AUTHOR_DATE="@1112911993 +0000" \
GIT_COMMITTER_DATE="@1112911993 +0000" \
git commit --allow-empty -m old &&
GIT_AUTHOR_DATE="@$(date +%s) +0000" \
GIT_COMMITTER_DATE="@$(date +%s) +0000" \
git commit --allow-empty -m fresh
)
'
daterc() {
{
echo "virtual-root=/"
echo "cache-size=0"
printf '%s\n' "$@"
echo "repo.url=dated"
echo "repo.path=$PWD/repos/dated/.git"
} >daterc
}
dateq() { CGIT_CONFIG="$PWD/daterc" QUERY_STRING="$1" cgit; }
test_expect_success 'relative dates are on by default' '
daterc &&
dateq "url=dated/refs/" >tmp &&
grep "class=.age-" tmp
'
test_expect_success 'enable-relative-dates=0 shows a calendar date' '
daterc "enable-relative-dates=0" &&
dateq "url=dated/refs/" >tmp &&
! grep "class=.age-" tmp &&
grep "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]<" tmp
'
test_expect_success 'the index and log columns follow the same flag' '
daterc "enable-relative-dates=0" &&
dateq "" >tmp &&
! grep "class=.age-" tmp &&
dateq "url=dated/log/" >tmp &&
! grep "class=.age-" tmp
'
test_expect_success 'date-format selects the calendar format' '
daterc "enable-relative-dates=0" "date-format=iso8601" &&
dateq "url=dated/refs/" >tmp &&
grep ">[0-9-]* [0-9][0-9]:[0-9][0-9]:[0-9][0-9] +0000<" tmp
'
test_expect_success 'date-format accepts a strftime format' '
daterc "enable-relative-dates=0" "date-format=format:%Y/%m/%d" &&
dateq "url=dated/refs/" >tmp &&
grep ">[0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9]<" tmp
'
test_expect_success 'an unknown date-format falls back to short' '
daterc "enable-relative-dates=0" "date-format=nonsense" &&
dateq "url=dated/refs/" >tmp &&
grep "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]<" tmp &&
daterc "enable-relative-dates=0" "date-format=format:" &&
dateq "url=dated/refs/" >tmp &&
grep "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]<" tmp
'
test_expect_success 'date-format still formats the log fallback' '
daterc "date-format=rfc2822" &&
dateq "url=dated/log/" >tmp &&
grep "class=.age-" tmp &&
grep ">[A-Z][a-z][a-z], [0-9]* Apr 2005 " tmp
'
test_expect_success 'date-format leaves the commit page on ISO 8601' '
daterc "date-format=rfc2822" &&
sha=$(git -C repos/dated rev-parse HEAD~1) &&
dateq "url=dated/commit/&id=$sha" >tmp &&
grep "2005-04-07 [0-9:]* +0000" tmp &&
! grep "Apr 2005" tmp
'
test_done
|