t / t3901-i18n-patch.shon commit Merge branch 'maint' (5c283eb)
   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 ISO-8859-1" ;;
  21                *)
  22                        ! grep "^encoding ISO-8859-1" ;;
  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        # the second one on the side branch is ISO-8859-1
  58        git config i18n.commitencoding ISO-8859-1 &&
  59        # use author and committer name in ISO-8859-1 to match it.
  60        . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
  61        test_tick &&
  62        echo Yet another >theirs &&
  63        git add theirs &&
  64        git commit -s -m "Third on side" &&
  65
  66        # Back to default
  67        git config i18n.commitencoding UTF-8
  68'
  69
  70test_expect_success 'format-patch output (ISO-8859-1)' '
  71        git config i18n.logoutputencoding ISO-8859-1 &&
  72
  73        git format-patch --stdout master..HEAD^ >out-l1 &&
  74        git format-patch --stdout HEAD^ >out-l2 &&
  75        grep "^Content-Type: text/plain; charset=ISO-8859-1" out-l1 &&
  76        grep "^From: =?ISO-8859-1?q?=C1=E9=ED=20=F3=FA?=" out-l1 &&
  77        grep "^Content-Type: text/plain; charset=ISO-8859-1" out-l2 &&
  78        grep "^From: =?ISO-8859-1?q?=C1=E9=ED=20=F3=FA?=" out-l2
  79'
  80
  81test_expect_success 'format-patch output (UTF-8)' '
  82        git config i18n.logoutputencoding UTF-8 &&
  83
  84        git format-patch --stdout master..HEAD^ >out-u1 &&
  85        git format-patch --stdout HEAD^ >out-u2 &&
  86        grep "^Content-Type: text/plain; charset=UTF-8" out-u1 &&
  87        grep "^From: =?UTF-8?q?=C3=81=C3=A9=C3=AD=20=C3=B3=C3=BA?=" out-u1 &&
  88        grep "^Content-Type: text/plain; charset=UTF-8" out-u2 &&
  89        grep "^From: =?UTF-8?q?=C3=81=C3=A9=C3=AD=20=C3=B3=C3=BA?=" out-u2
  90'
  91
  92test_expect_success 'rebase (U/U)' '
  93        # We want the result of rebase in UTF-8
  94        git config i18n.commitencoding UTF-8 &&
  95
  96        # The test is about logoutputencoding not affecting the
  97        # final outcome -- it is used internally to generate the
  98        # patch and the log.
  99
 100        git config i18n.logoutputencoding UTF-8 &&
 101
 102        # The result will be committed by GIT_COMMITTER_NAME --
 103        # we want UTF-8 encoded name.
 104        . "$TEST_DIRECTORY"/t3901-utf8.txt &&
 105        git checkout -b test &&
 106        git rebase master &&
 107
 108        check_encoding 2
 109'
 110
 111test_expect_success 'rebase (U/L)' '
 112        git config i18n.commitencoding UTF-8 &&
 113        git config i18n.logoutputencoding ISO-8859-1 &&
 114        . "$TEST_DIRECTORY"/t3901-utf8.txt &&
 115
 116        git reset --hard side &&
 117        git rebase master &&
 118
 119        check_encoding 2
 120'
 121
 122test_expect_success 'rebase (L/L)' '
 123        # In this test we want ISO-8859-1 encoded commits as the result
 124        git config i18n.commitencoding ISO-8859-1 &&
 125        git config i18n.logoutputencoding ISO-8859-1 &&
 126        . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
 127
 128        git reset --hard side &&
 129        git rebase master &&
 130
 131        check_encoding 2 8859
 132'
 133
 134test_expect_success 'rebase (L/U)' '
 135        # This is pathological -- use UTF-8 as intermediate form
 136        # to get ISO-8859-1 results.
 137        git config i18n.commitencoding ISO-8859-1 &&
 138        git config i18n.logoutputencoding UTF-8 &&
 139        . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
 140
 141        git reset --hard side &&
 142        git rebase master &&
 143
 144        check_encoding 2 8859
 145'
 146
 147test_expect_success 'cherry-pick(U/U)' '
 148        # Both the commitencoding and logoutputencoding is set to UTF-8.
 149
 150        git config i18n.commitencoding UTF-8 &&
 151        git config i18n.logoutputencoding UTF-8 &&
 152        . "$TEST_DIRECTORY"/t3901-utf8.txt &&
 153
 154        git reset --hard master &&
 155        git cherry-pick side^ &&
 156        git cherry-pick side &&
 157        git revert HEAD &&
 158
 159        check_encoding 3
 160'
 161
 162test_expect_success 'cherry-pick(L/L)' '
 163        # Both the commitencoding and logoutputencoding is set to ISO-8859-1
 164
 165        git config i18n.commitencoding ISO-8859-1 &&
 166        git config i18n.logoutputencoding ISO-8859-1 &&
 167        . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
 168
 169        git reset --hard master &&
 170        git cherry-pick side^ &&
 171        git cherry-pick side &&
 172        git revert HEAD &&
 173
 174        check_encoding 3 8859
 175'
 176
 177test_expect_success 'cherry-pick(U/L)' '
 178        # Commitencoding is set to UTF-8 but logoutputencoding is ISO-8859-1
 179
 180        git config i18n.commitencoding UTF-8 &&
 181        git config i18n.logoutputencoding ISO-8859-1 &&
 182        . "$TEST_DIRECTORY"/t3901-utf8.txt &&
 183
 184        git reset --hard master &&
 185        git cherry-pick side^ &&
 186        git cherry-pick side &&
 187        git revert HEAD &&
 188
 189        check_encoding 3
 190'
 191
 192test_expect_success 'cherry-pick(L/U)' '
 193        # Again, the commitencoding is set to ISO-8859-1 but
 194        # logoutputencoding is set to UTF-8.
 195
 196        git config i18n.commitencoding ISO-8859-1 &&
 197        git config i18n.logoutputencoding UTF-8 &&
 198        . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
 199
 200        git reset --hard master &&
 201        git cherry-pick side^ &&
 202        git cherry-pick side &&
 203        git revert HEAD &&
 204
 205        check_encoding 3 8859
 206'
 207
 208test_expect_success 'rebase --merge (U/U)' '
 209        git config i18n.commitencoding UTF-8 &&
 210        git config i18n.logoutputencoding UTF-8 &&
 211        . "$TEST_DIRECTORY"/t3901-utf8.txt &&
 212
 213        git reset --hard side &&
 214        git rebase --merge master &&
 215
 216        check_encoding 2
 217'
 218
 219test_expect_success 'rebase --merge (U/L)' '
 220        git config i18n.commitencoding UTF-8 &&
 221        git config i18n.logoutputencoding ISO-8859-1 &&
 222        . "$TEST_DIRECTORY"/t3901-utf8.txt &&
 223
 224        git reset --hard side &&
 225        git rebase --merge master &&
 226
 227        check_encoding 2
 228'
 229
 230test_expect_success 'rebase --merge (L/L)' '
 231        # In this test we want ISO-8859-1 encoded commits as the result
 232        git config i18n.commitencoding ISO-8859-1 &&
 233        git config i18n.logoutputencoding ISO-8859-1 &&
 234        . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
 235
 236        git reset --hard side &&
 237        git rebase --merge master &&
 238
 239        check_encoding 2 8859
 240'
 241
 242test_expect_success 'rebase --merge (L/U)' '
 243        # This is pathological -- use UTF-8 as intermediate form
 244        # to get ISO-8859-1 results.
 245        git config i18n.commitencoding ISO-8859-1 &&
 246        git config i18n.logoutputencoding UTF-8 &&
 247        . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
 248
 249        git reset --hard side &&
 250        git rebase --merge master &&
 251
 252        check_encoding 2 8859
 253'
 254
 255test_done