t4205: improve handling of ICONV prerequisite

In t4205 we have a bunch of tests that depend on the iconv prereq. This is for most of the part because we format commit messages that have been encoded in an encoding different than UTF-8. Those tests fall into two classes though: - One class of tests outputs the data as-is without reencoding. - One class of tests outputs the data with "i18n.logOutputEncoding" to reencode it. Curiously enough, both of these classes are marked with the ICONV prereq, even though one might expect that the first class wouldn't need the prereq. This is because we unconditionally use ISO-8859-1 encoding for the initial commit message, and thus we depend on converting to UTF-8 indeed. This creates another problem though: when the iconv(1) executable does not exist the test setup fails, even in the case where the ICONV prereq has not been set. Fix these issues by making the test encoding conditional on ICONV: if it's available we use ISO-8859-1, otherwise we use UTF-8. This fixes the test setup on platforms without iconv(1), and it allows us to drop the ICONV prereq from a bunch of tests. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Feb 20, 2026 at 09:26 UTC effb0aa84b3b3e6a16ed744fc9361257c7259d97
1 file changed +28 -22
t/t4205-log-pretty-formats.sh
+28 -22
@@ -9,7 +9,12 @@ test_description='Test pretty formats'
9 . ./test-lib.sh
10
11 # Tested non-UTF-8 encoding
12 -test_encoding="ISO8859-1"
12 +if test_have_prereq ICONV
13 +then
14 + test_encoding="ISO8859-1"
15 +else
16 + test_encoding="UTF-8"
17 +fi
18
19 sample_utf8_part=$(printf "f\303\244ng")
20
@@ -18,7 +23,7 @@ commit_msg () {
23 # (translated with Google Translate),
24 # encoded in UTF-8, used as a commit log message below.
25 msg="initial. an${sample_utf8_part}lich\n"
21 - if test -n "$1"
26 + if test -n "$1" && test "$1" != "UTF-8"
27 then
28 printf "$msg" | iconv -f utf-8 -t "$1"
29 else
@@ -113,19 +118,19 @@ test_expect_success 'alias loop' '
118 test_must_fail git log --pretty=test-foo
119 '
120
116 -test_expect_success ICONV 'NUL separation' '
121 +test_expect_success 'NUL separation' '
122 printf "add bar\0$(commit_msg)" >expected &&
123 git log -z --pretty="format:%s" >actual &&
124 test_cmp expected actual
125 '
126
122 -test_expect_success ICONV 'NUL termination' '
127 +test_expect_success 'NUL termination' '
128 printf "add bar\0$(commit_msg)\0" >expected &&
129 git log -z --pretty="tformat:%s" >actual &&
130 test_cmp expected actual
131 '
132
128 -test_expect_success ICONV 'NUL separation with --stat' '
133 +test_expect_success 'NUL separation with --stat' '
134 stat0_part=$(git diff --stat HEAD^ HEAD) &&
135 stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
136 printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n" >expected &&
@@ -180,7 +185,7 @@ test_expect_success 'setup more commits' '
185 head4=$(git rev-parse --verify --short HEAD~3)
186 '
187
183 -test_expect_success ICONV 'left alignment formatting' '
188 +test_expect_success 'left alignment formatting' '
189 git log --pretty="tformat:%<(40)%s" >actual &&
190 qz_to_tab_space <<-EOF >expected &&
191 message two Z
@@ -202,7 +207,7 @@ test_expect_success ICONV 'left alignment formatting. i18n.logOutputEncoding' '
207 test_cmp expected actual
208 '
209
205 -test_expect_success ICONV 'left alignment formatting at the nth column' '
210 +test_expect_success 'left alignment formatting at the nth column' '
211 git log --pretty="tformat:%h %<|(40)%s" >actual &&
212 qz_to_tab_space <<-EOF >expected &&
213 $head1 message two Z
@@ -213,7 +218,7 @@ test_expect_success ICONV 'left alignment formatting at the nth column' '
218 test_cmp expected actual
219 '
220
216 -test_expect_success ICONV 'left alignment formatting at the nth column' '
221 +test_expect_success 'left alignment formatting at the nth column' '
222 COLUMNS=50 git log --pretty="tformat:%h %<|(-10)%s" >actual &&
223 qz_to_tab_space <<-EOF >expected &&
224 $head1 message two Z
@@ -235,7 +240,7 @@ test_expect_success ICONV 'left alignment formatting at the nth column. i18n.log
240 test_cmp expected actual
241 '
242
238 -test_expect_success ICONV 'left alignment formatting with no padding' '
243 +test_expect_success 'left alignment formatting with no padding' '
244 git log --pretty="tformat:%<(1)%s" >actual &&
245 cat <<-EOF >expected &&
246 message two
@@ -246,7 +251,7 @@ test_expect_success ICONV 'left alignment formatting with no padding' '
251 test_cmp expected actual
252 '
253
249 -test_expect_success 'left alignment formatting with no padding. i18n.logOutputEncoding' '
254 +test_expect_success ICONV 'left alignment formatting with no padding. i18n.logOutputEncoding' '
255 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(1)%s" >actual &&
256 cat <<-EOF | iconv -f utf-8 -t $test_encoding >expected &&
257 message two
@@ -257,7 +262,7 @@ test_expect_success 'left alignment formatting with no padding. i18n.logOutputEn
262 test_cmp expected actual
263 '
264
260 -test_expect_success ICONV 'left alignment formatting with trunc' '
265 +test_expect_success 'left alignment formatting with trunc' '
266 git log --pretty="tformat:%<(10,trunc)%s" >actual &&
267 qz_to_tab_space <<-\EOF >expected &&
268 message ..
@@ -279,7 +284,7 @@ test_expect_success ICONV 'left alignment formatting with trunc. i18n.logOutputE
284 test_cmp expected actual
285 '
286
282 -test_expect_success ICONV 'left alignment formatting with ltrunc' '
287 +test_expect_success 'left alignment formatting with ltrunc' '
288 git log --pretty="tformat:%<(10,ltrunc)%s" >actual &&
289 qz_to_tab_space <<-EOF >expected &&
290 ..sage two
@@ -301,7 +306,7 @@ test_expect_success ICONV 'left alignment formatting with ltrunc. i18n.logOutput
306 test_cmp expected actual
307 '
308
304 -test_expect_success ICONV 'left alignment formatting with mtrunc' '
309 +test_expect_success 'left alignment formatting with mtrunc' '
310 git log --pretty="tformat:%<(10,mtrunc)%s" >actual &&
311 qz_to_tab_space <<-\EOF >expected &&
312 mess.. two
@@ -323,7 +328,7 @@ test_expect_success ICONV 'left alignment formatting with mtrunc. i18n.logOutput
328 test_cmp expected actual
329 '
330
326 -test_expect_success ICONV 'right alignment formatting' '
331 +test_expect_success 'right alignment formatting' '
332 git log --pretty="tformat:%>(40)%s" >actual &&
333 qz_to_tab_space <<-EOF >expected &&
334 Z message two
@@ -345,7 +350,7 @@ test_expect_success ICONV 'right alignment formatting. i18n.logOutputEncoding' '
350 test_cmp expected actual
351 '
352
348 -test_expect_success ICONV 'right alignment formatting at the nth column' '
353 +test_expect_success 'right alignment formatting at the nth column' '
354 git log --pretty="tformat:%h %>|(40)%s" >actual &&
355 qz_to_tab_space <<-EOF >expected &&
356 $head1 message two
@@ -356,7 +361,7 @@ test_expect_success ICONV 'right alignment formatting at the nth column' '
361 test_cmp expected actual
362 '
363
359 -test_expect_success ICONV 'right alignment formatting at the nth column' '
364 +test_expect_success 'right alignment formatting at the nth column' '
365 COLUMNS=50 git log --pretty="tformat:%h %>|(-10)%s" >actual &&
366 qz_to_tab_space <<-EOF >expected &&
367 $head1 message two
@@ -391,7 +396,7 @@ test_expect_success ICONV 'right alignment formatting at the nth column with --g
396 test_cmp expected actual
397 '
398
394 -test_expect_success ICONV 'right alignment formatting with no padding' '
399 +test_expect_success 'right alignment formatting with no padding' '
400 git log --pretty="tformat:%>(1)%s" >actual &&
401 cat <<-EOF >expected &&
402 message two
@@ -402,7 +407,7 @@ test_expect_success ICONV 'right alignment formatting with no padding' '
407 test_cmp expected actual
408 '
409
405 -test_expect_success ICONV 'right alignment formatting with no padding and with --graph' '
410 +test_expect_success 'right alignment formatting with no padding and with --graph' '
411 git log --graph --pretty="tformat:%>(1)%s" >actual &&
412 cat <<-EOF >expected &&
413 * message two
@@ -424,7 +429,7 @@ test_expect_success ICONV 'right alignment formatting with no padding. i18n.logO
429 test_cmp expected actual
430 '
431
427 -test_expect_success ICONV 'center alignment formatting' '
432 +test_expect_success 'center alignment formatting' '
433 git log --pretty="tformat:%><(40)%s" >actual &&
434 qz_to_tab_space <<-EOF >expected &&
435 Z message two Z
@@ -445,7 +450,8 @@ test_expect_success ICONV 'center alignment formatting. i18n.logOutputEncoding'
450 EOF
451 test_cmp expected actual
452 '
448 -test_expect_success ICONV 'center alignment formatting at the nth column' '
453 +
454 +test_expect_success 'center alignment formatting at the nth column' '
455 git log --pretty="tformat:%h %><|(40)%s" >actual &&
456 qz_to_tab_space <<-EOF >expected &&
457 $head1 message two Z
@@ -456,7 +462,7 @@ test_expect_success ICONV 'center alignment formatting at the nth column' '
462 test_cmp expected actual
463 '
464
459 -test_expect_success ICONV 'center alignment formatting at the nth column' '
465 +test_expect_success 'center alignment formatting at the nth column' '
466 COLUMNS=70 git log --pretty="tformat:%h %><|(-30)%s" >actual &&
467 qz_to_tab_space <<-EOF >expected &&
468 $head1 message two Z
@@ -478,7 +484,7 @@ test_expect_success ICONV 'center alignment formatting at the nth column. i18n.l
484 test_cmp expected actual
485 '
486
481 -test_expect_success ICONV 'center alignment formatting with no padding' '
487 +test_expect_success 'center alignment formatting with no padding' '
488 git log --pretty="tformat:%><(1)%s" >actual &&
489 cat <<-EOF >expected &&
490 message two