1#!/bin/sh
   2#
   3# Copyright (c) 2006 Junio C Hamano
   4#
   5test_description='i18n settings and format-patch | am pipe'
   7. ./test-lib.sh
   9check_encoding () {
  11        # Make sure characters are not corrupted
  12        cnt="$1" header="$2" i=1 j=0
  13        while test "$i" -le $cnt
  14        do
  15                git format-patch --encoding=UTF-8 --stdout HEAD~$i..HEAD~$j |
  16                grep "^From: =?UTF-8?q?=C3=81=C3=A9=C3=AD=20=C3=B3=C3=BA?=" &&
  17                git cat-file commit HEAD~$j |
  18                case "$header" in
  19                8859)
  20                        grep "^encoding ISO8859-1" ;;
  21                *)
  22                        grep "^encoding ISO8859-1"; test "$?" != 0 ;;
  23                esac || return 1
  24                j=$i
  25                i=$(($i+1))
  26        done
  27}
  28test_expect_success setup '
  30        git config i18n.commitencoding UTF-8 &&
  31        # use UTF-8 in author and committer name to match the
  33        # i18n.commitencoding settings
  34        . "$TEST_DIRECTORY"/t3901-utf8.txt &&
  35        test_tick &&
  37        echo "$GIT_AUTHOR_NAME" >mine &&
  38        git add mine &&
  39        git commit -s -m "Initial commit" &&
  40        test_tick &&
  42        echo Hello world >mine &&
  43        git add mine &&
  44        git commit -s -m "Second on main" &&
  45        # the first commit on the side branch is UTF-8
  47        test_tick &&
  48        git checkout -b side master^ &&
  49        echo Another file >yours &&
  50        git add yours &&
  51        git commit -s -m "Second on side" &&
  52        if test_have_prereq !MINGW
  54        then
  55                # the second one on the side branch is ISO-8859-1
  56                git config i18n.commitencoding ISO8859-1 &&
  57                # use author and committer name in ISO-8859-1 to match it.
  58                . "$TEST_DIRECTORY"/t3901-8859-1.txt
  59        fi &&
  60        test_tick &&
  61        echo Yet another >theirs &&
  62        git add theirs &&
  63        git commit -s -m "Third on side" &&
  64        # Back to default
  66        git config i18n.commitencoding UTF-8
  67'
  68test_expect_success 'format-patch output (ISO-8859-1)' '
  70        git config i18n.logoutputencoding ISO8859-1 &&
  71        git format-patch --stdout master..HEAD^ >out-l1 &&
  73        git format-patch --stdout HEAD^ >out-l2 &&
  74        grep "^Content-Type: text/plain; charset=ISO8859-1" out-l1 &&
  75        grep "^From: =?ISO8859-1?q?=C1=E9=ED=20=F3=FA?=" out-l1 &&
  76        grep "^Content-Type: text/plain; charset=ISO8859-1" out-l2 &&
  77        grep "^From: =?ISO8859-1?q?=C1=E9=ED=20=F3=FA?=" out-l2
  78'
  79test_expect_success 'format-patch output (UTF-8)' '
  81        git config i18n.logoutputencoding UTF-8 &&
  82        git format-patch --stdout master..HEAD^ >out-u1 &&
  84        git format-patch --stdout HEAD^ >out-u2 &&
  85        grep "^Content-Type: text/plain; charset=UTF-8" out-u1 &&
  86        grep "^From: =?UTF-8?q?=C3=81=C3=A9=C3=AD=20=C3=B3=C3=BA?=" out-u1 &&
  87        grep "^Content-Type: text/plain; charset=UTF-8" out-u2 &&
  88        grep "^From: =?UTF-8?q?=C3=81=C3=A9=C3=AD=20=C3=B3=C3=BA?=" out-u2
  89'
  90test_expect_success 'rebase (U/U)' '
  92        # We want the result of rebase in UTF-8
  93        git config i18n.commitencoding UTF-8 &&
  94        # The test is about logoutputencoding not affecting the
  96        # final outcome -- it is used internally to generate the
  97        # patch and the log.
  98        git config i18n.logoutputencoding UTF-8 &&
 100        # The result will be committed by GIT_COMMITTER_NAME --
 102        # we want UTF-8 encoded name.
 103        . "$TEST_DIRECTORY"/t3901-utf8.txt &&
 104        git checkout -b test &&
 105        git rebase master &&
 106        check_encoding 2
 108'
 109test_expect_success 'rebase (U/L)' '
 111        git config i18n.commitencoding UTF-8 &&
 112        git config i18n.logoutputencoding ISO8859-1 &&
 113        . "$TEST_DIRECTORY"/t3901-utf8.txt &&
 114        git reset --hard side &&
 116        git rebase master &&
 117        check_encoding 2
 119'
 120test_expect_success !MINGW 'rebase (L/L)' '
 122        # In this test we want ISO-8859-1 encoded commits as the result
 123        git config i18n.commitencoding ISO8859-1 &&
 124        git config i18n.logoutputencoding ISO8859-1 &&
 125        . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
 126        git reset --hard side &&
 128        git rebase master &&
 129        check_encoding 2 8859
 131'
 132test_expect_success !MINGW 'rebase (L/U)' '
 134        # This is pathological -- use UTF-8 as intermediate form
 135        # to get ISO-8859-1 results.
 136        git config i18n.commitencoding ISO8859-1 &&
 137        git config i18n.logoutputencoding UTF-8 &&
 138        . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
 139        git reset --hard side &&
 141        git rebase master &&
 142        check_encoding 2 8859
 144'
 145test_expect_success 'cherry-pick(U/U)' '
 147        # Both the commitencoding and logoutputencoding is set to UTF-8.
 148        git config i18n.commitencoding UTF-8 &&
 150        git config i18n.logoutputencoding UTF-8 &&
 151        . "$TEST_DIRECTORY"/t3901-utf8.txt &&
 152        git reset --hard master &&
 154        git cherry-pick side^ &&
 155        git cherry-pick side &&
 156        git revert HEAD &&
 157        check_encoding 3
 159'
 160test_expect_success !MINGW 'cherry-pick(L/L)' '
 162        # Both the commitencoding and logoutputencoding is set to ISO-8859-1
 163        git config i18n.commitencoding ISO8859-1 &&
 165        git config i18n.logoutputencoding ISO8859-1 &&
 166        . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
 167        git reset --hard master &&
 169        git cherry-pick side^ &&
 170        git cherry-pick side &&
 171        git revert HEAD &&
 172        check_encoding 3 8859
 174'
 175test_expect_success 'cherry-pick(U/L)' '
 177        # Commitencoding is set to UTF-8 but logoutputencoding is ISO-8859-1
 178        git config i18n.commitencoding UTF-8 &&
 180        git config i18n.logoutputencoding ISO8859-1 &&
 181        . "$TEST_DIRECTORY"/t3901-utf8.txt &&
 182        git reset --hard master &&
 184        git cherry-pick side^ &&
 185        git cherry-pick side &&
 186        git revert HEAD &&
 187        check_encoding 3
 189'
 190test_expect_success !MINGW 'cherry-pick(L/U)' '
 192        # Again, the commitencoding is set to ISO-8859-1 but
 193        # logoutputencoding is set to UTF-8.
 194        git config i18n.commitencoding ISO8859-1 &&
 196        git config i18n.logoutputencoding UTF-8 &&
 197        . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
 198        git reset --hard master &&
 200        git cherry-pick side^ &&
 201        git cherry-pick side &&
 202        git revert HEAD &&
 203        check_encoding 3 8859
 205'
 206test_expect_success 'rebase --merge (U/U)' '
 208        git config i18n.commitencoding UTF-8 &&
 209        git config i18n.logoutputencoding UTF-8 &&
 210        . "$TEST_DIRECTORY"/t3901-utf8.txt &&
 211        git reset --hard side &&
 213        git rebase --merge master &&
 214        check_encoding 2
 216'
 217test_expect_success 'rebase --merge (U/L)' '
 219        git config i18n.commitencoding UTF-8 &&
 220        git config i18n.logoutputencoding ISO8859-1 &&
 221        . "$TEST_DIRECTORY"/t3901-utf8.txt &&
 222        git reset --hard side &&
 224        git rebase --merge master &&
 225        check_encoding 2
 227'
 228test_expect_success 'rebase --merge (L/L)' '
 230        # In this test we want ISO-8859-1 encoded commits as the result
 231        git config i18n.commitencoding ISO8859-1 &&
 232        git config i18n.logoutputencoding ISO8859-1 &&
 233        . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
 234        git reset --hard side &&
 236        git rebase --merge master &&
 237        check_encoding 2 8859
 239'
 240test_expect_success 'rebase --merge (L/U)' '
 242        # This is pathological -- use UTF-8 as intermediate form
 243        # to get ISO-8859-1 results.
 244        git config i18n.commitencoding ISO8859-1 &&
 245        git config i18n.logoutputencoding UTF-8 &&
 246        . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
 247        git reset --hard side &&
 249        git rebase --merge master &&
 250        check_encoding 2 8859
 252'
 253test_expect_success 'am (U/U)' '
 255        # Apply UTF-8 patches with UTF-8 commitencoding
 256        git config i18n.commitencoding UTF-8 &&
 257        . "$TEST_DIRECTORY"/t3901-utf8.txt &&
 258        git reset --hard master &&
 260        git am out-u1 out-u2 &&
 261        check_encoding 2
 263'
 264test_expect_success !MINGW 'am (L/L)' '
 266        # Apply ISO-8859-1 patches with ISO-8859-1 commitencoding
 267        git config i18n.commitencoding ISO8859-1 &&
 268        . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
 269        git reset --hard master &&
 271        git am out-l1 out-l2 &&
 272        check_encoding 2 8859
 274'
 275test_expect_success 'am (U/L)' '
 277        # Apply ISO-8859-1 patches with UTF-8 commitencoding
 278        git config i18n.commitencoding UTF-8 &&
 279        . "$TEST_DIRECTORY"/t3901-utf8.txt &&
 280        git reset --hard master &&
 281        # am specifies --utf8 by default.
 283        git am out-l1 out-l2 &&
 284        check_encoding 2
 286'
 287test_expect_success 'am --no-utf8 (U/L)' '
 289        # Apply ISO-8859-1 patches with UTF-8 commitencoding
 290        git config i18n.commitencoding UTF-8 &&
 291        . "$TEST_DIRECTORY"/t3901-utf8.txt &&
 292        git reset --hard master &&
 294        git am --no-utf8 out-l1 out-l2 2>err &&
 295        # commit-tree will warn that the commit message does not contain valid UTF-8
 297        # as mailinfo did not convert it
 298        grep "did not conform" err &&
 299        check_encoding 2
 301'
 302test_expect_success !MINGW 'am (L/U)' '
 304        # Apply UTF-8 patches with ISO-8859-1 commitencoding
 305        git config i18n.commitencoding ISO8859-1 &&
 306        . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
 307        git reset --hard master &&
 309        # mailinfo will re-code the commit message to the charset specified by
 310        # i18n.commitencoding
 311        git am out-u1 out-u2 &&
 312        check_encoding 2 8859
 314'
 315test_done