(command.CommandList
  children: [
    (command.ShAssignment
      pairs: [
        (assign_pair
          lhs: (sh_lhs_expr.Name name:test_description)
          op: assign_op.Equal
          rhs: {(SQ <'send-pack --stdin tests'>)}
          spids: [4]
        )
      ]
    )
    (C {<.>} {<'./test-lib.sh'>})
    (command.ShFunction
      name: create_ref
      body: 
        (BraceGroup
          children: [
            (command.AndOr
              ops: [Id.Op_DAmp Id.Op_DAmp Id.Op_DAmp]
              children: [
                (command.ShAssignment
                  pairs: [
                    (assign_pair
                      lhs: (sh_lhs_expr.Name name:tree)
                      op: assign_op.Equal
                      rhs: 
                        {
                          (command_sub
                            left_token: <Id.Left_DollarParen '$('>
                            child: (C {<git>} {<write-tree>})
                          )
                        }
                      spids: [22]
                    )
                  ]
                )
                (C {<test_tick>})
                (command.ShAssignment
                  pairs: [
                    (assign_pair
                      lhs: (sh_lhs_expr.Name name:commit)
                      op: assign_op.Equal
                      rhs: 
                        {
                          (command_sub
                            left_token: <Id.Left_DollarParen '$('>
                            child: 
                              (command.Pipeline
                                children: [
                                  (C {<echo>} {(DQ ($ Id.VSub_Number '$1'))})
                                  (C {<git>} {<commit-tree>} {($ Id.VSub_DollarName '$tree')})
                                ]
                                negated: F
                              )
                          )
                        }
                      spids: [37]
                    )
                  ]
                )
                (C {<git>} {<update-ref>} {(DQ ($ Id.VSub_Number '$1'))} 
                  {($ Id.VSub_DollarName '$commit')}
                )
              ]
            )
          ]
        )
    )
    (command.ShFunction
      name: clear_remote
      body: 
        (BraceGroup
          children: [
            (command.AndOr
              ops: [Id.Op_DAmp]
              children: [
                (C {<rm>} {<-rf>} {<remote.git>})
                (C {<git>} {<init>} {<--bare>} {<remote.git>})
              ]
            )
          ]
        )
    )
    (command.ShFunction
      name: verify_push
      body: 
        (BraceGroup
          children: [
            (command.AndOr
              ops: [Id.Op_DAmp Id.Op_DAmp]
              children: [
                (command.Simple
                  words: [{<git>} {<rev-parse>} {(DQ ($ Id.VSub_Number '$1'))}]
                  redirects: [(redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<expect>})]
                  do_fork: T
                )
                (command.Simple
                  words: [
                    {<git>}
                    {<--git-dir> <Id.Lit_Equals '='> <remote.git>}
                    {<rev-parse>}
                    {
                      (DQ 
                        (braced_var_sub
                          token: <Id.VSub_Number 2>
                          suffix_op: 
                            (suffix_op.Unary
                              tok: <Id.VTest_ColonHyphen ':-'>
                              arg_word: {($ Id.VSub_Number '$1')}
                            )
                        )
                      )
                    }
                  ]
                  redirects: [(redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<actual>})]
                  do_fork: T
                )
                (C {<test_cmp>} {<expect>} {<actual>})
              ]
            )
          ]
        )
    )
    (C {<test_expect_success>} {(SQ <'setup refs'>)} 
      {
        (SQ <'\n'> <'\tcat >refs <<-\\EOF &&\n'> <'\trefs/heads/A\n'> <'\trefs/heads/C\n'> 
          <'\trefs/tags/D\n'> <'\trefs/heads/B\n'> <'\trefs/tags/E\n'> <'\tEOF\n'> <'\tfor i in $(cat refs); do\n'> 
          <'\t\tcreate_ref $i || return 1\n'> <'\tdone\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'refs on cmdline'>)} 
      {
        (SQ <'\n'> <'\tclear_remote &&\n'> <'\tgit send-pack remote.git $(cat refs) &&\n'> 
          <'\tfor i in $(cat refs); do\n'> <'\t\tverify_push $i || return 1\n'> <'\tdone\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'refs over stdin'>)} 
      {
        (SQ <'\n'> <'\tclear_remote &&\n'> <'\tgit send-pack remote.git --stdin <refs &&\n'> 
          <'\tfor i in $(cat refs); do\n'> <'\t\tverify_push $i || return 1\n'> <'\tdone\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'stdin lines are full refspecs'>)} 
      {
        (SQ <'\n'> <'\tclear_remote &&\n'> <'\techo "A:other" >input &&\n'> 
          <'\tgit send-pack remote.git --stdin <input &&\n'> <'\tverify_push refs/heads/A refs/heads/other\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'stdin mixed with cmdline'>)} 
      {
        (SQ <'\n'> <'\tclear_remote &&\n'> <'\techo A >input &&\n'> 
          <'\tgit send-pack remote.git --stdin B <input &&\n'> <'\tverify_push A &&\n'> <'\tverify_push B\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'cmdline refs written in order'>)} 
      {
        (SQ <'\n'> <'\tclear_remote &&\n'> 
          <'\ttest_must_fail git send-pack remote.git A:foo B:foo &&\n'> <'\tverify_push A foo\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'--stdin refs come after cmdline'>)} 
      {
        (SQ <'\n'> <'\tclear_remote &&\n'> <'\techo A:foo >input &&\n'> 
          <'\ttest_must_fail git send-pack remote.git --stdin B:foo <input &&\n'> <'\tverify_push B foo\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'refspecs and --mirror do not mix (cmdline)'>)} 
      {
        (SQ <'\n'> <'\tclear_remote &&\n'> 
          <'\ttest_must_fail git send-pack remote.git --mirror $(cat refs)\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'refspecs and --mirror do not mix (stdin)'>)} 
      {
        (SQ <'\n'> <'\tclear_remote &&\n'> 
          <'\ttest_must_fail git send-pack remote.git --mirror --stdin <refs\n'>
        )
      }
    )
    (C {<test_done>})
  ]
)