(CommandList
  children: [
    (Assignment
      keyword: Assign_None
      pairs: [
        (assign_pair
          lhs: (LhsName name:test_description)
          op: Equal
          rhs: {(SQ <'checkout into detached HEAD state'>)}
          spids: [4]
        )
      ]
      spids: [4]
    )
    (C {(.)} {(./test-lib.sh)})
    (FuncDef
      name: check_detached
      body: 
        (BraceGroup
          children: [
            (SimpleCommand
              words: [{(test_must_fail)} {(git)} {(symbolic-ref)} {(-q)} {(HEAD)}]
              redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[32])]
            )
          ]
          spids: [19]
        )
      spids: [14 18]
    )
    (FuncDef
      name: check_not_detached
      body: 
        (BraceGroup
          children: [
            (SimpleCommand
              words: [{(git)} {(symbolic-ref)} {(-q)} {(HEAD)}]
              redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[54])]
            )
          ]
          spids: [43]
        )
      spids: [38 42]
    )
    (Assignment
      keyword: Assign_None
      pairs: [
        (assign_pair
          lhs: (LhsName name:PREV_HEAD_DESC)
          op: Equal
          rhs: {(SQ <'Previous HEAD position was'>)}
          spids: [60]
        )
      ]
      spids: [60]
    )
    (FuncDef
      name: check_orphan_warning
      body: 
        (BraceGroup
          children: [
            (AndOr
              children: [
                (C {(test_i18ngrep)} {(DQ ('you are leaving ') ($ VSub_Number '$2') (' behind'))} 
                  {(DQ ($ VSub_Number '$1'))}
                )
                (C {(test_i18ngrep)} {(KW_Bang '!')} {(DQ ($ VSub_Name '$PREV_HEAD_DESC'))} 
                  {(DQ ($ VSub_Number '$1'))}
                )
              ]
              op_id: Op_DAmp
            )
          ]
          spids: [69]
        )
      spids: [65 68]
    )
    (FuncDef
      name: check_no_orphan_warning
      body: 
        (BraceGroup
          children: [
            (AndOr
              children: [
                (C {(test_i18ngrep)} {(KW_Bang '!')} {(DQ ('you are leaving .* commit.*behind'))} 
                  {(DQ ($ VSub_Number '$1'))}
                )
                (C {(test_i18ngrep)} {(DQ ($ VSub_Name '$PREV_HEAD_DESC'))} {(DQ ($ VSub_Number '$1'))})
              ]
              op_id: Op_DAmp
            )
          ]
          spids: [105]
        )
      spids: [101 104]
    )
    (FuncDef
      name: reset
      body: 
        (BraceGroup
          children: [
            (AndOr
              children: [(C {(git)} {(checkout)} {(master)}) (C {(check_not_detached)})]
              op_id: Op_DAmp
            )
          ]
          spids: [141]
        )
      spids: [136 140]
    )
    (C {(test_expect_success)} {(SQ <setup>)} 
      {
        (SQ <'\n'> <'\ttest_commit one &&\n'> <'\ttest_commit two &&\n'> 
          <'\ttest_commit three && git tag -d three &&\n'> <'\ttest_commit four && git tag -d four &&\n'> <'\tgit branch branch &&\n'> <'\tgit tag tag\n'>
        )
      }
    )
    (C {(test_expect_success)} {(SQ <'checkout branch does not detach'>)} 
      {(SQ <'\n'> <'\treset &&\n'> <'\tgit checkout branch &&\n'> <'\tcheck_not_detached\n'>)}
    )
    (C {(test_expect_success)} {(SQ <'checkout tag detaches'>)} 
      {(SQ <'\n'> <'\treset &&\n'> <'\tgit checkout tag &&\n'> <'\tcheck_detached\n'>)}
    )
    (C {(test_expect_success)} {(SQ <'checkout branch by full name detaches'>)} 
      {(SQ <'\n'> <'\treset &&\n'> <'\tgit checkout refs/heads/branch &&\n'> <'\tcheck_detached\n'>)}
    )
    (C {(test_expect_success)} {(SQ <'checkout non-ref detaches'>)} 
      {(SQ <'\n'> <'\treset &&\n'> <'\tgit checkout branch^ &&\n'> <'\tcheck_detached\n'>)}
    )
    (C {(test_expect_success)} {(SQ <'checkout ref^0 detaches'>)} 
      {(SQ <'\n'> <'\treset &&\n'> <'\tgit checkout branch^0 &&\n'> <'\tcheck_detached\n'>)}
    )
    (C {(test_expect_success)} {(SQ <'checkout --detach detaches'>)} 
      {(SQ <'\n'> <'\treset &&\n'> <'\tgit checkout --detach branch &&\n'> <'\tcheck_detached\n'>)}
    )
    (C {(test_expect_success)} {(SQ <'checkout --detach without branch name'>)} 
      {(SQ <'\n'> <'\treset &&\n'> <'\tgit checkout --detach &&\n'> <'\tcheck_detached\n'>)}
    )
    (C {(test_expect_success)} {(SQ <'checkout --detach errors out for non-commit'>)} 
      {
        (SQ <'\n'> <'\treset &&\n'> <'\ttest_must_fail git checkout --detach one^{tree} &&\n'> 
          <'\tcheck_not_detached\n'>
        )
      }
    )
    (C {(test_expect_success)} {(SQ <'checkout --detach errors out for extra argument'>)} 
      {
        (SQ <'\n'> <'\treset &&\n'> <'\tgit checkout master &&\n'> 
          <'\ttest_must_fail git checkout --detach tag one.t &&\n'> <'\tcheck_not_detached\n'>
        )
      }
    )
    (C {(test_expect_success)} {(SQ <'checkout --detached and -b are incompatible'>)} 
      {
        (SQ <'\n'> <'\treset &&\n'> <'\ttest_must_fail git checkout --detach -b newbranch tag &&\n'> 
          <'\tcheck_not_detached\n'>
        )
      }
    )
    (C {(test_expect_success)} {(SQ <'checkout --detach moves HEAD'>)} 
      {
        (SQ <'\n'> <'\treset &&\n'> <'\tgit checkout one &&\n'> <'\tgit checkout --detach two &&\n'> 
          <'\tgit diff --exit-code HEAD &&\n'> <'\tgit diff --exit-code two\n'>
        )
      }
    )
    (C {(test_expect_success)} {(SQ <'checkout warns on orphan commits'>)} 
      {
        (SQ <'\n'> <'\treset &&\n'> <'\tgit checkout --detach two &&\n'> <'\techo content >orphan &&\n'> 
          <'\tgit add orphan &&\n'> <'\tgit commit -a -m orphan1 &&\n'> <'\techo new content >orphan &&\n'> 
          <'\tgit commit -a -m orphan2 &&\n'> <'\torphan2=$(git rev-parse HEAD) &&\n'> <'\tgit checkout master 2>stderr\n'>
        )
      }
    )
    (C {(test_expect_success)} {(SQ <'checkout warns on orphan commits: output'>)} 
      {(SQ <'\n'> <'\tcheck_orphan_warning stderr "2 commits"\n'>)}
    )
    (C {(test_expect_success)} {(SQ <'checkout warns orphaning 1 of 2 commits'>)} 
      {(SQ <'\n'> <'\tgit checkout "$orphan2" &&\n'> <'\tgit checkout HEAD^ 2>stderr\n'>)}
    )
    (C {(test_expect_success)} {(SQ <'checkout warns orphaning 1 of 2 commits: output'>)} 
      {(SQ <'\n'> <'\tcheck_orphan_warning stderr "1 commit"\n'>)}
    )
    (C {(test_expect_success)} {(SQ <'checkout does not warn leaving ref tip'>)} 
      {
        (SQ <'\n'> <'\treset &&\n'> <'\tgit checkout --detach two &&\n'> 
          <'\tgit checkout master 2>stderr\n'>
        )
      }
    )
    (C {(test_expect_success)} {(SQ <'checkout does not warn leaving ref tip'>)} 
      {(SQ <'\n'> <'\tcheck_no_orphan_warning stderr\n'>)}
    )
    (C {(test_expect_success)} {(SQ <'checkout does not warn leaving reachable commit'>)} 
      {
        (SQ <'\n'> <'\treset &&\n'> <'\tgit checkout --detach HEAD^ &&\n'> 
          <'\tgit checkout master 2>stderr\n'>
        )
      }
    )
    (C {(test_expect_success)} {(SQ <'checkout does not warn leaving reachable commit'>)} 
      {(SQ <'\n'> <'\tcheck_no_orphan_warning stderr\n'>)}
    )
    (SimpleCommand
      words: [{(cat)}]
      redirects: [
        (Redir op_id:Redir_Great fd:-1 arg_word:{(expect)} spids:[443])
        (HereDoc
          op_id: Redir_DLess
          fd: -1
          body: 
            {("Your branch is behind 'master' by 1 commit, and can be fast-forwarded.\n") 
              ('  (use "git pull" to update your local branch)\n')
            }
          do_expansion: False
          here_end: EOF
          was_filled: True
          spids: [446]
        )
      ]
    )
    (C {(test_expect_success)} {(SQ <'tracking count is accurate after orphan check'>)} 
      {
        (SQ <'\n'> <'\treset &&\n'> <'\tgit branch child master^ &&\n'> 
          <'\tgit config branch.child.remote . &&\n'> <'\tgit config branch.child.merge refs/heads/master &&\n'> <'\tgit checkout child^ &&\n'> 
          <'\tgit checkout child >stdout &&\n'> <'\ttest_i18ncmp expect stdout\n'>
        )
      }
    )
    (C {(test_expect_success)} {(SQ <'no advice given for explicit detached head state'>)} 
      {
        (SQ <'\n'> <'\t# baseline\n'> <'\ttest_config advice.detachedHead true &&\n'> 
          <'\tgit checkout child && git checkout HEAD^0 >expect.advice 2>&1 &&\n'> <'\ttest_config advice.detachedHead false &&\n'> 
          <'\tgit checkout child && git checkout HEAD^0 >expect.no-advice 2>&1 &&\n'> <'\ttest_unconfig advice.detachedHead &&\n'> 
          <'\t# without configuration, the advice.* variables default to true\n'> <'\tgit checkout child && git checkout HEAD^0 >actual 2>&1 &&\n'> 
          <'\ttest_cmp expect.advice actual &&\n'> <'\n'> <'\t# with explicit --detach\n'> <'\t# no configuration\n'> 
          <'\ttest_unconfig advice.detachedHead &&\n'> <'\tgit checkout child && git checkout --detach HEAD^0 >actual 2>&1 &&\n'> 
          <'\ttest_cmp expect.no-advice actual &&\n'> <'\n'> <'\t# explicitly decline advice\n'> <'\ttest_config advice.detachedHead false &&\n'> 
          <'\tgit checkout child && git checkout --detach HEAD^0 >actual 2>&1 &&\n'> <'\ttest_cmp expect.no-advice actual\n'>
        )
      }
    )
    (C {(test_done)})
  ]
)