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 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}
  32test_expect_success setup '
  34        git config i18n.commitencoding UTF-8 &&
  35        # use UTF-8 in author and committer name to match the
  37        # i18n.commitencoding settings
  38        . "$TEST_DIRECTORY"/t3901-utf8.txt &&
  39        test_tick &&
  41        echo "$GIT_AUTHOR_NAME" >mine &&
  42        git add mine &&
  43        git commit -s -m "Initial commit" &&
  44        test_tick &&
  46        echo Hello world >mine &&
  47        git add mine &&
  48        git commit -s -m "Second on main" &&
  49        # 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        # 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        # Back to default
  67        git config i18n.commitencoding UTF-8
  68'
  69test_expect_success 'format-patch output (ISO-8859-1)' '
  71        git config i18n.logoutputencoding ISO-8859-1 &&
  72        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'
  80test_expect_success 'format-patch output (UTF-8)' '
  82        git config i18n.logoutputencoding UTF-8 &&
  83        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'
  91test_expect_success 'rebase (U/U)' '
  93        # We want the result of rebase in UTF-8
  94        git config i18n.commitencoding UTF-8 &&
  95        # The test is about logoutputencoding not affecting the
  97        # final outcome -- it is used internally to generate the
  98        # patch and the log.
  99        git config i18n.logoutputencoding UTF-8 &&
 101        # 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        check_encoding 2
 109'
 110test_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        git reset --hard side &&
 117        git rebase master &&
 118        check_encoding 2
 120'
 121test_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        git reset --hard side &&
 129        git rebase master &&
 130        check_encoding 2 8859
 132'
 133test_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        git reset --hard side &&
 142        git rebase master &&
 143        check_encoding 2 8859
 145'
 146test_expect_success 'cherry-pick(U/U)' '
 148        # Both the commitencoding and logoutputencoding is set to UTF-8.
 149        git config i18n.commitencoding UTF-8 &&
 151        git config i18n.logoutputencoding UTF-8 &&
 152        . "$TEST_DIRECTORY"/t3901-utf8.txt &&
 153        git reset --hard master &&
 155        git cherry-pick side^ &&
 156        git cherry-pick side &&
 157        git revert HEAD &&
 158        check_encoding 3
 160'
 161test_expect_success 'cherry-pick(L/L)' '
 163        # Both the commitencoding and logoutputencoding is set to ISO-8859-1
 164        git config i18n.commitencoding ISO-8859-1 &&
 166        git config i18n.logoutputencoding ISO-8859-1 &&
 167        . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
 168        git reset --hard master &&
 170        git cherry-pick side^ &&
 171        git cherry-pick side &&
 172        git revert HEAD &&
 173        check_encoding 3 8859
 175'
 176test_expect_success 'cherry-pick(U/L)' '
 178        # Commitencoding is set to UTF-8 but logoutputencoding is ISO-8859-1
 179        git config i18n.commitencoding UTF-8 &&
 181        git config i18n.logoutputencoding ISO-8859-1 &&
 182        . "$TEST_DIRECTORY"/t3901-utf8.txt &&
 183        git reset --hard master &&
 185        git cherry-pick side^ &&
 186        git cherry-pick side &&
 187        git revert HEAD &&
 188        check_encoding 3
 190'
 191test_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        git config i18n.commitencoding ISO-8859-1 &&
 197        git config i18n.logoutputencoding UTF-8 &&
 198        . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
 199        git reset --hard master &&
 201        git cherry-pick side^ &&
 202        git cherry-pick side &&
 203        git revert HEAD &&
 204        check_encoding 3 8859
 206'
 207test_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        git reset --hard side &&
 214        git rebase --merge master &&
 215        check_encoding 2
 217'
 218test_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        git reset --hard side &&
 225        git rebase --merge master &&
 226        check_encoding 2
 228'
 229test_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        git reset --hard side &&
 237        git rebase --merge master &&
 238        check_encoding 2 8859
 240'
 241test_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        git reset --hard side &&
 250        git rebase --merge master &&
 251        check_encoding 2 8859
 253'
 254test_done