(command.CommandList
  children: [
    (command.ShAssignment
      pairs: [
        (assign_pair
          lhs: (sh_lhs_expr.Name name:test_description)
          op: assign_op.Equal
          rhs: {(SQ <'GIT_EDITOR, core.editor, and stuff'>)}
          spids: [4]
        )
      ]
    )
    (C {<.>} {<'./test-lib.sh'>})
    (C {<unset>} {<EDITOR>} {<VISUAL>} {<GIT_EDITOR>})
    (C {<test_expect_success>} {(SQ <'determine default editor'>)} 
      {(SQ <'\n'> <'\n'> <'\tvi=$(TERM=vt100 git var GIT_EDITOR) &&\n'> <'\ttest -n "$vi"\n'> <'\n'>)}
    )
    (command.If
      arms: [
        (if_arm
          cond: [
            (command.Pipeline
              children: [
                (command.Simple
                  words: [
                    {<expr>}
                    {(DQ ($ Id.VSub_DollarName '$vi'))}
                    {<Id.Lit_Colon ':'>}
                    {(SQ <'[a-z]*$'>)}
                  ]
                  redirects: [
                    (redir
                      op: <Id.Redir_Great '>'>
                      loc: (redir_loc.Fd fd:1)
                      arg: {<'/dev/null'>}
                    )
                  ]
                  do_fork: T
                )
              ]
              negated: T
            )
          ]
          action: [
            (command.ShAssignment
              pairs: [
                (assign_pair
                  lhs: (sh_lhs_expr.Name name:vi)
                  op: assign_op.Equal
                  rhs: (word.Empty)
                  spids: [61]
                )
              ]
            )
          ]
          spids: [39 58]
        )
      ]
    )
    (command.ForEach
      iter_name: i
      iter_words: [{<GIT_EDITOR>} {<core_editor>} {<EDITOR>} {<VISUAL>} {($ Id.VSub_DollarName '$vi')}]
      do_arg_iter: F
      body: 
        (command.DoGroup
          children: [
            (command.Simple
              words: [{<cat>}]
              redirects: [
                (redir
                  op: <Id.Redir_Great '>'>
                  loc: (redir_loc.Fd fd:1)
                  arg: {<e-> ($ Id.VSub_DollarName '$i') <.sh>}
                )
                (redir
                  op: <Id.Redir_DLessDash '<<-'>
                  loc: (redir_loc.Fd fd:0)
                  arg: 
                    (redir_param.MultiLine
                      here_begin: {<EOF>}
                      here_end_span_id: 110
                      stdin_parts: [
                        <'#!'>
                        ($ Id.VSub_DollarName '$SHELL_PATH')
                        <'\n'>
                        <'echo '>
                        <Id.Right_DoubleQuote '"'>
                        <'Edited by '>
                        ($ Id.VSub_DollarName '$i')
                        <Id.Right_DoubleQuote '"'>
                        <' >'>
                        <Id.Right_DoubleQuote '"'>
                        (word_part.EscapedLiteral
                          token: <Id.Lit_EscapedChar '\\$'>
                        )
                        <1>
                        <Id.Right_DoubleQuote '"'>
                        <'\n'>
                      ]
                    )
                )
              ]
              do_fork: T
            )
            (C {<chmod>} {<Id.Lit_Other '+'> <x>} {<e-> ($ Id.VSub_DollarName '$i') <.sh>})
          ]
        )
    )
    (command.If
      arms: [
        (if_arm
          cond: [
            (command.Pipeline
              children: [(C {<test>} {<-z>} {(DQ ($ Id.VSub_DollarName '$vi'))})]
              negated: T
            )
          ]
          action: [(C {<mv>} {<e-> ($ Id.VSub_DollarName '$vi') <.sh>} {($ Id.VSub_DollarName '$vi')})]
          spids: [124 136]
        )
      ]
    )
    (C {<test_expect_success>} {<setup>} 
      {
        (SQ <'\n'> <'\n'> <'\tmsg="Hand-edited" &&\n'> <'\ttest_commit "$msg" &&\n'> 
          <'\techo "$msg" >expect &&\n'> <'\tgit show -s --format=%s > actual &&\n'> <'\ttest_cmp actual expect\n'> <'\n'>
        )
      }
    )
    (command.ShAssignment
      pairs: [
        (assign_pair
          lhs: (sh_lhs_expr.Name name:TERM)
          op: assign_op.Equal
          rhs: {<dumb>}
          spids: [166]
        )
      ]
    )
    (C {<export>} {<TERM>})
    (C {<test_expect_success>} {(SQ <'dumb should error out when falling back on vi'>)} 
      {
        (SQ <'\n'> <'\n'> <'\tif git commit --amend\n'> <'\tthen\n'> <'\t\techo "Oops?"\n'> 
          <'\t\tfalse\n'> <'\telse\n'> <'\t\t: happy\n'> <'\tfi\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'dumb should prefer EDITOR to VISUAL'>)} 
      {
        (SQ <'\n'> <'\n'> <'\tEDITOR=./e-EDITOR.sh &&\n'> <'\tVISUAL=./e-VISUAL.sh &&\n'> 
          <'\texport EDITOR VISUAL &&\n'> <'\tgit commit --amend &&\n'> <'\ttest "$(git show -s --format=%s)" = "Edited by EDITOR"\n'> <'\n'>
        )
      }
    )
    (command.ShAssignment
      pairs: [
        (assign_pair
          lhs: (sh_lhs_expr.Name name:TERM)
          op: assign_op.Equal
          rhs: {<vt100>}
          spids: [210]
        )
      ]
    )
    (C {<export>} {<TERM>})
    (command.ForEach
      iter_name: i
      iter_words: [{($ Id.VSub_DollarName '$vi')} {<EDITOR>} {<VISUAL>} {<core_editor>} {<GIT_EDITOR>}]
      do_arg_iter: F
      body: 
        (command.DoGroup
          children: [
            (command.Simple
              words: [{<echo>} {(DQ <'Edited by '> ($ Id.VSub_DollarName '$i'))}]
              redirects: [(redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<expect>})]
              do_fork: T
            )
            (C {<unset>} {<EDITOR>} {<VISUAL>} {<GIT_EDITOR>})
            (C {<git>} {<config>} {<--unset-all>} {<core.editor>})
            (command.Case
              to_match: {(DQ ($ Id.VSub_DollarName '$i'))}
              arms: [
                (case_arm
                  pat_list: [{<core_editor>}]
                  action: [(C {<git>} {<config>} {<core.editor>} {<'./e-core_editor.sh'>})]
                  spids: [274 275 287 -1]
                )
                (case_arm
                  pat_list: [{<Id.Lit_LBracket '['> <A-Z> <Id.Lit_RBracket ']'> <Id.Lit_Star '*'>}]
                  action: [
                    (C {<eval>} 
                      {(DQ ($ Id.VSub_DollarName '$i') <'=./e-'> ($ Id.VSub_DollarName '$i') <.sh>)}
                    )
                    (C {<export>} {($ Id.VSub_DollarName '$i')})
                  ]
                  spids: [290 294 312 -1]
                )
              ]
            )
            (C {<test_expect_success>} {(DQ <'Using '> ($ Id.VSub_DollarName '$i'))} 
              {
                (SQ <'\n'> <'\t\tgit --exec-path=. commit --amend &&\n'> 
                  <'\t\tgit show -s --pretty=oneline |\n'> <'\t\tsed -e "s/^[0-9a-f]* //" >actual &&\n'> <'\t\ttest_cmp actual expect\n'> <'\t'>
                )
              }
            )
          ]
        )
    )
    (C {<unset>} {<EDITOR>} {<VISUAL>} {<GIT_EDITOR>})
    (C {<git>} {<config>} {<--unset-all>} {<core.editor>})
    (command.ForEach
      iter_name: i
      iter_words: [{($ Id.VSub_DollarName '$vi')} {<EDITOR>} {<VISUAL>} {<core_editor>} {<GIT_EDITOR>}]
      do_arg_iter: F
      body: 
        (command.DoGroup
          children: [
            (command.Simple
              words: [{<echo>} {(DQ <'Edited by '> ($ Id.VSub_DollarName '$i'))}]
              redirects: [(redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<expect>})]
              do_fork: T
            )
            (command.Case
              to_match: {(DQ ($ Id.VSub_DollarName '$i'))}
              arms: [
                (case_arm
                  pat_list: [{<core_editor>}]
                  action: [(C {<git>} {<config>} {<core.editor>} {<'./e-core_editor.sh'>})]
                  spids: [392 393 405 -1]
                )
                (case_arm
                  pat_list: [{<Id.Lit_LBracket '['> <A-Z> <Id.Lit_RBracket ']'> <Id.Lit_Star '*'>}]
                  action: [
                    (C {<eval>} 
                      {(DQ ($ Id.VSub_DollarName '$i') <'=./e-'> ($ Id.VSub_DollarName '$i') <.sh>)}
                    )
                    (C {<export>} {($ Id.VSub_DollarName '$i')})
                  ]
                  spids: [408 412 430 -1]
                )
              ]
            )
            (C {<test_expect_success>} {(DQ <'Using '> ($ Id.VSub_DollarName '$i') <' (override)'>)} 
              {
                (SQ <'\n'> <'\t\tgit --exec-path=. commit --amend &&\n'> 
                  <'\t\tgit show -s --pretty=oneline |\n'> <'\t\tsed -e "s/^[0-9a-f]* //" >actual &&\n'> <'\t\ttest_cmp actual expect\n'> <'\t'>
                )
              }
            )
          ]
        )
    )
    (command.If
      arms: [
        (if_arm
          cond: [
            (command.Simple
              words: [{<echo>} {(SQ <'echo space > "$1"'>)}]
              redirects: [
                (redir
                  op: <Id.Redir_Great '>'>
                  loc: (redir_loc.Fd fd:1)
                  arg: {(DQ <'e space.sh'>)}
                )
              ]
              do_fork: T
            )
          ]
          action: [(C {<test_set_prereq>} {<SPACES_IN_FILENAMES>})]
          spids: [456 470]
        )
      ]
    )
    (C {<test_expect_success>} {<SPACES_IN_FILENAMES>} {(SQ <'editor with a space'>)} 
      {
        (SQ <'\n'> <'\n'> <'\tchmod a+x "e space.sh" &&\n'> 
          <'\tGIT_EDITOR="./e\\ space.sh" git commit --amend &&\n'> <'\ttest space = "$(git show -s --pretty=format:%s)"\n'> <'\n'>
        )
      }
    )
    (C {<unset>} {<GIT_EDITOR>})
    (C {<test_expect_success>} {<SPACES_IN_FILENAMES>} {(SQ <'core.editor with a space'>)} 
      {
        (SQ <'\n'> <'\n'> <'\tgit config core.editor \\"./e\\ space.sh\\" &&\n'> 
          <'\tgit commit --amend &&\n'> <'\ttest space = "$(git show -s --pretty=format:%s)"\n'> <'\n'>
        )
      }
    )
    (C {<test_done>})
  ]
)