(command.CommandList
  children: [
    (command.ShAssignment
      pairs: [
        (assign_pair
          lhs: (sh_lhs_expr.Name name:test_description)
          op: assign_op.Equal
          rhs: {(SQ <'Test the update hook infrastructure.'>)}
          spids: [13]
        )
      ]
    )
    (C {<.>} {<'./test-lib.sh'>})
    (C {<test_expect_success>} {<setup>} 
      {
        (SQ <'\n'> <'\techo This is a test. >a &&\n'> <'\tgit update-index --add a &&\n'> 
          <'\ttree0=$(git write-tree) &&\n'> <'\tcommit0=$(echo setup | git commit-tree $tree0) &&\n'> <'\techo We hope it works. >a &&\n'> 
          <'\tgit update-index a &&\n'> <'\ttree1=$(git write-tree) &&\n'> 
          <'\tcommit1=$(echo modify | git commit-tree $tree1 -p $commit0) &&\n'> <'\tgit update-ref refs/heads/master $commit0 &&\n'> 
          <'\tgit update-ref refs/heads/tofail $commit1 &&\n'> <'\tgit clone --bare ./. victim.git &&\n'> 
          <'\tGIT_DIR=victim.git git update-ref refs/heads/tofail $commit1 &&\n'> <'\tgit update-ref refs/heads/master $commit1 &&\n'> <'\tgit update-ref refs/heads/tofail $commit0\n'>
        )
      }
    )
    (command.Simple
      words: [{<cat>}]
      redirects: [
        (redir
          op: <Id.Redir_Great '>'>
          loc: (redir_loc.Fd fd:1)
          arg: {<'victim.git/hooks/pre-receive'>}
        )
        (redir
          op: <Id.Redir_DLess '<<'>
          loc: (redir_loc.Fd fd:0)
          arg: 
            (redir_param.MultiLine
              here_begin: {(SQ <EOF>)}
              here_end_span_id: 61
              stdin_parts: [
                <'#!/bin/sh\n'>
                <'printf %s "$@" >>$GIT_DIR/pre-receive.args\n'>
                <'cat - >$GIT_DIR/pre-receive.stdin\n'>
                <'echo STDOUT pre-receive\n'>
                <'echo STDERR pre-receive >&2\n'>
              ]
            )
        )
      ]
      do_fork: T
    )
    (C {<chmod>} {<u> <Id.Lit_Other '+'> <x>} {<'victim.git/hooks/pre-receive'>})
    (command.Simple
      words: [{<cat>}]
      redirects: [
        (redir
          op: <Id.Redir_Great '>'>
          loc: (redir_loc.Fd fd:1)
          arg: {<'victim.git/hooks/update'>}
        )
        (redir
          op: <Id.Redir_DLess '<<'>
          loc: (redir_loc.Fd fd:0)
          arg: 
            (redir_param.MultiLine
              here_begin: {(SQ <EOF>)}
              here_end_span_id: 87
              stdin_parts: [
                <'#!/bin/sh\n'>
                <'echo "$@" >>$GIT_DIR/update.args\n'>
                <'read x; printf %s "$x" >$GIT_DIR/update.stdin\n'>
                <'echo STDOUT update $1\n'>
                <'echo STDERR update $1 >&2\n'>
                <'test "$1" = refs/heads/master || exit\n'>
              ]
            )
        )
      ]
      do_fork: T
    )
    (C {<chmod>} {<u> <Id.Lit_Other '+'> <x>} {<'victim.git/hooks/update'>})
    (command.Simple
      words: [{<cat>}]
      redirects: [
        (redir
          op: <Id.Redir_Great '>'>
          loc: (redir_loc.Fd fd:1)
          arg: {<'victim.git/hooks/post-receive'>}
        )
        (redir
          op: <Id.Redir_DLess '<<'>
          loc: (redir_loc.Fd fd:0)
          arg: 
            (redir_param.MultiLine
              here_begin: {(SQ <EOF>)}
              here_end_span_id: 112
              stdin_parts: [
                <'#!/bin/sh\n'>
                <'printf %s "$@" >>$GIT_DIR/post-receive.args\n'>
                <'cat - >$GIT_DIR/post-receive.stdin\n'>
                <'echo STDOUT post-receive\n'>
                <'echo STDERR post-receive >&2\n'>
              ]
            )
        )
      ]
      do_fork: T
    )
    (C {<chmod>} {<u> <Id.Lit_Other '+'> <x>} {<'victim.git/hooks/post-receive'>})
    (command.Simple
      words: [{<cat>}]
      redirects: [
        (redir
          op: <Id.Redir_Great '>'>
          loc: (redir_loc.Fd fd:1)
          arg: {<'victim.git/hooks/post-update'>}
        )
        (redir
          op: <Id.Redir_DLess '<<'>
          loc: (redir_loc.Fd fd:0)
          arg: 
            (redir_param.MultiLine
              here_begin: {(SQ <EOF>)}
              here_end_span_id: 137
              stdin_parts: [
                <'#!/bin/sh\n'>
                <'echo "$@" >>$GIT_DIR/post-update.args\n'>
                <'read x; printf %s "$x" >$GIT_DIR/post-update.stdin\n'>
                <'echo STDOUT post-update\n'>
                <'echo STDERR post-update >&2\n'>
              ]
            )
        )
      ]
      do_fork: T
    )
    (C {<chmod>} {<u> <Id.Lit_Other '+'> <x>} {<'victim.git/hooks/post-update'>})
    (C {<test_expect_success>} {<push>} 
      {
        (SQ <'\n'> <'\ttest_must_fail git send-pack --force ./victim.git \\\n'> 
          <'\t\tmaster tofail >send.out 2>send.err\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'updated as expected'>)} 
      {
        (SQ <'\n'> <'\ttest $(GIT_DIR=victim.git git rev-parse master) = $commit1 &&\n'> 
          <'\ttest $(GIT_DIR=victim.git git rev-parse tofail) = $commit1\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'hooks ran'>)} 
      {
        (SQ <'\n'> <'\ttest -f victim.git/pre-receive.args &&\n'> 
          <'\ttest -f victim.git/pre-receive.stdin &&\n'> <'\ttest -f victim.git/update.args &&\n'> <'\ttest -f victim.git/update.stdin &&\n'> 
          <'\ttest -f victim.git/post-receive.args &&\n'> <'\ttest -f victim.git/post-receive.stdin &&\n'> <'\ttest -f victim.git/post-update.args &&\n'> 
          <'\ttest -f victim.git/post-update.stdin\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'pre-receive hook input'>)} 
      {
        (SQ <'\n'> <'\t(echo $commit0 $commit1 refs/heads/master;\n'> 
          <'\t echo $commit1 $commit0 refs/heads/tofail\n'> <'\t) | test_cmp - victim.git/pre-receive.stdin\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'update hook arguments'>)} 
      {
        (SQ <'\n'> <'\t(echo refs/heads/master $commit0 $commit1;\n'> 
          <'\t echo refs/heads/tofail $commit1 $commit0\n'> <'\t) | test_cmp - victim.git/update.args\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'post-receive hook input'>)} 
      {
        (SQ <'\n'> <'\techo $commit0 $commit1 refs/heads/master |\n'> 
          <'\ttest_cmp - victim.git/post-receive.stdin\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'post-update hook arguments'>)} 
      {(SQ <'\n'> <'\techo refs/heads/master |\n'> <'\ttest_cmp - victim.git/post-update.args\n'>)}
    )
    (C {<test_expect_success>} {(SQ <'all hook stdin is /dev/null'>)} 
      {
        (SQ <'\n'> <'\t! test -s victim.git/update.stdin &&\n'> 
          <'\t! test -s victim.git/post-update.stdin\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'all *-receive hook args are empty'>)} 
      {
        (SQ <'\n'> <'\t! test -s victim.git/pre-receive.args &&\n'> 
          <'\t! test -s victim.git/post-receive.args\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'send-pack produced no output'>)} 
      {(SQ <'\n'> <'\t! test -s send.out\n'>)}
    )
    (command.Simple
      words: [{<cat>}]
      redirects: [
        (redir
          op: <Id.Redir_DLess '<<'>
          loc: (redir_loc.Fd fd:0)
          arg: 
            (redir_param.MultiLine
              here_begin: {<EOF>}
              here_end_span_id: 302
              stdin_parts: [
                <'remote: STDOUT pre-receive\n'>
                <'remote: STDERR pre-receive\n'>
                <'remote: STDOUT update refs/heads/master\n'>
                <'remote: STDERR update refs/heads/master\n'>
                <'remote: STDOUT update refs/heads/tofail\n'>
                <'remote: STDERR update refs/heads/tofail\n'>
                <'remote: error: hook declined to update refs/heads/tofail\n'>
                <'remote: STDOUT post-receive\n'>
                <'remote: STDERR post-receive\n'>
                <'remote: STDOUT post-update\n'>
                <'remote: STDERR post-update\n'>
              ]
            )
        )
        (redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<expect>})
      ]
      do_fork: T
    )
    (C {<test_expect_success>} {(SQ <'send-pack stderr contains hook messages'>)} 
      {
        (SQ <'\n'> <'\tgrep ^remote: send.err | sed "s/ *\\$//" >actual &&\n'> 
          <'\ttest_cmp expect actual\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'pre-receive hook that forgets to read its input'>)} 
      {
        (SQ <'\n'> <'\twrite_script victim.git/hooks/pre-receive <<-\\EOF &&\n'> <'\texit 0\n'> 
          <'\tEOF\n'> <'\trm -f victim.git/hooks/update victim.git/hooks/post-update &&\n'> <'\n'> 
          <'\tfor v in $(test_seq 100 999)\n'> <'\tdo\n'> <'\t\tgit branch branch_$v master || return\n'> <'\tdone &&\n'> 
          <'\tgit push ./victim.git "+refs/heads/*:refs/heads/*"\n'>
        )
      }
    )
    (C {<test_done>})
  ]
)