t / t3901-i18n-patch.shon commit userdiff: add a builtin pattern for dts files (3c81760)
   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
  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}
  28
  29test_expect_success setup '
  30        git config i18n.commitencoding UTF-8 &&
  31
  32        # use UTF-8 in author and committer name to match the
  33        # i18n.commitencoding settings
  34        . "$TEST_DIRECTORY"/t3901/utf8.txt &&
  35
  36        test_tick &&
  37        echo "$GIT_AUTHOR_NAME" >mine &&
  38        git add mine &&
  39        git commit -s -m "Initial commit" &&
  40
  41        test_tick &&
  42        echo Hello world >mine &&
  43        git add mine &&
  44        git commit -s -m "Second on main" &&
  45
  46        # 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
  53        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
  65        # Back to default
  66        git config i18n.commitencoding UTF-8
  67'
  68
  69test_expect_success 'format-patch output (ISO-8859-1)' '
  70        git config i18n.logoutputencoding ISO8859-1 &&
  71
  72        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'
  79
  80test_expect_success 'format-patch output (UTF-8)' '
  81        git config i18n.logoutputencoding UTF-8 &&
  82
  83        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'
  90
  91test_expect_success 'rebase (U/U)' '
  92        # We want the result of rebase in UTF-8
  93        git config i18n.commitencoding UTF-8 &&
  94
  95        # The test is about logoutputencoding not affecting the
  96        # final outcome -- it is used internally to generate the
  97        # patch and the log.
  98
  99        git config i18n.logoutputencoding UTF-8 &&
 100
 101        # 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
 107        check_encoding 2
 108'
 109
 110test_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
 115        git reset --hard side &&
 116        git rebase master &&
 117
 118        check_encoding 2
 119'
 120
 121test_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
 127        git reset --hard side &&
 128        git rebase master &&
 129
 130        check_encoding 2 8859
 131'
 132
 133test_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
 140        git reset --hard side &&
 141        git rebase master &&
 142
 143        check_encoding 2 8859
 144'
 145
 146test_expect_success 'cherry-pick(U/U)' '
 147        # Both the commitencoding and logoutputencoding is set to UTF-8.
 148
 149        git config i18n.commitencoding UTF-8 &&
 150        git config i18n.logoutputencoding UTF-8 &&
 151        . "$TEST_DIRECTORY"/t3901/utf8.txt &&
 152
 153        git reset --hard master &&
 154        git cherry-pick side^ &&
 155        git cherry-pick side &&
 156        git revert HEAD &&
 157
 158        check_encoding 3
 159'
 160
 161test_expect_success !MINGW 'cherry-pick(L/L)' '
 162        # Both the commitencoding and logoutputencoding is set to ISO-8859-1
 163
 164        git config i18n.commitencoding ISO8859-1 &&
 165        git config i18n.logoutputencoding ISO8859-1 &&
 166        . "$TEST_DIRECTORY"/t3901/8859-1.txt &&
 167
 168        git reset --hard master &&
 169        git cherry-pick side^ &&
 170        git cherry-pick side &&
 171        git revert HEAD &&
 172
 173        check_encoding 3 8859
 174'
 175
 176test_expect_success 'cherry-pick(U/L)' '
 177        # Commitencoding is set to UTF-8 but logoutputencoding is ISO-8859-1
 178
 179        git config i18n.commitencoding UTF-8 &&
 180        git config i18n.logoutputencoding ISO8859-1 &&
 181        . "$TEST_DIRECTORY"/t3901/utf8.txt &&
 182
 183        git reset --hard master &&
 184        git cherry-pick side^ &&
 185        git cherry-pick side &&
 186        git revert HEAD &&
 187
 188        check_encoding 3
 189'
 190
 191test_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
 195        git config i18n.commitencoding ISO8859-1 &&
 196        git config i18n.logoutputencoding UTF-8 &&
 197        . "$TEST_DIRECTORY"/t3901/8859-1.txt &&
 198
 199        git reset --hard master &&
 200        git cherry-pick side^ &&
 201        git cherry-pick side &&
 202        git revert HEAD &&
 203
 204        check_encoding 3 8859
 205'
 206
 207test_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
 212        git reset --hard side &&
 213        git rebase --merge master &&
 214
 215        check_encoding 2
 216'
 217
 218test_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
 223        git reset --hard side &&
 224        git rebase --merge master &&
 225
 226        check_encoding 2
 227'
 228
 229test_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
 235        git reset --hard side &&
 236        git rebase --merge master &&
 237
 238        check_encoding 2 8859
 239'
 240
 241test_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
 248        git reset --hard side &&
 249        git rebase --merge master &&
 250
 251        check_encoding 2 8859
 252'
 253
 254test_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
 259        git reset --hard master &&
 260        git am out-u1 out-u2 &&
 261
 262        check_encoding 2
 263'
 264
 265test_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
 270        git reset --hard master &&
 271        git am out-l1 out-l2 &&
 272
 273        check_encoding 2 8859
 274'
 275
 276test_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
 282        # am specifies --utf8 by default.
 283        git am out-l1 out-l2 &&
 284
 285        check_encoding 2
 286'
 287
 288test_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
 293        git reset --hard master &&
 294        git am --no-utf8 out-l1 out-l2 2>err &&
 295
 296        # commit-tree will warn that the commit message does not contain valid UTF-8
 297        # as mailinfo did not convert it
 298        test_i18ngrep "did not conform" err &&
 299
 300        check_encoding 2
 301'
 302
 303test_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
 308        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
 313        check_encoding 2 8859
 314'
 315
 316test_done