(command.CommandList
  children: [
    (command.ShAssignment
      pairs: [
        (assign_pair
          lhs: (sh_lhs_expr.Name name:test_description)
          op: assign_op.Equal
          rhs: {(SQ <'Test prune and reflog expiration'>)}
          spids: [13]
        )
      ]
    )
    (C {<.>} {<'./test-lib.sh'>})
    (command.ShFunction
      name: check_have
      body: 
        (BraceGroup
          children: [
            (command.AndOr
              ops: [Id.Op_DAmp Id.Op_DAmp]
              children: [
                (command.ShAssignment
                  pairs: [
                    (assign_pair
                      lhs: (sh_lhs_expr.Name name:gaah)
                      op: assign_op.Equal
                      rhs: (word.Empty)
                      spids: [31]
                    )
                  ]
                )
                (command.ForEach
                  iter_name: N
                  iter_words: [{(DQ ($ Id.VSub_At '$@'))}]
                  do_arg_iter: F
                  body: 
                    (command.DoGroup
                      children: [
                        (command.AndOr
                          ops: [Id.Op_DAmp Id.Op_DPipe]
                          children: [
                            (C {<eval>} 
                              {
                                (DQ <'o='> (word_part.EscapedLiteral token:<Id.Lit_EscapedChar '\\$'>) 
                                  ($ Id.VSub_DollarName '$N')
                                )
                              }
                            )
                            (C {<git>} {<cat-file>} {<-t>} {($ Id.VSub_DollarName '$o')})
                            (BraceGroup
                              children: [
                                (C {<echo>} {<Gaah>} {($ Id.VSub_DollarName '$N')})
                                (command.ShAssignment
                                  pairs: [
                                    (assign_pair
                                      lhs: (sh_lhs_expr.Name name:gaah)
                                      op: assign_op.Equal
                                      rhs: {($ Id.VSub_DollarName '$N')}
                                      spids: [80]
                                    )
                                  ]
                                )
                                (command.ControlFlow
                                  token: <Id.ControlFlow_Break break>
                                )
                              ]
                            )
                          ]
                        )
                      ]
                    )
                )
                (C {<test>} {<-z>} {(DQ ($ Id.VSub_DollarName '$gaah'))})
              ]
            )
          ]
        )
    )
    (command.ShFunction
      name: check_fsck
      body: 
        (BraceGroup
          children: [
            (command.ShAssignment
              pairs: [
                (assign_pair
                  lhs: (sh_lhs_expr.Name name:output)
                  op: assign_op.Equal
                  rhs: 
                    {
                      (command_sub
                        left_token: <Id.Left_DollarParen '$('>
                        child: (C {<git>} {<fsck>} {<--full>})
                      )
                    }
                  spids: [114]
                )
              ]
            )
            (command.Case
              to_match: {(DQ ($ Id.VSub_Number '$1'))}
              arms: [
                (case_arm
                  pat_list: [{(SQ )}]
                  action: [(C {<test>} {<-z>} {(DQ ($ Id.VSub_DollarName '$output'))})]
                  spids: [133 135 146 -1]
                )
                (case_arm
                  pat_list: [{<Id.Lit_Star '*'>}]
                  action: [
                    (command.Pipeline
                      children: [
                        (C {<echo>} {(DQ ($ Id.VSub_DollarName '$output'))})
                        (C {<grep>} {(DQ ($ Id.VSub_Number '$1'))})
                      ]
                      negated: F
                    )
                  ]
                  spids: [149 150 167 -1]
                )
              ]
            )
          ]
        )
    )
    (command.ShFunction
      name: corrupt
      body: 
        (BraceGroup
          children: [
            (command.ShAssignment
              pairs: [
                (assign_pair
                  lhs: (sh_lhs_expr.Name name:aa)
                  op: assign_op.Equal
                  rhs: 
                    {
                      (braced_var_sub
                        token: <Id.VSub_Number 1>
                        suffix_op: 
                          (suffix_op.Unary
                            op_id: Id.VOp1_Percent
                            arg_word: {<'??????????????????????????????????????'>}
                          )
                      )
                    }
                  spids: [183]
                )
                (assign_pair
                  lhs: (sh_lhs_expr.Name name:zz)
                  op: assign_op.Equal
                  rhs: 
                    {
                      (braced_var_sub
                        token: <Id.VSub_Number 1>
                        suffix_op: (suffix_op.Unary op_id:Id.VOp1_Pound arg_word:{<'??'>})
                      )
                    }
                  spids: [190]
                )
              ]
            )
            (C {<mv>} 
              {<'.git/objects/'> ($ Id.VSub_DollarName '$aa') <'/'> ($ Id.VSub_DollarName '$zz')} {<'.git/'> ($ Id.VSub_DollarName '$aa') ($ Id.VSub_DollarName '$zz')}
            )
          ]
        )
    )
    (command.ShFunction
      name: recover
      body: 
        (BraceGroup
          children: [
            (command.ShAssignment
              pairs: [
                (assign_pair
                  lhs: (sh_lhs_expr.Name name:aa)
                  op: assign_op.Equal
                  rhs: 
                    {
                      (braced_var_sub
                        token: <Id.VSub_Number 1>
                        suffix_op: 
                          (suffix_op.Unary
                            op_id: Id.VOp1_Percent
                            arg_word: {<'??????????????????????????????????????'>}
                          )
                      )
                    }
                  spids: [220]
                )
                (assign_pair
                  lhs: (sh_lhs_expr.Name name:zz)
                  op: assign_op.Equal
                  rhs: 
                    {
                      (braced_var_sub
                        token: <Id.VSub_Number 1>
                        suffix_op: (suffix_op.Unary op_id:Id.VOp1_Pound arg_word:{<'??'>})
                      )
                    }
                  spids: [227]
                )
              ]
            )
            (C {<mkdir>} {<-p>} {<'.git/objects/'> ($ Id.VSub_DollarName '$aa')})
            (C {<mv>} {<'.git/'> ($ Id.VSub_DollarName '$aa') ($ Id.VSub_DollarName '$zz')} 
              {<'.git/objects/'> ($ Id.VSub_DollarName '$aa') <'/'> ($ Id.VSub_DollarName '$zz')}
            )
          ]
        )
    )
    (command.ShFunction
      name: check_dont_have
      body: 
        (BraceGroup
          children: [
            (command.AndOr
              ops: [Id.Op_DAmp]
              children: [
                (command.ShAssignment
                  pairs: [
                    (assign_pair
                      lhs: (sh_lhs_expr.Name name:gaah)
                      op: assign_op.Equal
                      rhs: (word.Empty)
                      spids: [265]
                    )
                  ]
                )
                (command.ForEach
                  iter_name: N
                  iter_words: [{(DQ ($ Id.VSub_At '$@'))}]
                  do_arg_iter: F
                  body: 
                    (command.DoGroup
                      children: [
                        (C {<eval>} 
                          {
                            (DQ <'o='> (word_part.EscapedLiteral token:<Id.Lit_EscapedChar '\\$'>) 
                              ($ Id.VSub_DollarName '$N')
                            )
                          }
                        )
                        (command.AndOr
                          ops: [Id.Op_DAmp]
                          children: [
                            (C {<git>} {<cat-file>} {<-t>} {($ Id.VSub_DollarName '$o')})
                            (BraceGroup
                              children: [
                                (C {<echo>} {<Gaah>} {($ Id.VSub_DollarName '$N')})
                                (command.ShAssignment
                                  pairs: [
                                    (assign_pair
                                      lhs: (sh_lhs_expr.Name name:gaah)
                                      op: assign_op.Equal
                                      rhs: {($ Id.VSub_DollarName '$N')}
                                      spids: [313]
                                    )
                                  ]
                                )
                                (command.ControlFlow
                                  token: <Id.ControlFlow_Break break>
                                )
                              ]
                            )
                          ]
                        )
                      ]
                    )
                )
              ]
            )
            (C {<test>} {<-z>} {(DQ ($ Id.VSub_DollarName '$gaah'))})
          ]
        )
    )
    (C {<test_expect_success>} {<setup>} 
      {
        (SQ <'\n'> <'\tmkdir -p A/B &&\n'> <'\techo rat >C &&\n'> <'\techo ox >A/D &&\n'> 
          <'\techo tiger >A/B/E &&\n'> <'\tgit add . &&\n'> <'\n'> <'\ttest_tick && git commit -m rabbit &&\n'> 
          <'\tH=$(git rev-parse --verify HEAD) &&\n'> <'\tA=$(git rev-parse --verify HEAD:A) &&\n'> <'\tB=$(git rev-parse --verify HEAD:A/B) &&\n'> 
          <'\tC=$(git rev-parse --verify HEAD:C) &&\n'> <'\tD=$(git rev-parse --verify HEAD:A/D) &&\n'> <'\tE=$(git rev-parse --verify HEAD:A/B/E) &&\n'> 
          <'\tcheck_fsck &&\n'> <'\n'> <'\ttest_chmod +x C &&\n'> <'\tgit add C &&\n'> <'\ttest_tick && git commit -m dragon &&\n'> 
          <'\tL=$(git rev-parse --verify HEAD) &&\n'> <'\tcheck_fsck &&\n'> <'\n'> <'\trm -f C A/B/E &&\n'> <'\techo snake >F &&\n'> <'\techo horse >A/G &&\n'> 
          <'\tgit add F A/G &&\n'> <'\ttest_tick && git commit -a -m sheep &&\n'> <'\tF=$(git rev-parse --verify HEAD:F) &&\n'> 
          <'\tG=$(git rev-parse --verify HEAD:A/G) &&\n'> <'\tI=$(git rev-parse --verify HEAD:A) &&\n'> <'\tJ=$(git rev-parse --verify HEAD) &&\n'> 
          <'\tcheck_fsck &&\n'> <'\n'> <'\trm -f A/G &&\n'> <'\ttest_tick && git commit -a -m monkey &&\n'> 
          <'\tK=$(git rev-parse --verify HEAD) &&\n'> <'\tcheck_fsck &&\n'> <'\n'> <'\tcheck_have A B C D E F G H I J K L &&\n'> <'\n'> <'\tgit prune &&\n'> 
          <'\n'> <'\tcheck_have A B C D E F G H I J K L &&\n'> <'\n'> <'\tcheck_fsck &&\n'> <'\n'> 
          <'\tgit reflog refs/heads/master >output &&\n'> <'\ttest_line_count = 4 output\n'>
        )
      }
    )
    (C {<test_expect_success>} {<rewind>} 
      {
        (SQ <'\n'> <'\ttest_tick && git reset --hard HEAD~2 &&\n'> <'\ttest -f C &&\n'> 
          <'\ttest -f A/B/E &&\n'> <'\t! test -f F &&\n'> <'\t! test -f A/G &&\n'> <'\n'> <'\tcheck_have A B C D E F G H I J K L &&\n'> 
          <'\n'> <'\tgit prune &&\n'> <'\n'> <'\tcheck_have A B C D E F G H I J K L &&\n'> <'\n'> 
          <'\tgit reflog refs/heads/master >output &&\n'> <'\ttest_line_count = 5 output\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'corrupt and check'>)} 
      {(SQ <'\n'> <'\n'> <'\tcorrupt $F &&\n'> <'\tcheck_fsck "missing blob $F"\n'> <'\n'>)}
    )
    (C {<test_expect_success>} {(SQ <'reflog expire --dry-run should not touch reflog'>)} 
      {
        (SQ <'\n'> <'\n'> <'\tgit reflog expire --dry-run \\\n'> 
          <'\t\t--expire=$(($test_tick - 10000)) \\\n'> <'\t\t--expire-unreachable=$(($test_tick - 10000)) \\\n'> <'\t\t--stale-fix \\\n'> <'\t\t--all &&\n'> 
          <'\n'> <'\tgit reflog refs/heads/master >output &&\n'> <'\ttest_line_count = 5 output &&\n'> <'\n'> 
          <'\tcheck_fsck "missing blob $F"\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'reflog expire'>)} 
      {
        (SQ <'\n'> <'\n'> <'\tgit reflog expire --verbose \\\n'> 
          <'\t\t--expire=$(($test_tick - 10000)) \\\n'> <'\t\t--expire-unreachable=$(($test_tick - 10000)) \\\n'> <'\t\t--stale-fix \\\n'> <'\t\t--all &&\n'> 
          <'\n'> <'\tgit reflog refs/heads/master >output &&\n'> <'\ttest_line_count = 2 output &&\n'> <'\n'> 
          <'\tcheck_fsck "dangling commit $K"\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'prune and fsck'>)} 
      {
        (SQ <'\n'> <'\n'> <'\tgit prune &&\n'> <'\tcheck_fsck &&\n'> <'\n'> 
          <'\tcheck_have A B C D E H L &&\n'> <'\tcheck_dont_have F G I J K\n'> <'\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'recover and check'>)} 
      {(SQ <'\n'> <'\n'> <'\trecover $F &&\n'> <'\tcheck_fsck "dangling blob $F"\n'> <'\n'>)}
    )
    (C {<test_expect_success>} {(SQ <delete>)} 
      {
        (SQ <'\n'> <'\techo 1 > C &&\n'> <'\ttest_tick &&\n'> <'\tgit commit -m rat C &&\n'> <'\n'> 
          <'\techo 2 > C &&\n'> <'\ttest_tick &&\n'> <'\tgit commit -m ox C &&\n'> <'\n'> <'\techo 3 > C &&\n'> <'\ttest_tick &&\n'> 
          <'\tgit commit -m tiger C &&\n'> <'\n'> <'\tHEAD_entry_count=$(git reflog | wc -l) &&\n'> 
          <'\tmaster_entry_count=$(git reflog show master | wc -l) &&\n'> <'\n'> <'\ttest $HEAD_entry_count = 5 &&\n'> <'\ttest $master_entry_count = 5 &&\n'> <'\n'> <'\n'> 
          <'\tgit reflog delete master@{1} &&\n'> <'\tgit reflog show master > output &&\n'> 
          <'\ttest $(($master_entry_count - 1)) = $(wc -l < output) &&\n'> <'\ttest $HEAD_entry_count = $(git reflog | wc -l) &&\n'> <'\t! grep ox < output &&\n'> <'\n'> 
          <'\tmaster_entry_count=$(wc -l < output) &&\n'> <'\n'> <'\tgit reflog delete HEAD@{1} &&\n'> 
          <'\ttest $(($HEAD_entry_count -1)) = $(git reflog | wc -l) &&\n'> <'\ttest $master_entry_count = $(git reflog show master | wc -l) &&\n'> <'\n'> 
          <'\tHEAD_entry_count=$(git reflog | wc -l) &&\n'> <'\n'> <'\tgit reflog delete master@{07.04.2005.15:15:00.-0700} &&\n'> 
          <'\tgit reflog show master > output &&\n'> <'\ttest $(($master_entry_count - 1)) = $(wc -l < output) &&\n'> <'\t! grep dragon < output\n'> <'\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <rewind2>)} 
      {
        (SQ <'\n'> <'\n'> <'\ttest_tick && git reset --hard HEAD~2 &&\n'> 
          <'\tgit reflog refs/heads/master >output &&\n'> <'\ttest_line_count = 4 output\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'--expire=never'>)} 
      {
        (SQ <'\n'> <'\n'> <'\tgit reflog expire --verbose \\\n'> <'\t\t--expire=never \\\n'> 
          <'\t\t--expire-unreachable=never \\\n'> <'\t\t--all &&\n'> <'\tgit reflog refs/heads/master >output &&\n'> <'\ttest_line_count = 4 output\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'gc.reflogexpire=never'>)} 
      {
        (SQ <'\n'> <'\n'> <'\tgit config gc.reflogexpire never &&\n'> 
          <'\tgit config gc.reflogexpireunreachable never &&\n'> <'\tgit reflog expire --verbose --all &&\n'> <'\tgit reflog refs/heads/master >output &&\n'> 
          <'\ttest_line_count = 4 output\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'gc.reflogexpire=false'>)} 
      {
        (SQ <'\n'> <'\n'> <'\tgit config gc.reflogexpire false &&\n'> 
          <'\tgit config gc.reflogexpireunreachable false &&\n'> <'\tgit reflog expire --verbose --all &&\n'> <'\tgit reflog refs/heads/master >output &&\n'> 
          <'\ttest_line_count = 4 output &&\n'> <'\n'> <'\tgit config --unset gc.reflogexpire &&\n'> 
          <'\tgit config --unset gc.reflogexpireunreachable\n'> <'\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'checkout should not delete log for packed ref'>)} 
      {
        (SQ <'\n'> <'\ttest $(git reflog master | wc -l) = 4 &&\n'> <'\tgit branch foo &&\n'> 
          <'\tgit pack-refs --all &&\n'> <'\tgit checkout foo &&\n'> <'\ttest $(git reflog master | wc -l) = 4\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'stale dirs do not cause d/f conflicts (reflogs on)'>)} 
      {
        (SQ <'\n'> <'\ttest_when_finished "git branch -d one || git branch -d one/two" &&\n'> <'\n'> 
          <'\tgit branch one/two master &&\n'> <'\techo "one/two@{0} branch: Created from master" >expect &&\n'> 
          <'\tgit log -g --format="%gd %gs" one/two >actual &&\n'> <'\ttest_cmp expect actual &&\n'> <'\tgit branch -d one/two &&\n'> <'\n'> 
          <'\t# now logs/refs/heads/one is a stale directory, but\n'> <'\t# we should move it out of the way to create "one" reflog\n'> <'\tgit branch one master &&\n'> 
          <'\techo "one@{0} branch: Created from master" >expect &&\n'> <'\tgit log -g --format="%gd %gs" one >actual &&\n'> <'\ttest_cmp expect actual\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'stale dirs do not cause d/f conflicts (reflogs off)'>)} 
      {
        (SQ <'\n'> <'\ttest_when_finished "git branch -d one || git branch -d one/two" &&\n'> <'\n'> 
          <'\tgit branch one/two master &&\n'> <'\techo "one/two@{0} branch: Created from master" >expect &&\n'> 
          <'\tgit log -g --format="%gd %gs" one/two >actual &&\n'> <'\ttest_cmp expect actual &&\n'> <'\tgit branch -d one/two &&\n'> <'\n'> 
          <'\t# same as before, but we only create a reflog for "one" if\n'> <'\t# it already exists, which it does not\n'> 
          <'\tgit -c core.logallrefupdates=false branch one master &&\n'> <'\t: >expect &&\n'> <'\tgit log -g --format="%gd %gs" one >actual &&\n'> 
          <'\ttest_cmp expect actual\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'parsing reverse reflogs at BUFSIZ boundaries'>)} 
      {
        (SQ <'\n'> <'\tgit checkout -b reflogskip &&\n'> 
          <'\tz38=00000000000000000000000000000000000000 &&\n'> <'\tident="abc <xyz> 0000000001 +0000" &&\n'> <'\tfor i in $(test_seq 1 75); do\n'> 
          <'\t\tprintf "$z38%02d $z38%02d %s\\t" $i $(($i+1)) "$ident" &&\n'> <'\t\tif test $i = 75; then\n'> <'\t\t\tfor j in $(test_seq 1 89); do\n'> <'\t\t\t\tprintf X\n'> 
          <'\t\t\tdone\n'> <'\t\telse\n'> <'\t\t\tprintf X\n'> <'\t\tfi &&\n'> <'\t\tprintf "\\n"\n'> 
          <'\tdone >.git/logs/refs/heads/reflogskip &&\n'> <'\tgit rev-parse reflogskip@{73} >actual &&\n'> <'\techo ${z38}03 >expect &&\n'> 
          <'\ttest_cmp expect actual\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'no segfaults for reflog containing non-commit sha1s'>)} 
      {
        (SQ <'\n'> <'\tgit update-ref --create-reflog -m "Creating ref" \\\n'> 
          <'\t\trefs/tests/tree-in-reflog HEAD &&\n'> <'\tgit update-ref -m "Forcing tree" refs/tests/tree-in-reflog HEAD^{tree} &&\n'> 
          <'\tgit update-ref -m "Restoring to commit" refs/tests/tree-in-reflog HEAD &&\n'> <'\tgit reflog refs/tests/tree-in-reflog\n'>
        )
      }
    )
    (C {<test_expect_failure>} {(SQ <'reflog with non-commit entries displays all entries'>)} 
      {
        (SQ <'\n'> <'\tgit reflog refs/tests/tree-in-reflog >actual &&\n'> 
          <'\ttest_line_count = 3 actual\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'reflog expire operates on symref not referrent'>)} 
      {
        (SQ <'\n'> <'\tgit branch -l the_symref &&\n'> <'\tgit branch -l referrent &&\n'> 
          <'\tgit update-ref referrent HEAD &&\n'> <'\tgit symbolic-ref refs/heads/the_symref refs/heads/referrent &&\n'> 
          <'\ttest_when_finished "rm -f .git/refs/heads/referrent.lock" &&\n'> <'\ttouch .git/refs/heads/referrent.lock &&\n'> <'\tgit reflog expire --expire=all the_symref\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'continue walking past root commits'>)} 
      {
        (SQ <'\n'> <'\tgit init orphanage &&\n'> <'\t(\n'> <'\t\tcd orphanage &&\n'> 
          <'\t\tcat >expect <<-\\EOF &&\n'> <'\t\tHEAD@{0} commit (initial): orphan2-1\n'> <'\t\tHEAD@{1} commit: orphan1-2\n'> 
          <'\t\tHEAD@{2} commit (initial): orphan1-1\n'> <'\t\tHEAD@{3} commit (initial): initial\n'> <'\t\tEOF\n'> <'\t\ttest_commit initial &&\n'> 
          <'\t\tgit checkout --orphan orphan1 &&\n'> <'\t\ttest_commit orphan1-1 &&\n'> <'\t\ttest_commit orphan1-2 &&\n'> 
          <'\t\tgit checkout --orphan orphan2 &&\n'> <'\t\ttest_commit orphan2-1 &&\n'> <'\t\tgit log -g --format="%gd %gs" >actual &&\n'> 
          <'\t\ttest_cmp expect actual\n'> <'\t)\n'>
        )
      }
    )
    (C {<test_done>})
  ]
)