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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
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() {
cgitrc_repo daterc dated "$@"
}
test_expect_success 'relative dates are on by default' '
daterc &&
cgit_ok 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_ok 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_ok daterc "" >tmp &&
grep "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]<" tmp &&
! grep "class=.age-" tmp &&
cgit_ok daterc "url=dated/log/" >tmp &&
grep ">2005-04-07<" tmp &&
! grep "class=.age-" tmp
'
test_expect_success 'date-format selects the calendar format' '
daterc "enable-relative-dates=0" "date-format=iso8601" &&
cgit_ok 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, on the index too' '
daterc "enable-relative-dates=0" "date-format=format:%Y/%m/%d" &&
cgit_ok daterc "url=dated/refs/" >tmp &&
grep ">[0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9]<" tmp &&
cgit_ok daterc "" >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_ok 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_ok 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_ok 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 'date-format=local is the default format in local time' '
daterc "enable-relative-dates=0" "date-format=local" &&
cgit_ok daterc "url=dated/log/" >tmp &&
grep ">Fri Apr 1 11:14:15 2005<" tmp
'
test_expect_success 'a -local date-format shows the server timezone' '
daterc "enable-relative-dates=0" "date-format=iso8601-local" &&
(
TZ=EST5 &&
export TZ &&
cgit_ok daterc "url=dated/log/"
) >tmp &&
grep ">2005-04-07 17:13:13 -0500<" tmp
'
test_expect_success 'local-time shows commit times in the server timezone' '
sha=$(git -C repos/dated rev-parse HEAD~1) &&
daterc "local-time=1" &&
(
TZ=EST5 &&
export TZ &&
cgit_ok daterc "url=dated/commit/&id=$sha"
) >tmp &&
grep ">2005-04-07 17:13:13 -0500<" tmp &&
daterc &&
(
TZ=EST5 &&
export TZ &&
cgit_ok daterc "url=dated/commit/&id=$sha"
) >tmp &&
grep ">2005-04-07 22:13:13 +0000<" tmp
'
test_expect_success 'date-format still formats the log fallback' '
daterc "date-format=rfc2822" &&
cgit_ok 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_ok daterc "url=dated/commit/&id=$sha" >tmp &&
grep "2005-04-07 [0-9:]* +0000" tmp &&
! grep "Apr 2005" tmp
'
test_expect_success 'a date in a listing stays on one line' '
sed -n "/^div#cgit time.age-mins,$/,/^}/p" \
"$TEST_OUTPUT_DIRECTORY/../assets/cgit.css" >rule &&
grep "^div#cgit table.list time {$" rule &&
grep "^ white-space: nowrap;$" rule
'
test_expect_success 'odd dates and zones in pushed objects render' '
test_create_repo repos/odd &&
(
cd repos/odd &&
test_commit base &&
c=$(git rev-parse HEAD) &&
t=$(printf "object %s\\ntype commit\\ntag early\\ntagger E <e@x> 1 -0100\\n\\nearly\\n" $c |
git hash-object -t tag -w --stdin) &&
git update-ref refs/tags/early $t &&
tree=$(git rev-parse HEAD^{tree}) &&
far=$(printf "tree %s\\nauthor A <a@x> 9223372036854775808 +0000\\ncommitter A <a@x> 9223372036854775808 +0000\\n\\nfar\\n" $tree |
git hash-object -t commit -w --literally --stdin) &&
git update-ref refs/heads/far $far &&
zone=$(printf "tree %s\\nauthor A <a@x> 1700000000 -2147483648\\ncommitter A <a@x> 1700000000 +99999999999\\n\\nzone\\n" $tree |
git hash-object -t commit -w --literally --stdin) &&
git update-ref refs/heads/zone $zone
) &&
cgitrc_repo oddrc odd &&
for q in "url=odd/" "url=odd/refs/" "url=odd/tag/&h=early" \
"url=odd/log/&h=far" "url=odd/commit/&h=far" "url=odd/commit/&h=zone" \
"url=odd/atom/&h=far"
do
cgit_rc oddrc "$q" >tmp 2>err &&
grep "^Status: 200" tmp &&
! grep "Unable to complete" tmp &&
! grep "Timestamp" err || return 1
done &&
cgit_rc oddrc "url=odd/commit/&h=far" >tmp &&
grep "1970-01-01" tmp
'
test_done
|