(command.CommandList
  children: [
    (command.ShAssignment
      pairs: [
        (assign_pair
          lhs: (sh_lhs_expr.Name name:test_description)
          op: assign_op.Equal
          rhs: {(SQ <'basic symbolic-ref tests'>)}
          spids: [4]
        )
      ]
    )
    (C {<.>} {<'./test-lib.sh'>})
    (command.ShFunction
      name: reset_to_sane
      body: 
        (BraceGroup
          children: [
            (command.Simple
              words: [{<echo>} {<ref> <Id.Lit_Colon ':'>} {<'refs/heads/foo'>}]
              redirects: [(redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<'.git/HEAD'>})]
              do_fork: T
            )
          ]
        )
    )
    (C {<test_expect_success>} {(SQ <'symbolic-ref writes HEAD'>)} 
      {
        (SQ <'\n'> <'\tgit symbolic-ref HEAD refs/heads/foo &&\n'> 
          <'\techo ref: refs/heads/foo >expect &&\n'> <'\ttest_cmp expect .git/HEAD\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'symbolic-ref reads HEAD'>)} 
      {
        (SQ <'\n'> <'\techo refs/heads/foo >expect &&\n'> <'\tgit symbolic-ref HEAD >actual &&\n'> 
          <'\ttest_cmp expect actual\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'symbolic-ref refuses non-ref for HEAD'>)} 
      {(SQ <'\n'> <'\ttest_must_fail git symbolic-ref HEAD foo\n'>)}
    )
    (C {<reset_to_sane>})
    (C {<test_expect_success>} {(SQ <'symbolic-ref refuses bare sha1'>)} 
      {
        (SQ <'\n'> <'\techo content >file && git add file && git commit -m one &&\n'> 
          <'\ttest_must_fail git symbolic-ref HEAD $(git rev-parse HEAD)\n'>
        )
      }
    )
    (C {<reset_to_sane>})
    (C {<test_expect_success>} {(SQ <'HEAD cannot be removed'>)} 
      {(SQ <'\n'> <'\ttest_must_fail git symbolic-ref -d HEAD\n'>)}
    )
    (C {<reset_to_sane>})
    (C {<test_expect_success>} {(SQ <'symbolic-ref can be deleted'>)} 
      {
        (SQ <'\n'> <'\tgit symbolic-ref NOTHEAD refs/heads/foo &&\n'> 
          <'\tgit symbolic-ref -d NOTHEAD &&\n'> <'\ttest_path_is_file .git/refs/heads/foo &&\n'> <'\ttest_path_is_missing .git/NOTHEAD\n'>
        )
      }
    )
    (C {<reset_to_sane>})
    (C {<test_expect_success>} {(SQ <'symbolic-ref can delete dangling symref'>)} 
      {
        (SQ <'\n'> <'\tgit symbolic-ref NOTHEAD refs/heads/missing &&\n'> 
          <'\tgit symbolic-ref -d NOTHEAD &&\n'> <'\ttest_path_is_missing .git/refs/heads/missing &&\n'> <'\ttest_path_is_missing .git/NOTHEAD\n'>
        )
      }
    )
    (C {<reset_to_sane>})
    (C {<test_expect_success>} {(SQ <'symbolic-ref fails to delete missing FOO'>)} 
      {
        (SQ <'\n'> <'\techo "fatal: Cannot delete FOO, not a symbolic ref" >expect &&\n'> 
          <'\ttest_must_fail git symbolic-ref -d FOO >actual 2>&1 &&\n'> <'\ttest_cmp expect actual\n'>
        )
      }
    )
    (C {<reset_to_sane>})
    (C {<test_expect_success>} {(SQ <'symbolic-ref fails to delete real ref'>)} 
      {
        (SQ <'\n'> <'\techo "fatal: Cannot delete refs/heads/foo, not a symbolic ref" >expect &&\n'> 
          <'\ttest_must_fail git symbolic-ref -d refs/heads/foo >actual 2>&1 &&\n'> <'\ttest_path_is_file .git/refs/heads/foo &&\n'> <'\ttest_cmp expect actual\n'>
        )
      }
    )
    (C {<reset_to_sane>})
    (C {<test_expect_success>} {(SQ <'create large ref name'>)} 
      {
        (SQ <'\n'> <'\t# make 256+ character ref; some systems may not handle that,\n'> 
          <'\t# so be gentle\n'> <'\tlong=0123456789abcdef &&\n'> <'\tlong=$long/$long/$long/$long &&\n'> 
          <'\tlong=$long/$long/$long/$long &&\n'> <'\tlong_ref=refs/heads/$long &&\n'> <'\ttree=$(git write-tree) &&\n'> 
          <'\tcommit=$(echo foo | git commit-tree $tree) &&\n'> <'\tif git update-ref $long_ref $commit; then\n'> <'\t\ttest_set_prereq LONG_REF\n'> <'\telse\n'> 
          <'\t\techo >&2 "long refs not supported"\n'> <'\tfi\n'>
        )
      }
    )
    (C {<test_expect_success>} {<LONG_REF>} {(SQ <'symbolic-ref can point to large ref name'>)} 
      {
        (SQ <'\n'> <'\tgit symbolic-ref HEAD $long_ref &&\n'> <'\techo $long_ref >expect &&\n'> 
          <'\tgit symbolic-ref HEAD >actual &&\n'> <'\ttest_cmp expect actual\n'>
        )
      }
    )
    (C {<test_expect_success>} {<LONG_REF>} {(SQ <'we can parse long symbolic ref'>)} 
      {
        (SQ <'\n'> <'\techo $commit >expect &&\n'> <'\tgit rev-parse --verify HEAD >actual &&\n'> 
          <'\ttest_cmp expect actual\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'symbolic-ref reports failure in exit code'>)} 
      {
        (SQ <'\n'> <'\ttest_when_finished "rm -f .git/HEAD.lock" &&\n'> <'\t>.git/HEAD.lock &&\n'> 
          <'\ttest_must_fail git symbolic-ref HEAD refs/heads/whatever\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'symbolic-ref writes reflog entry'>)} 
      {
        (SQ <'\n'> <'\tgit checkout -b log1 &&\n'> <'\ttest_commit one &&\n'> 
          <'\tgit checkout -b log2  &&\n'> <'\ttest_commit two &&\n'> <'\tgit checkout --orphan orphan &&\n'> 
          <'\tgit symbolic-ref -m create HEAD refs/heads/log1 &&\n'> <'\tgit symbolic-ref -m update HEAD refs/heads/log2 &&\n'> <'\tcat >expect <<-\\EOF &&\n'> 
          <'\tupdate\n'> <'\tcreate\n'> <'\tEOF\n'> <'\tgit log --format=%gs -g -2 >actual &&\n'> <'\ttest_cmp expect actual\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'symbolic-ref does not create ref d/f conflicts'>)} 
      {
        (SQ <'\n'> <'\tgit checkout -b df &&\n'> <'\ttest_commit df &&\n'> 
          <'\ttest_must_fail git symbolic-ref refs/heads/df/conflict refs/heads/df &&\n'> <'\tgit pack-refs --all --prune &&\n'> 
          <'\ttest_must_fail git symbolic-ref refs/heads/df/conflict refs/heads/df\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'symbolic-ref handles existing pointer to invalid name'>)} 
      {
        (SQ <'\n'> <'\thead=$(git rev-parse HEAD) &&\n'> 
          <'\tgit symbolic-ref HEAD refs/heads/outer &&\n'> <'\tgit update-ref refs/heads/outer/inner $head &&\n'> 
          <'\tgit symbolic-ref HEAD refs/heads/unrelated\n'>
        )
      }
    )
    (C {<test_done>})
  ]
)