(command.CommandList
  children: [
    (command.ShAssignment
      pairs: [
        (assign_pair
          lhs: (sh_lhs_expr.Name name:test_description)
          op: assign_op.Equal
          rhs: {(SQ <'clone --branch option'>)}
          spids: [4]
        )
      ]
    )
    (C {<.>} {<'./test-lib.sh'>})
    (command.ShFunction
      name: check_HEAD
      body: 
        (BraceGroup
          children: [
            (command.AndOr
              ops: [Id.Op_DAmp Id.Op_DAmp]
              children: [
                (command.Simple
                  words: [{<echo>} {<'refs/heads/'> (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>} {<symbolic-ref>} {<HEAD>}]
                  redirects: [(redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<actual>})]
                  do_fork: T
                )
                (C {<test_cmp>} {<expect>} {<actual>})
              ]
            )
          ]
        )
    )
    (command.ShFunction
      name: check_file
      body: 
        (BraceGroup
          children: [
            (command.AndOr
              ops: [Id.Op_DAmp]
              children: [
                (command.Simple
                  words: [{<echo>} {(DQ ($ Id.VSub_Number '$1'))}]
                  redirects: [(redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<expect>})]
                  do_fork: T
                )
                (C {<test_cmp>} {<expect>} {<file>})
              ]
            )
          ]
        )
    )
    (C {<test_expect_success>} {(SQ <setup>)} 
      {
        (SQ <'\n'> <'\tmkdir parent &&\n'> <'\t(cd parent && git init &&\n'> 
          <'\t echo one >file && git add file && git commit -m one &&\n'> <'\t git checkout -b two &&\n'> <'\t echo two >file && git add file && git commit -m two &&\n'> 
          <'\t git checkout master) &&\n'> <'\tmkdir empty &&\n'> <'\t(cd empty && git init)\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'vanilla clone chooses HEAD'>)} 
      {
        (SQ <'\n'> <'\tgit clone parent clone &&\n'> <'\t(cd clone &&\n'> <'\t check_HEAD master &&\n'> 
          <'\t check_file one\n'> <'\t)\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'clone -b chooses specified branch'>)} 
      {
        (SQ <'\n'> <'\tgit clone -b two parent clone-two &&\n'> <'\t(cd clone-two &&\n'> 
          <'\t check_HEAD two &&\n'> <'\t check_file two\n'> <'\t)\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'clone -b sets up tracking'>)} 
      {
        (SQ <'\n'> <'\t(cd clone-two &&\n'> <'\t echo origin >expect &&\n'> 
          <'\t git config branch.two.remote >actual &&\n'> <'\t echo refs/heads/two >>expect &&\n'> <'\t git config branch.two.merge >>actual &&\n'> 
          <'\t test_cmp expect actual\n'> <'\t)\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'clone -b does not munge remotes/origin/HEAD'>)} 
      {
        (SQ <'\n'> <'\t(cd clone-two &&\n'> <'\t echo refs/remotes/origin/master >expect &&\n'> 
          <'\t git symbolic-ref refs/remotes/origin/HEAD >actual &&\n'> <'\t test_cmp expect actual\n'> <'\t)\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'clone -b with bogus branch'>)} 
      {(SQ <'\n'> <'\ttest_must_fail git clone -b bogus parent clone-bogus\n'>)}
    )
    (C {<test_expect_success>} {(SQ <'clone -b not allowed with empty repos'>)} 
      {(SQ <'\n'> <'\ttest_must_fail git clone -b branch empty clone-branch-empty\n'>)}
    )
    (C {<test_done>})
  ]
)