a392f3d1d66757361ff9fc4e26f4125da5ab0a4f
   1#!/bin/sh
   2#
   3# Copyright (c) 2006 Junio C Hamano
   4#
   5
   6test_description='i18n settings and format-patch | am pipe'
   7
   8. ./test-lib.sh
   9
  10check_encoding () {
  11        # Make sure characters are not corrupted
  12        cnt="$1" header="$2" i=1 j=0 bad=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 || {
  24                        bad=1
  25                        break
  26                }
  27                j=$i
  28                i=$(($i+1))
  29        done
  30        (exit $bad)
  31}
  32
  33test_expect_success setup '
  34        git config i18n.commitencoding UTF-8 &&
  35
  36        # use UTF-8 in author and committer name to match the
  37        # i18n.commitencoding settings
  38        . "$TEST_DIRECTORY"/t3901-utf8.txt &&
  39
  40        test_tick &&
  41        echo "$GIT_AUTHOR_NAME" >mine &&
  42        git add mine &&
  43        git commit -s -m "Initial commit" &&
  44
  45        test_tick &&
  46        echo Hello world >mine &&
  47        git add mine &&
  48        git commit -s -m "Second on main" &&
  49
  50        # the first commit on the side branch is UTF-8
  51        test_tick &&
  52        git checkout -b side master^ &&
  53        echo Another file >yours &&
  54        git add yours &&
  55        git commit -s -m "Second on side" &&
  56
  57        if test_have_prereq !MINGW
  58        then
  59                # the second one on the side branch is ISO-8859-1
  60                git config i18n.commitencoding ISO8859-1 &&
  61                # use author and committer name in ISO-8859-1 to match it.
  62                . "$TEST_DIRECTORY"/t3901-8859-1.txt
  63        fi &&
  64        test_tick &&
  65        echo Yet another >theirs &&
  66        git add theirs &&
  67        git commit -s -m "Third on side" &&
  68
  69        # Back to default
  70        git config i18n.commitencoding UTF-8
  71'
  72
  73test_expect_success 'format-patch output (ISO-8859-1)' '
  74        git config i18n.logoutputencoding ISO8859-1 &&
  75
  76        git format-patch --stdout master..HEAD^ >out-l1 &&
  77        git format-patch --stdout HEAD^ >out-l2 &&
  78        grep "^Content-Type: text/plain; charset=ISO8859-1" out-l1 &&
  79        grep "^From: =?ISO8859-1?q?=C1=E9=ED=20=F3=FA?=" out-l1 &&
  80        grep "^Content-Type: text/plain; charset=ISO8859-1" out-l2 &&
  81        grep "^From: =?ISO8859-1?q?=C1=E9=ED=20=F3=FA?=" out-l2
  82'
  83
  84test_expect_success 'format-patch output (UTF-8)' '
  85        git config i18n.logoutputencoding UTF-8 &&
  86
  87        git format-patch --stdout master..HEAD^ >out-u1 &&
  88        git format-patch --stdout HEAD^ >out-u2 &&
  89        grep "^Content-Type: text/plain; charset=UTF-8" out-u1 &&
  90        grep "^From: =?UTF-8?q?=C3=81=C3=A9=C3=AD=20=C3=B3=C3=BA?=" out-u1 &&
  91        grep "^Content-Type: text/plain; charset=UTF-8" out-u2 &&
  92        grep "^From: =?UTF-8?q?=C3=81=C3=A9=C3=AD=20=C3=B3=C3=BA?=" out-u2
  93'
  94
  95test_expect_success 'rebase (U/U)' '
  96        # We want the result of rebase in UTF-8
  97        git config i18n.commitencoding UTF-8 &&
  98
  99        # The test is about logoutputencoding not affecting the
 100        # final outcome -- it is used internally to generate the
 101        # patch and the log.
 102
 103        git config i18n.logoutputencoding UTF-8 &&
 104
 105        # The result will be committed by GIT_COMMITTER_NAME --
 106        # we want UTF-8 encoded name.
 107        . "$TEST_DIRECTORY"/t3901-utf8.txt &&
 108        git checkout -b test &&
 109        git rebase master &&
 110
 111        check_encoding 2
 112'
 113
 114test_expect_success 'rebase (U/L)' '
 115        git config i18n.commitencoding UTF-8 &&
 116        git config i18n.logoutputencoding ISO8859-1 &&
 117        . "$TEST_DIRECTORY"/t3901-utf8.txt &&
 118
 119        git reset --hard side &&
 120        git rebase master &&
 121
 122        check_encoding 2
 123'
 124
 125test_expect_success !MINGW 'rebase (L/L)' '
 126        # In this test we want ISO-8859-1 encoded commits as the result
 127        git config i18n.commitencoding ISO8859-1 &&
 128        git config i18n.logoutputencoding ISO8859-1 &&
 129        . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
 130
 131        git reset --hard side &&
 132        git rebase master &&
 133
 134        check_encoding 2 8859
 135'
 136
 137test_expect_success !MINGW 'rebase (L/U)' '
 138        # This is pathological -- use UTF-8 as intermediate form
 139        # to get ISO-8859-1 results.
 140        git config i18n.commitencoding ISO8859-1 &&
 141        git config i18n.logoutputencoding UTF-8 &&
 142        . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
 143
 144        git reset --hard side &&
 145        git rebase master &&
 146
 147        check_encoding 2 8859
 148'
 149
 150test_expect_success 'cherry-pick(U/U)' '
 151        # Both the commitencoding and logoutputencoding is set to UTF-8.
 152
 153        git config i18n.commitencoding UTF-8 &&
 154        git config i18n.logoutputencoding UTF-8 &&
 155        . "$TEST_DIRECTORY"/t3901-utf8.txt &&
 156
 157        git reset --hard master &&
 158        git cherry-pick side^ &&
 159        git cherry-pick side &&
 160        git revert HEAD &&
 161
 162        check_encoding 3
 163'
 164
 165test_expect_success !MINGW 'cherry-pick(L/L)' '
 166        # Both the commitencoding and logoutputencoding is set to ISO-8859-1
 167
 168        git config i18n.commitencoding ISO8859-1 &&
 169        git config i18n.logoutputencoding ISO8859-1 &&
 170        . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
 171
 172        git reset --hard master &&
 173        git cherry-pick side^ &&
 174        git cherry-pick side &&
 175        git revert HEAD &&
 176
 177        check_encoding 3 8859
 178'
 179
 180test_expect_success 'cherry-pick(U/L)' '
 181        # Commitencoding is set to UTF-8 but logoutputencoding is ISO-8859-1
 182
 183        git config i18n.commitencoding UTF-8 &&
 184        git config i18n.logoutputencoding ISO8859-1 &&
 185        . "$TEST_DIRECTORY"/t3901-utf8.txt &&
 186
 187        git reset --hard master &&
 188        git cherry-pick side^ &&
 189        git cherry-pick side &&
 190        git revert HEAD &&
 191
 192        check_encoding 3
 193'
 194
 195test_expect_success !MINGW 'cherry-pick(L/U)' '
 196        # Again, the commitencoding is set to ISO-8859-1 but
 197        # logoutputencoding is set to UTF-8.
 198
 199        git config i18n.commitencoding ISO8859-1 &&
 200        git config i18n.logoutputencoding UTF-8 &&
 201        . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
 202
 203        git reset --hard master &&
 204        git cherry-pick side^ &&
 205        git cherry-pick side &&
 206        git revert HEAD &&
 207
 208        check_encoding 3 8859
 209'
 210
 211test_expect_success 'rebase --merge (U/U)' '
 212        git config i18n.commitencoding UTF-8 &&
 213        git config i18n.logoutputencoding UTF-8 &&
 214        . "$TEST_DIRECTORY"/t3901-utf8.txt &&
 215
 216        git reset --hard side &&
 217        git rebase --merge master &&
 218
 219        check_encoding 2
 220'
 221
 222test_expect_success 'rebase --merge (U/L)' '
 223        git config i18n.commitencoding UTF-8 &&
 224        git config i18n.logoutputencoding ISO8859-1 &&
 225        . "$TEST_DIRECTORY"/t3901-utf8.txt &&
 226
 227        git reset --hard side &&
 228        git rebase --merge master &&
 229
 230        check_encoding 2
 231'
 232
 233test_expect_success 'rebase --merge (L/L)' '
 234        # In this test we want ISO-8859-1 encoded commits as the result
 235        git config i18n.commitencoding ISO8859-1 &&
 236        git config i18n.logoutputencoding ISO8859-1 &&
 237        . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
 238
 239        git reset --hard side &&
 240        git rebase --merge master &&
 241
 242        check_encoding 2 8859
 243'
 244
 245test_expect_success 'rebase --merge (L/U)' '
 246        # This is pathological -- use UTF-8 as intermediate form
 247        # to get ISO-8859-1 results.
 248        git config i18n.commitencoding ISO8859-1 &&
 249        git config i18n.logoutputencoding UTF-8 &&
 250        . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
 251
 252        git reset --hard side &&
 253        git rebase --merge master &&
 254
 255        check_encoding 2 8859
 256'
 257
 258test_done