(command.CommandList
  children: [
    (command.ShAssignment
      pairs: [
        (assign_pair
          lhs: (sh_lhs_expr.Name name:test_description)
          op: assign_op.Equal
          rhs: {(SQ <'i18n settings and format-patch | am pipe'>)}
          spids: [13]
        )
      ]
    )
    (C {<.>} {<'./test-lib.sh'>})
    (command.ShFunction
      name: check_encoding
      body: 
        (BraceGroup
          children: [
            (command.ShAssignment
              pairs: [
                (assign_pair
                  lhs: (sh_lhs_expr.Name name:cnt)
                  op: assign_op.Equal
                  rhs: {(DQ ($ Id.VSub_Number '$1'))}
                  spids: [36]
                )
                (assign_pair
                  lhs: (sh_lhs_expr.Name name:header)
                  op: assign_op.Equal
                  rhs: {(DQ ($ Id.VSub_Number '$2'))}
                  spids: [41]
                )
                (assign_pair
                  lhs: (sh_lhs_expr.Name name:i)
                  op: assign_op.Equal
                  rhs: {<1>}
                  spids: [46]
                )
                (assign_pair
                  lhs: (sh_lhs_expr.Name name:j)
                  op: assign_op.Equal
                  rhs: {<0>}
                  spids: [49]
                )
              ]
            )
            (command.WhileUntil
              keyword: <Id.KW_While while>
              cond: 
                (condition.Shell
                  commands: [
                    (C {<test>} {(DQ ($ Id.VSub_DollarName '$i'))} {<-le>} 
                      {($ Id.VSub_DollarName '$cnt')}
                    )
                  ]
                )
              body: 
                (command.DoGroup
                  children: [
                    (command.AndOr
                      ops: [Id.Op_DAmp Id.Op_DPipe]
                      children: [
                        (command.Pipeline
                          children: [
                            (C {<git>} {<format-patch>} {<--encoding> <Id.Lit_Equals '='> <UTF-8>} 
                              {<--stdout>} 
                              {<HEAD> <Id.Lit_TildeLike '~'> ($ Id.VSub_DollarName '$i') <..HEAD> 
                                <Id.Lit_TildeLike '~'> ($ Id.VSub_DollarName '$j')
                              }
                            )
                            (C {<grep>} {(DQ <'^From: =?UTF-8?q?=C3=81=C3=A9=C3=AD=20=C3=B3=C3=BA?='>)})
                          ]
                          negated: F
                        )
                        (command.Pipeline
                          children: [
                            (C {<git>} {<cat-file>} {<commit>} 
                              {<HEAD> <Id.Lit_TildeLike '~'> ($ Id.VSub_DollarName '$j')}
                            )
                            (command.Case
                              to_match: {(DQ ($ Id.VSub_DollarName '$header'))}
                              arms: [
                                (case_arm
                                  pat_list: [{<8859>}]
                                  action: [(C {<grep>} {(DQ <'^encoding ISO8859-1'>)})]
                                  spids: [120 121 130 -1]
                                )
                                (case_arm
                                  pat_list: [{<Id.Lit_Star '*'>}]
                                  action: [
                                    (command.Sentence
                                      child: (C {<grep>} {(DQ <'^encoding ISO8859-1'>)})
                                      terminator: <Id.Op_Semi _>
                                    )
                                    (C {<test>} {(DQ ($ Id.VSub_QMark '$?'))} 
                                      {<Id.KW_Bang '!'> <Id.Lit_Equals '='>} {<0>}
                                    )
                                  ]
                                  spids: [133 134 155 -1]
                                )
                              ]
                            )
                          ]
                          negated: F
                        )
                        (command.ControlFlow
                          token: <Id.ControlFlow_Return return>
                          arg_word: {<1>}
                        )
                      ]
                    )
                    (command.ShAssignment
                      pairs: [
                        (assign_pair
                          lhs: (sh_lhs_expr.Name name:j)
                          op: assign_op.Equal
                          rhs: {($ Id.VSub_DollarName '$i')}
                          spids: [167]
                        )
                      ]
                    )
                    (command.ShAssignment
                      pairs: [
                        (assign_pair
                          lhs: (sh_lhs_expr.Name name:i)
                          op: assign_op.Equal
                          rhs: 
                            {
                              (word_part.ArithSub
                                anode: 
                                  (arith_expr.Binary
                                    op_id: Id.Arith_Plus
                                    left: {($ Id.VSub_DollarName '$i')}
                                    right: {<Id.Lit_Digits 1>}
                                  )
                              )
                            }
                          spids: [171]
                        )
                      ]
                    )
                  ]
                )
            )
          ]
        )
    )
    (C {<test_expect_success>} {<setup>} 
      {
        (SQ <'\n'> <'\tgit config i18n.commitencoding UTF-8 &&\n'> <'\n'> 
          <'\t# use UTF-8 in author and committer name to match the\n'> <'\t# i18n.commitencoding settings\n'> <'\t. "$TEST_DIRECTORY"/t3901-utf8.txt &&\n'> <'\n'> 
          <'\ttest_tick &&\n'> <'\techo "$GIT_AUTHOR_NAME" >mine &&\n'> <'\tgit add mine &&\n'> 
          <'\tgit commit -s -m "Initial commit" &&\n'> <'\n'> <'\ttest_tick &&\n'> <'\techo Hello world >mine &&\n'> <'\tgit add mine &&\n'> 
          <'\tgit commit -s -m "Second on main" &&\n'> <'\n'> <'\t# the first commit on the side branch is UTF-8\n'> <'\ttest_tick &&\n'> 
          <'\tgit checkout -b side master^ &&\n'> <'\techo Another file >yours &&\n'> <'\tgit add yours &&\n'> 
          <'\tgit commit -s -m "Second on side" &&\n'> <'\n'> <'\tif test_have_prereq !MINGW\n'> <'\tthen\n'> 
          <'\t\t# the second one on the side branch is ISO-8859-1\n'> <'\t\tgit config i18n.commitencoding ISO8859-1 &&\n'> 
          <'\t\t# use author and committer name in ISO-8859-1 to match it.\n'> <'\t\t. "$TEST_DIRECTORY"/t3901-8859-1.txt\n'> <'\tfi &&\n'> <'\ttest_tick &&\n'> 
          <'\techo Yet another >theirs &&\n'> <'\tgit add theirs &&\n'> <'\tgit commit -s -m "Third on side" &&\n'> <'\n'> <'\t# Back to default\n'> 
          <'\tgit config i18n.commitencoding UTF-8\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'format-patch output (ISO-8859-1)'>)} 
      {
        (SQ <'\n'> <'\tgit config i18n.logoutputencoding ISO8859-1 &&\n'> <'\n'> 
          <'\tgit format-patch --stdout master..HEAD^ >out-l1 &&\n'> <'\tgit format-patch --stdout HEAD^ >out-l2 &&\n'> 
          <'\tgrep "^Content-Type: text/plain; charset=ISO8859-1" out-l1 &&\n'> <'\tgrep "^From: =?ISO8859-1?q?=C1=E9=ED=20=F3=FA?=" out-l1 &&\n'> 
          <'\tgrep "^Content-Type: text/plain; charset=ISO8859-1" out-l2 &&\n'> <'\tgrep "^From: =?ISO8859-1?q?=C1=E9=ED=20=F3=FA?=" out-l2\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'format-patch output (UTF-8)'>)} 
      {
        (SQ <'\n'> <'\tgit config i18n.logoutputencoding UTF-8 &&\n'> <'\n'> 
          <'\tgit format-patch --stdout master..HEAD^ >out-u1 &&\n'> <'\tgit format-patch --stdout HEAD^ >out-u2 &&\n'> 
          <'\tgrep "^Content-Type: text/plain; charset=UTF-8" out-u1 &&\n'> <'\tgrep "^From: =?UTF-8?q?=C3=81=C3=A9=C3=AD=20=C3=B3=C3=BA?=" out-u1 &&\n'> 
          <'\tgrep "^Content-Type: text/plain; charset=UTF-8" out-u2 &&\n'> <'\tgrep "^From: =?UTF-8?q?=C3=81=C3=A9=C3=AD=20=C3=B3=C3=BA?=" out-u2\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'rebase (U/U)'>)} 
      {
        (SQ <'\n'> <'\t# We want the result of rebase in UTF-8\n'> 
          <'\tgit config i18n.commitencoding UTF-8 &&\n'> <'\n'> <'\t# The test is about logoutputencoding not affecting the\n'> 
          <'\t# final outcome -- it is used internally to generate the\n'> <'\t# patch and the log.\n'> <'\n'> <'\tgit config i18n.logoutputencoding UTF-8 &&\n'> <'\n'> 
          <'\t# The result will be committed by GIT_COMMITTER_NAME --\n'> <'\t# we want UTF-8 encoded name.\n'> <'\t. "$TEST_DIRECTORY"/t3901-utf8.txt &&\n'> 
          <'\tgit checkout -b test &&\n'> <'\tgit rebase master &&\n'> <'\n'> <'\tcheck_encoding 2\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'rebase (U/L)'>)} 
      {
        (SQ <'\n'> <'\tgit config i18n.commitencoding UTF-8 &&\n'> 
          <'\tgit config i18n.logoutputencoding ISO8859-1 &&\n'> <'\t. "$TEST_DIRECTORY"/t3901-utf8.txt &&\n'> <'\n'> <'\tgit reset --hard side &&\n'> 
          <'\tgit rebase master &&\n'> <'\n'> <'\tcheck_encoding 2\n'>
        )
      }
    )
    (C {<test_expect_success>} {<Id.KW_Bang '!'> <MINGW>} {(SQ <'rebase (L/L)'>)} 
      {
        (SQ <'\n'> <'\t# In this test we want ISO-8859-1 encoded commits as the result\n'> 
          <'\tgit config i18n.commitencoding ISO8859-1 &&\n'> <'\tgit config i18n.logoutputencoding ISO8859-1 &&\n'> <'\t. "$TEST_DIRECTORY"/t3901-8859-1.txt &&\n'> 
          <'\n'> <'\tgit reset --hard side &&\n'> <'\tgit rebase master &&\n'> <'\n'> <'\tcheck_encoding 2 8859\n'>
        )
      }
    )
    (C {<test_expect_success>} {<Id.KW_Bang '!'> <MINGW>} {(SQ <'rebase (L/U)'>)} 
      {
        (SQ <'\n'> <'\t# This is pathological -- use UTF-8 as intermediate form\n'> 
          <'\t# to get ISO-8859-1 results.\n'> <'\tgit config i18n.commitencoding ISO8859-1 &&\n'> <'\tgit config i18n.logoutputencoding UTF-8 &&\n'> 
          <'\t. "$TEST_DIRECTORY"/t3901-8859-1.txt &&\n'> <'\n'> <'\tgit reset --hard side &&\n'> <'\tgit rebase master &&\n'> <'\n'> <'\tcheck_encoding 2 8859\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'cherry-pick(U/U)'>)} 
      {
        (SQ <'\n'> <'\t# Both the commitencoding and logoutputencoding is set to UTF-8.\n'> <'\n'> 
          <'\tgit config i18n.commitencoding UTF-8 &&\n'> <'\tgit config i18n.logoutputencoding UTF-8 &&\n'> <'\t. "$TEST_DIRECTORY"/t3901-utf8.txt &&\n'> <'\n'> 
          <'\tgit reset --hard master &&\n'> <'\tgit cherry-pick side^ &&\n'> <'\tgit cherry-pick side &&\n'> <'\tgit revert HEAD &&\n'> <'\n'> 
          <'\tcheck_encoding 3\n'>
        )
      }
    )
    (C {<test_expect_success>} {<Id.KW_Bang '!'> <MINGW>} {(SQ <'cherry-pick(L/L)'>)} 
      {
        (SQ <'\n'> <'\t# Both the commitencoding and logoutputencoding is set to ISO-8859-1\n'> <'\n'> 
          <'\tgit config i18n.commitencoding ISO8859-1 &&\n'> <'\tgit config i18n.logoutputencoding ISO8859-1 &&\n'> <'\t. "$TEST_DIRECTORY"/t3901-8859-1.txt &&\n'> 
          <'\n'> <'\tgit reset --hard master &&\n'> <'\tgit cherry-pick side^ &&\n'> <'\tgit cherry-pick side &&\n'> 
          <'\tgit revert HEAD &&\n'> <'\n'> <'\tcheck_encoding 3 8859\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'cherry-pick(U/L)'>)} 
      {
        (SQ <'\n'> <'\t# Commitencoding is set to UTF-8 but logoutputencoding is ISO-8859-1\n'> <'\n'> 
          <'\tgit config i18n.commitencoding UTF-8 &&\n'> <'\tgit config i18n.logoutputencoding ISO8859-1 &&\n'> <'\t. "$TEST_DIRECTORY"/t3901-utf8.txt &&\n'> 
          <'\n'> <'\tgit reset --hard master &&\n'> <'\tgit cherry-pick side^ &&\n'> <'\tgit cherry-pick side &&\n'> 
          <'\tgit revert HEAD &&\n'> <'\n'> <'\tcheck_encoding 3\n'>
        )
      }
    )
    (C {<test_expect_success>} {<Id.KW_Bang '!'> <MINGW>} {(SQ <'cherry-pick(L/U)'>)} 
      {
        (SQ <'\n'> <'\t# Again, the commitencoding is set to ISO-8859-1 but\n'> 
          <'\t# logoutputencoding is set to UTF-8.\n'> <'\n'> <'\tgit config i18n.commitencoding ISO8859-1 &&\n'> 
          <'\tgit config i18n.logoutputencoding UTF-8 &&\n'> <'\t. "$TEST_DIRECTORY"/t3901-8859-1.txt &&\n'> <'\n'> <'\tgit reset --hard master &&\n'> 
          <'\tgit cherry-pick side^ &&\n'> <'\tgit cherry-pick side &&\n'> <'\tgit revert HEAD &&\n'> <'\n'> <'\tcheck_encoding 3 8859\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'rebase --merge (U/U)'>)} 
      {
        (SQ <'\n'> <'\tgit config i18n.commitencoding UTF-8 &&\n'> 
          <'\tgit config i18n.logoutputencoding UTF-8 &&\n'> <'\t. "$TEST_DIRECTORY"/t3901-utf8.txt &&\n'> <'\n'> <'\tgit reset --hard side &&\n'> 
          <'\tgit rebase --merge master &&\n'> <'\n'> <'\tcheck_encoding 2\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'rebase --merge (U/L)'>)} 
      {
        (SQ <'\n'> <'\tgit config i18n.commitencoding UTF-8 &&\n'> 
          <'\tgit config i18n.logoutputencoding ISO8859-1 &&\n'> <'\t. "$TEST_DIRECTORY"/t3901-utf8.txt &&\n'> <'\n'> <'\tgit reset --hard side &&\n'> 
          <'\tgit rebase --merge master &&\n'> <'\n'> <'\tcheck_encoding 2\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'rebase --merge (L/L)'>)} 
      {
        (SQ <'\n'> <'\t# In this test we want ISO-8859-1 encoded commits as the result\n'> 
          <'\tgit config i18n.commitencoding ISO8859-1 &&\n'> <'\tgit config i18n.logoutputencoding ISO8859-1 &&\n'> <'\t. "$TEST_DIRECTORY"/t3901-8859-1.txt &&\n'> 
          <'\n'> <'\tgit reset --hard side &&\n'> <'\tgit rebase --merge master &&\n'> <'\n'> 
          <'\tcheck_encoding 2 8859\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'rebase --merge (L/U)'>)} 
      {
        (SQ <'\n'> <'\t# This is pathological -- use UTF-8 as intermediate form\n'> 
          <'\t# to get ISO-8859-1 results.\n'> <'\tgit config i18n.commitencoding ISO8859-1 &&\n'> <'\tgit config i18n.logoutputencoding UTF-8 &&\n'> 
          <'\t. "$TEST_DIRECTORY"/t3901-8859-1.txt &&\n'> <'\n'> <'\tgit reset --hard side &&\n'> <'\tgit rebase --merge master &&\n'> <'\n'> 
          <'\tcheck_encoding 2 8859\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'am (U/U)'>)} 
      {
        (SQ <'\n'> <'\t# Apply UTF-8 patches with UTF-8 commitencoding\n'> 
          <'\tgit config i18n.commitencoding UTF-8 &&\n'> <'\t. "$TEST_DIRECTORY"/t3901-utf8.txt &&\n'> <'\n'> <'\tgit reset --hard master &&\n'> 
          <'\tgit am out-u1 out-u2 &&\n'> <'\n'> <'\tcheck_encoding 2\n'>
        )
      }
    )
    (C {<test_expect_success>} {<Id.KW_Bang '!'> <MINGW>} {(SQ <'am (L/L)'>)} 
      {
        (SQ <'\n'> <'\t# Apply ISO-8859-1 patches with ISO-8859-1 commitencoding\n'> 
          <'\tgit config i18n.commitencoding ISO8859-1 &&\n'> <'\t. "$TEST_DIRECTORY"/t3901-8859-1.txt &&\n'> <'\n'> <'\tgit reset --hard master &&\n'> 
          <'\tgit am out-l1 out-l2 &&\n'> <'\n'> <'\tcheck_encoding 2 8859\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'am (U/L)'>)} 
      {
        (SQ <'\n'> <'\t# Apply ISO-8859-1 patches with UTF-8 commitencoding\n'> 
          <'\tgit config i18n.commitencoding UTF-8 &&\n'> <'\t. "$TEST_DIRECTORY"/t3901-utf8.txt &&\n'> <'\tgit reset --hard master &&\n'> <'\n'> 
          <'\t# am specifies --utf8 by default.\n'> <'\tgit am out-l1 out-l2 &&\n'> <'\n'> <'\tcheck_encoding 2\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'am --no-utf8 (U/L)'>)} 
      {
        (SQ <'\n'> <'\t# Apply ISO-8859-1 patches with UTF-8 commitencoding\n'> 
          <'\tgit config i18n.commitencoding UTF-8 &&\n'> <'\t. "$TEST_DIRECTORY"/t3901-utf8.txt &&\n'> <'\n'> <'\tgit reset --hard master &&\n'> 
          <'\tgit am --no-utf8 out-l1 out-l2 2>err &&\n'> <'\n'> <'\t# commit-tree will warn that the commit message does not contain valid UTF-8\n'> 
          <'\t# as mailinfo did not convert it\n'> <'\ttest_i18ngrep "did not conform" err &&\n'> <'\n'> <'\tcheck_encoding 2\n'>
        )
      }
    )
    (C {<test_expect_success>} {<Id.KW_Bang '!'> <MINGW>} {(SQ <'am (L/U)'>)} 
      {
        (SQ <'\n'> <'\t# Apply UTF-8 patches with ISO-8859-1 commitencoding\n'> 
          <'\tgit config i18n.commitencoding ISO8859-1 &&\n'> <'\t. "$TEST_DIRECTORY"/t3901-8859-1.txt &&\n'> <'\n'> <'\tgit reset --hard master &&\n'> 
          <'\t# mailinfo will re-code the commit message to the charset specified by\n'> <'\t# i18n.commitencoding\n'> <'\tgit am out-u1 out-u2 &&\n'> <'\n'> <'\tcheck_encoding 2 8859\n'>
        )
      }
    )
    (C {<test_done>})
  ]
)