(command.CommandList
  children: [
    (command.ShAssignment
      pairs: [
        (assign_pair
          lhs: (sh_lhs_expr.Name name:test_description)
          op: assign_op.Equal
          rhs: {(SQ <'test clone --reference'>)}
          spids: [13]
        )
      ]
    )
    (C {<.>} {<'./test-lib.sh'>})
    (command.ShAssignment
      pairs: [
        (assign_pair
          lhs: (sh_lhs_expr.Name name:base_dir)
          op: assign_op.Equal
          rhs: {(command_sub left_token:<Id.Left_DollarParen '$('> child:(C {<pwd>}))}
          spids: [23]
        )
      ]
    )
    (command.ShAssignment
      pairs: [
        (assign_pair
          lhs: (sh_lhs_expr.Name name:U)
          op: assign_op.Equal
          rhs: {($ Id.VSub_DollarName '$base_dir') <'/UPLOAD_LOG'>}
          spids: [29]
        )
      ]
    )
    (command.ShFunction
      name: commit_in
      body: 
        (BraceGroup
          children: [
            (command.Subshell
              child: 
                (command.AndOr
                  ops: [Id.Op_DAmp Id.Op_DAmp Id.Op_DAmp]
                  children: [
                    (C {<cd>} {(DQ ($ Id.VSub_Number '$1'))})
                    (command.Simple
                      words: [{<echo>} {(DQ ($ Id.VSub_Number '$2'))}]
                      redirects: [
                        (redir
                          op: <Id.Redir_Great '>'>
                          loc: (redir_loc.Fd fd:1)
                          arg: {(DQ ($ Id.VSub_Number '$2'))}
                        )
                      ]
                      do_fork: T
                    )
                    (C {<git>} {<add>} {(DQ ($ Id.VSub_Number '$2'))})
                    (C {<git>} {<commit>} {<-m>} {(DQ ($ Id.VSub_Number '$2'))})
                  ]
                )
            )
          ]
        )
    )
    (command.ShFunction
      name: test_objcount
      body: 
        (BraceGroup
          children: [
            (command.AndOr
              ops: [Id.Op_DAmp Id.Op_DAmp Id.Op_DAmp]
              children: [
                (command.Simple
                  words: [{<echo>} {(DQ ($ Id.VSub_Number '$2'))}]
                  redirects: [(redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<expect>})]
                  do_fork: T
                )
                (command.Simple
                  words: [{<git>} {<-C>} {(DQ ($ Id.VSub_Number '$1'))} {<count-objects>}]
                  redirects: [
                    (redir
                      op: <Id.Redir_Great '>'>
                      loc: (redir_loc.Fd fd:1)
                      arg: {<actual.raw>}
                    )
                  ]
                  do_fork: T
                )
                (command.Simple
                  words: [{<cut>} {<-d> (SQ <' '>)} {<-f1>}]
                  redirects: [
                    (redir
                      op: <Id.Redir_Less '<'>
                      loc: (redir_loc.Fd fd:0)
                      arg: {<actual.raw>}
                    )
                    (redir
                      op: <Id.Redir_Great '>'>
                      loc: (redir_loc.Fd fd:1)
                      arg: {<actual>}
                    )
                  ]
                  do_fork: T
                )
                (C {<test_cmp>} {<expect>} {<actual>})
              ]
            )
          ]
        )
    )
    (C {<test_expect_success>} {(SQ <'preparing first repository'>)} 
      {(SQ <'\n'> <'\ttest_create_repo A &&\n'> <'\tcommit_in A file1\n'>)}
    )
    (C {<test_expect_success>} {(SQ <'preparing second repository'>)} 
      {
        (SQ <'\n'> <'\tgit clone A B &&\n'> <'\tcommit_in B file2 &&\n'> <'\tgit -C B repack -ad &&\n'> 
          <'\tgit -C B prune\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'cloning with reference (-l -s)'>)} 
      {(SQ <'\n'> <'\tgit clone -l -s --reference B A C\n'>)}
    )
    (C {<test_expect_success>} {(SQ <'existence of info/alternates'>)} 
      {(SQ <'\n'> <'\ttest_line_count = 2 C/.git/objects/info/alternates\n'>)}
    )
    (C {<test_expect_success>} {(SQ <'pulling from reference'>)} 
      {(SQ <'\n'> <'\tgit -C C pull ../B master\n'>)}
    )
    (C {<test_expect_success>} {(SQ <'that reference gets used'>)} 
      {(SQ <'\n'> <'\ttest_objcount C 0\n'>)}
    )
    (C {<test_expect_success>} {(SQ <'cloning with reference (no -l -s)'>)} 
      {(SQ <'\n'> <'\tGIT_TRACE_PACKET=$U.D git clone --reference B "file://$(pwd)/A" D\n'>)}
    )
    (C {<test_expect_success>} {(SQ <'fetched no objects'>)} 
      {(SQ <'\n'> <'\ttest -s "$U.D" &&\n'> <'\t! grep " want" "$U.D"\n'>)}
    )
    (C {<test_expect_success>} {(SQ <'existence of info/alternates'>)} 
      {(SQ <'\n'> <'\ttest_line_count = 1 D/.git/objects/info/alternates\n'>)}
    )
    (C {<test_expect_success>} {(SQ <'pulling from reference'>)} 
      {(SQ <'\n'> <'\tgit -C D pull ../B master\n'>)}
    )
    (C {<test_expect_success>} {(SQ <'that reference gets used'>)} 
      {(SQ <'\n'> <'\ttest_objcount D 0\n'>)}
    )
    (C {<test_expect_success>} {(SQ <'updating origin'>)} 
      {(SQ <'\n'> <'\tcommit_in A file3 &&\n'> <'\tgit -C A repack -ad &&\n'> <'\tgit -C A prune\n'>)}
    )
    (C {<test_expect_success>} {(SQ <'pulling changes from origin'>)} 
      {(SQ <'\n'> <'\tgit -C C pull origin\n'>)}
    )
    (C {<test_expect_success>} {(SQ <'that alternate to origin gets used'>)} 
      {(SQ <'\n'> <'\ttest_objcount C 2\n'>)}
    )
    (C {<test_expect_success>} {(SQ <'pulling changes from origin'>)} 
      {(SQ <'\n'> <'\tgit -C D pull origin\n'>)}
    )
    (C {<test_expect_success>} {(SQ <'check objects expected to exist locally'>)} 
      {(SQ <'\n'> <'\ttest_objcount D 5\n'>)}
    )
    (C {<test_expect_success>} {(SQ <'preparing alternate repository #1'>)} 
      {(SQ <'\n'> <'\ttest_create_repo F &&\n'> <'\tcommit_in F file1\n'>)}
    )
    (C {<test_expect_success>} {(SQ <'cloning alternate repo #2 and adding changes to repo #1'>)} 
      {(SQ <'\n'> <'\tgit clone F G &&\n'> <'\tcommit_in F file2\n'>)}
    )
    (C {<test_expect_success>} {(SQ <'cloning alternate repo #1, using #2 as reference'>)} 
      {(SQ <'\n'> <'\tgit clone --reference G F H\n'>)}
    )
    (C {<test_expect_success>} {(SQ <'cloning with reference being subset of source (-l -s)'>)} 
      {(SQ <'\n'> <'\tgit clone -l -s --reference A B E\n'>)}
    )
    (C {<test_expect_success>} {(SQ <'cloning with multiple references drops duplicates'>)} 
      {
        (SQ <'\n'> <'\tgit clone -s --reference B --reference A --reference B A dups &&\n'> 
          <'\ttest_line_count = 2 dups/.git/objects/info/alternates\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'clone with reference from a tagged repository'>)} 
      {
        (SQ <'\n'> <'\t(\n'> <'\t\tcd A && git tag -a -m tagged HEAD\n'> <'\t) &&\n'> 
          <'\tgit clone --reference=A A I\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'prepare branched repository'>)} 
      {
        (SQ <'\n'> <'\tgit clone A J &&\n'> <'\t(\n'> <'\t\tcd J &&\n'> 
          <'\t\tgit checkout -b other master^ &&\n'> <'\t\techo other >otherfile &&\n'> <'\t\tgit add otherfile &&\n'> <'\t\tgit commit -m other &&\n'> 
          <'\t\tgit checkout master\n'> <'\t)\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'fetch with incomplete alternates'>)} 
      {
        (SQ <'\n'> <'\tgit init K &&\n'> 
          <'\techo "$base_dir/A/.git/objects" >K/.git/objects/info/alternates &&\n'> <'\t(\n'> <'\t\tcd K &&\n'> <'\t\tgit remote add J "file://$base_dir/J" &&\n'> 
          <'\t\tGIT_TRACE_PACKET=$U.K git fetch J\n'> <'\t) &&\n'> 
          <
'\tmaster_object=$(cd A && git for-each-ref --format="%(objectname)" refs/heads/master) &&\n'
          > <'\ttest -s "$U.K" &&\n'> <'\t! grep " want $master_object" "$U.K" &&\n'> 
          <'\ttag_object=$(cd A && git for-each-ref --format="%(objectname)" refs/tags/HEAD) &&\n'> <'\t! grep " want $tag_object" "$U.K"\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'clone using repo with gitfile as a reference'>)} 
      {
        (SQ <'\n'> <'\tgit clone --separate-git-dir=L A M &&\n'> <'\tgit clone --reference=M A N &&\n'> 
          <'\techo "$base_dir/L/objects" >expected &&\n'> <'\ttest_cmp expected "$base_dir/N/.git/objects/info/alternates"\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'clone using repo pointed at by gitfile as reference'>)} 
      {
        (SQ <'\n'> <'\tgit clone --reference=M/.git A O &&\n'> 
          <'\techo "$base_dir/L/objects" >expected &&\n'> <'\ttest_cmp expected "$base_dir/O/.git/objects/info/alternates"\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'clone and dissociate from reference'>)} 
      {
        (SQ <'\n'> <'\tgit init P &&\n'> <'\t(\n'> <'\t\tcd P &&\ttest_commit one\n'> <'\t) &&\n'> 
          <'\tgit clone P Q &&\n'> <'\t(\n'> <'\t\tcd Q && test_commit two\n'> <'\t) &&\n'> 
          <'\tgit clone --no-local --reference=P Q R &&\n'> <'\tgit clone --no-local --reference=P --dissociate Q S &&\n'> 
          <'\t# removing the reference P would corrupt R but not S\n'> <'\trm -fr P &&\n'> <'\ttest_must_fail git -C R fsck &&\n'> <'\tgit -C S fsck\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'clone, dissociate from partial reference and repack'>)} 
      {
        (SQ <'\n'> <'\trm -fr P Q R &&\n'> <'\tgit init P &&\n'> <'\t(\n'> <'\t\tcd P &&\n'> 
          <'\t\ttest_commit one &&\n'> <'\t\tgit repack &&\n'> <'\t\ttest_commit two &&\n'> <'\t\tgit repack\n'> <'\t) &&\n'> 
          <'\tgit clone --bare P Q &&\n'> <'\t(\n'> <'\t\tcd P &&\n'> <'\t\tgit checkout -b second &&\n'> <'\t\ttest_commit three &&\n'> 
          <'\t\tgit repack\n'> <'\t) &&\n'> <'\tgit clone --bare --dissociate --reference=P Q R &&\n'> 
          <'\tls R/objects/pack/*.pack >packs.txt &&\n'> <'\ttest_line_count = 1 packs.txt\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'clone, dissociate from alternates'>)} 
      {
        (SQ <'\n'> <'\trm -fr A B C &&\n'> <'\ttest_create_repo A &&\n'> <'\tcommit_in A file1 &&\n'> 
          <'\tgit clone --reference=A A B &&\n'> <'\ttest_line_count = 1 B/.git/objects/info/alternates &&\n'> 
          <'\tgit clone --local --dissociate B C &&\n'> <'\t! test -f C/.git/objects/info/alternates &&\n'> <'\t( cd C && git fsck )\n'>
        )
      }
    )
    (C {<test_done>})
  ]
)