(CommandList
  children: [
    (Assignment
      keyword: Assign_None
      pairs: [
        (assign_pair
          lhs: (LhsName name:test_description)
          op: Equal
          rhs: {(SQ <"i18n settings and format-patch | am pipe">)}
          spids: [13]
        )
      ]
      spids: [13]
    )
    (C {(.)} {(./test-lib.sh)})
    (FuncDef
      name: check_encoding
      body: 
        (BraceGroup
          children: [
            (Assignment
              keyword: Assign_None
              pairs: [
                (assign_pair
                  lhs: (LhsName name:cnt)
                  op: Equal
                  rhs: {(DQ ($ VSub_Number "$1"))}
                  spids: [36]
                )
                (assign_pair
                  lhs: (LhsName name:header)
                  op: Equal
                  rhs: {(DQ ($ VSub_Number "$2"))}
                  spids: [41]
                )
                (assign_pair lhs:(LhsName name:i) op:Equal rhs:{(1)} spids:[46])
                (assign_pair lhs:(LhsName name:j) op:Equal rhs:{(0)} spids:[49])
              ]
              spids: [36]
            )
            (While
              cond: [(C {(test)} {(DQ ($ VSub_Name "$i"))} {(-le)} {($ VSub_Name "$cnt")})]
              body: 
                (DoGroup
                  children: [
                    (AndOr
                      children: [
                        (Pipeline
                          children: [
                            (C {(git)} {(format-patch)} {(--encoding) (Lit_Other "=") (UTF-8)} 
                              {(--stdout)} {(HEAD) (Lit_Tilde "~") ($ VSub_Name "$i") (..HEAD) (Lit_Tilde "~") ($ VSub_Name "$j")}
                            )
                            (C {(grep)} {(DQ ("^From: =?UTF-8?q?=C3=81=C3=A9=C3=AD=20=C3=B3=C3=BA?="))})
                          ]
                          negated: False
                        )
                        (AndOr
                          children: [
                            (Pipeline
                              children: [
                                (C {(git)} {(cat-file)} {(commit)} 
                                  {(HEAD) (Lit_Tilde "~") ($ VSub_Name "$j")}
                                )
                                (Case
                                  to_match: {(DQ ($ VSub_Name "$header"))}
                                  arms: [
                                    (case_arm
                                      pat_list: [{(8859)}]
                                      action: [(C {(grep)} {(DQ ("^encoding ISO8859-1"))})]
                                      spids: [120 121 130 -1]
                                    )
                                    (case_arm
                                      pat_list: [{(Lit_Other "*")}]
                                      action: [
                                        (Sentence
                                          child: (C {(grep)} {(DQ ("^encoding ISO8859-1"))})
                                          terminator: <Op_Semi ";">
                                        )
                                        (C {(test)} {(DQ ($ VSub_QMark "$?"))} 
                                          {(KW_Bang "!") (Lit_Other "=")} {(0)}
                                        )
                                      ]
                                      spids: [133 134 155 -1]
                                    )
                                  ]
                                  spids: [111 117 158]
                                )
                              ]
                              negated: False
                            )
                            (ControlFlow
                              token: <ControlFlow_Return return>
                              arg_word: {(1)}
                            )
                          ]
                          op_id: Op_DPipe
                        )
                      ]
                      op_id: Op_DAmp
                    )
                    (Assignment
                      keyword: Assign_None
                      pairs: [
                        (assign_pair
                          lhs: (LhsName name:j)
                          op: Equal
                          rhs: {($ VSub_Name "$i")}
                          spids: [167]
                        )
                      ]
                      spids: [167]
                    )
                    (Assignment
                      keyword: Assign_None
                      pairs: [
                        (assign_pair
                          lhs: (LhsName name:i)
                          op: Equal
                          rhs: 
                            {
                              (ArithSubPart
                                anode: 
                                  (ArithBinary
                                    op_id: Arith_Plus
                                    left: (ArithWord w:{($ VSub_Name "$i")})
                                    right: (ArithWord w:{(Lit_Digits 1)})
                                  )
                                spids: [172 177]
                              )
                            }
                          spids: [171]
                        )
                      ]
                      spids: [171]
                    )
                  ]
                  spids: [66 180]
                )
            )
          ]
          spids: [29]
        )
      spids: [24 28]
    )
    (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)} {(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)} {(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)} {(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)} {(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)} {(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)} {(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)})
  ]
)