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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
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 &&
unset GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
git commit --allow-empty -m fresh &&
now=$(git log -1 --format=%ct) &&
for age in mins:5380 hours:108000 days:864000 weeks:3628800 \
months:47304000 years:94608000 future:-86400
do
GIT_COMMITTER_DATE="@$((now - ${age#*:})) +0000" \
git tag -a -m ${age%%:*} ${age%%:*} || return 1
done
)
'
daterc() {
{
echo "virtual-root=/"
echo "cache-size=0"
printf '%s\n' "$@"
echo "repo.url=dated"
echo "repo.path=$PWD/repos/dated/.git"
} >daterc
}
test_expect_success 'relative dates are on by default' '
daterc &&
cgit_rc daterc "url=dated/refs/" >tmp &&
grep "class=.age-" tmp
'
test_expect_success 'each age bucket counts in its own unit' '
daterc &&
cgit_ok daterc "url=dated/refs/" >tmp &&
grep ">mins</a>.*<time class=.age-mins. [^>]*>90 min.</time>" tmp &&
grep ">hours</a>.*<time class=.age-hours. [^>]*>30 hours</time>" tmp &&
grep ">days</a>.*<time class=.age-days. [^>]*>10 days</time>" tmp &&
grep ">weeks</a>.*<time class=.age-weeks. [^>]*>6 weeks</time>" tmp &&
grep ">months</a>.*<time class=.age-months. [^>]*>18 months</time>" tmp &&
grep ">years</a>.*<time class=.age-years. [^>]*>3 years</time>" tmp
'
test_expect_success 'a date past now reads as no age at all' '
daterc &&
cgit_ok daterc "url=dated/refs/" >tmp &&
grep ">future</a>.*<time class=.age-mins. [^>]*>0 min.</time>" tmp
'
test_expect_success 'an age keeps the date it stands for' '
iso=$(git -C repos/dated for-each-ref --format="%(taggerdate:iso8601)" refs/tags/years) &&
strict=$(git -C repos/dated for-each-ref --format="%(taggerdate:iso-strict)" refs/tags/years) &&
test -n "$iso" &&
daterc &&
cgit_ok daterc "url=dated/refs/" >tmp &&
grep "<time class=.age-years. datetime=.$strict. data-ut=.[0-9]*. title=.$iso.>3 years</time>" tmp
'
test_expect_success 'enable-relative-dates=0 shows a calendar date' '
daterc "enable-relative-dates=0" &&
cgit_rc daterc "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" &&
cgit_rc daterc "" >tmp &&
! grep "class=.age-" tmp &&
cgit_rc daterc "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" &&
cgit_rc daterc "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" &&
cgit_rc daterc "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" &&
cgit_rc daterc "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:" &&
cgit_rc daterc "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 'a date-format git would refuse falls back to short' '
daterc "enable-relative-dates=0" "date-format=local-local" &&
cgit_rc daterc "url=dated/refs/" >tmp &&
grep "^Status: 200" tmp &&
grep "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]<" tmp
'
test_expect_success 'date-format=local is the default format in local time' '
daterc "enable-relative-dates=0" "date-format=local" &&
cgit_rc daterc "url=dated/refs/" >tmp &&
grep ">[A-Z][a-z][a-z] [A-Z][a-z][a-z] [0-9]* [0-9:]* [0-9]*<" tmp
'
test_expect_success 'date-format still formats the log fallback' '
daterc "date-format=rfc2822" &&
cgit_rc daterc "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) &&
cgit_rc daterc "url=dated/commit/&id=$sha" >tmp &&
grep "2005-04-07 [0-9:]* +0000" tmp &&
! grep "Apr 2005" tmp
'
test_done
|