]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t40xx: don't use iconv(1) without ICONV prereq
authorPatrick Steinhardt <ps@pks.im>
Fri, 20 Feb 2026 08:26:00 +0000 (09:26 +0100)
committerJunio C Hamano <gitster@pobox.com>
Fri, 20 Feb 2026 15:52:27 +0000 (07:52 -0800)
We've got a couple of tests related to diffs in t40xx that use the
iconv(1) executable to convert the encoding of a commit message. All of
these tests are prepared to handle a missing ICONV prereq, in which case
they will simply use UTF-8 encoding.

But even if the ICONV prerequisite has failed we try to use the iconv(1)
executable, even though it's not safe to assume that the executable
exists in that case. And besides that, it's also unnecessary to use
iconv(1) in the first place, as we would only use it to convert from
UTF-8 to UTF-8, which should be equivalent to a no-op.

Fix the issue and skip the call to iconv(1) in case the prerequisite is
not set. This makes tests work on systems that don't have iconv at all.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t4041-diff-submodule-option.sh
t/t4059-diff-submodule-not-initialized.sh
t/t4060-diff-submodule-option-diff-format.sh

index 4d4aa1650fe84a1db88ea9a77958aa7a2be3ca02..4dd4954260cfc1dd5c326ab817f9abab7dbfbebc 100755 (executable)
@@ -37,8 +37,12 @@ add_file () {
                        test_tick &&
                        # "git commit -m" would break MinGW, as Windows refuse to pass
                        # $test_encoding encoded parameter to git.
-                       echo "Add $name ($added $name)" | iconv -f utf-8 -t $test_encoding |
-                       git -c "i18n.commitEncoding=$test_encoding" commit -F -
+                       message="Add $name ($added $name)" &&
+                       if test_have_prereq ICONV
+                       then
+                               message=$(echo "$message" | iconv -f utf-8 -t $test_encoding)
+                       fi &&
+                       echo "$message" | git -c "i18n.commitEncoding=$test_encoding" commit -F -
                done >/dev/null &&
                git rev-parse --short --verify HEAD
        )
index 0fe81056d5be685a53f3c218d733765678e1264c..bb902ce94df6f6b82d039dc561cd6bdcf4bc6850 100755 (executable)
@@ -35,8 +35,12 @@ add_file () {
                        test_tick &&
                        # "git commit -m" would break MinGW, as Windows refuse to pass
                        # $test_encoding encoded parameter to git.
-                       echo "Add $name ($added $name)" | iconv -f utf-8 -t $test_encoding |
-                       git -c "i18n.commitEncoding=$test_encoding" commit -F -
+                       message="Add $name ($added $name)" &&
+                       if test_have_prereq ICONV
+                       then
+                               message=$(echo "$message" | iconv -f utf-8 -t $test_encoding)
+                       fi &&
+                       echo "$message" | git -c "i18n.commitEncoding=$test_encoding" commit -F -
                done >/dev/null &&
                git rev-parse --short --verify HEAD
        )
index dbfeb7470bcfadd37c5f9d67b5f702b1b2babb50..d8f92132550681fcaf35c07522df56013daadf24 100755 (executable)
@@ -35,8 +35,12 @@ add_file () {
                        test_tick &&
                        # "git commit -m" would break MinGW, as Windows refuse to pass
                        # $test_encoding encoded parameter to git.
-                       echo "Add $name ($added $name)" | iconv -f utf-8 -t $test_encoding |
-                       git -c "i18n.commitEncoding=$test_encoding" commit -F -
+                       message="Add $name ($added $name)" &&
+                       if test_have_prereq ICONV
+                       then
+                               message=$(echo "$message" | iconv -f utf-8 -t $test_encoding)
+                       fi &&
+                       echo "$message" | git -c "i18n.commitEncoding=$test_encoding" commit -F -
                done >/dev/null &&
                git rev-parse --short --verify HEAD
        )