(command.CommandList
  children: [
    (command.ShAssignment
      pairs: [
        (assign_pair
          lhs: (sh_lhs_expr.Name name:test_description)
          op: assign_op.Equal
          rhs: {(SQ <'see how we handle various forms of corruption'>)}
          spids: [4]
        )
      ]
    )
    (C {<.>} {<'./test-lib.sh'>})
    (command.ShFunction
      name: obj_to_file
      body: 
        (BraceGroup
          children: [
            (C {<echo>} 
              {
                (DQ 
                  (command_sub
                    left_token: <Id.Left_DollarParen '$('>
                    child: (C {<git>} {<rev-parse>} {<--git-dir>})
                  ) <'/objects/'> 
                  (command_sub
                    left_token: <Id.Left_DollarParen '$('>
                    child: 
                      (command.Pipeline
                        children: [
                          (C {<git>} {<rev-parse>} {(DQ ($ Id.VSub_Number '$1'))})
                          (C {<sed>} {(SQ <'s,..,&/,'>)})
                        ]
                        negated: F
                      )
                  )
                )
              }
            )
          ]
        )
    )
    (command.ShFunction
      name: corrupt_byte
      body: 
        (BraceGroup
          children: [
            (command.AndOr
              ops: [Id.Op_DAmp Id.Op_DAmp]
              children: [
                (command.ShAssignment
                  pairs: [
                    (assign_pair
                      lhs: (sh_lhs_expr.Name name:obj_file)
                      op: assign_op.Equal
                      rhs: 
                        {
                          (command_sub
                            left_token: <Id.Left_DollarParen '$('>
                            child: (C {<obj_to_file>} {(DQ ($ Id.VSub_Number '$1'))})
                          )
                        }
                      spids: [67]
                    )
                  ]
                )
                (C {<chmod>} {<Id.Lit_Other '+'> <w>} {(DQ ($ Id.VSub_DollarName '$obj_file'))})
                (command.Pipeline
                  children: [
                    (C {<printf>} {(SQ <'\\0'>)})
                    (C {<dd>} {<Id.Lit_VarLike 'of='> (DQ ($ Id.VSub_DollarName '$obj_file'))} 
                      {<Id.Lit_VarLike 'bs='> <1>} {<Id.Lit_VarLike 'seek='> (DQ ($ Id.VSub_Number '$2'))} {<Id.Lit_VarLike 'conv='> <notrunc>}
                    )
                  ]
                  negated: F
                )
              ]
            )
          ]
        )
    )
    (C {<test_expect_success>} {(SQ <'setup corrupt repo'>)} 
      {
        (SQ <'\n'> <'\tgit init bit-error &&\n'> <'\t(\n'> <'\t\tcd bit-error &&\n'> 
          <'\t\ttest_commit content &&\n'> <'\t\tcorrupt_byte HEAD:content.t 10\n'> <'\t)\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'setup repo with missing object'>)} 
      {
        (SQ <'\n'> <'\tgit init missing &&\n'> <'\t(\n'> <'\t\tcd missing &&\n'> 
          <'\t\ttest_commit content &&\n'> <'\t\trm -f "$(obj_to_file HEAD:content.t)"\n'> <'\t)\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'setup repo with misnamed object'>)} 
      {
        (SQ <'\n'> <'\tgit init misnamed &&\n'> <'\t(\n'> <'\t\tcd misnamed &&\n'> 
          <'\t\ttest_commit content &&\n'> <'\t\tgood=$(obj_to_file HEAD:content.t) &&\n'> 
          <'\t\tblob=$(echo corrupt | git hash-object -w --stdin) &&\n'> <'\t\tbad=$(obj_to_file $blob) &&\n'> <'\t\trm -f "$good" &&\n'> <'\t\tmv "$bad" "$good"\n'> <'\t)\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'streaming a corrupt blob fails'>)} 
      {
        (SQ <'\n'> <'\t(\n'> <'\t\tcd bit-error &&\n'> 
          <'\t\ttest_must_fail git cat-file blob HEAD:content.t\n'> <'\t)\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'read-tree -u detects bit-errors in blobs'>)} 
      {
        (SQ <'\n'> <'\t(\n'> <'\t\tcd bit-error &&\n'> <'\t\trm -f content.t &&\n'> 
          <'\t\ttest_must_fail git read-tree --reset -u HEAD\n'> <'\t)\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'read-tree -u detects missing objects'>)} 
      {
        (SQ <'\n'> <'\t(\n'> <'\t\tcd missing &&\n'> <'\t\trm -f content.t &&\n'> 
          <'\t\ttest_must_fail git read-tree --reset -u HEAD\n'> <'\t)\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'clone --no-local --bare detects corruption'>)} 
      {(SQ <'\n'> <'\ttest_must_fail git clone --no-local --bare bit-error corrupt-transport\n'>)}
    )
    (C {<test_expect_success>} {(SQ <'clone --no-local --bare detects missing object'>)} 
      {(SQ <'\n'> <'\ttest_must_fail git clone --no-local --bare missing missing-transport\n'>)}
    )
    (C {<test_expect_success>} {(SQ <'clone --no-local --bare detects misnamed object'>)} 
      {(SQ <'\n'> <'\ttest_must_fail git clone --no-local --bare misnamed misnamed-transport\n'>)}
    )
    (C {<test_expect_success>} {(SQ <'clone --local detects corruption'>)} 
      {(SQ <'\n'> <'\ttest_must_fail git clone --local bit-error corrupt-checkout\n'>)}
    )
    (C {<test_expect_success>} {(SQ <'error detected during checkout leaves repo intact'>)} 
      {(SQ <'\n'> <'\ttest_path_is_dir corrupt-checkout/.git\n'>)}
    )
    (C {<test_expect_success>} {(SQ <'clone --local detects missing objects'>)} 
      {(SQ <'\n'> <'\ttest_must_fail git clone --local missing missing-checkout\n'>)}
    )
    (C {<test_expect_failure>} {(SQ <'clone --local detects misnamed objects'>)} 
      {(SQ <'\n'> <'\ttest_must_fail git clone --local misnamed misnamed-checkout\n'>)}
    )
    (C {<test_done>})
  ]
)