(command.CommandList
  children: [
    (command.ShAssignment
      pairs: [
        (assign_pair
          lhs: (sh_lhs_expr.Name name:test_description)
          op: assign_op.Equal
          rhs: {(SQ <'Test shared repository initialization'>)}
          spids: [13]
        )
      ]
    )
    (C {<.>} {<'./test-lib.sh'>})
    (command.Simple
      words: [{<setfacl>} {<-k>} {<.>}]
      redirects: [(redir op:<Id.Redir_Great '2>'> loc:(redir_loc.Fd fd:2) arg:{<'/dev/null'>})]
      do_fork: T
    )
    (C {<test_expect_success>} {(SQ <'shared = 0400 (faulty permission u-w)'>)} 
      {
        (SQ <'\n'> <'\ttest_when_finished "rm -rf sub" &&\n'> <'\tmkdir sub && (\n'> <'\t\tcd sub &&\n'> 
          <'\t\ttest_must_fail git init --shared=0400\n'> <'\t)\n'>
        )
      }
    )
    (command.ShFunction
      name: modebits
      body: 
        (BraceGroup
          children: [
            (command.Pipeline
              children: [
                (C {<ls>} {<-l>} {(DQ ($ Id.VSub_Number '$1'))})
                (C {<sed>} {<-e>} {(SQ <'s|^\\(..........\\).*|\\1|'>)})
              ]
              negated: F
            )
          ]
        )
    )
    (command.ForEach
      iter_name: u
      iter_words: [{<002>} {<022>}]
      do_arg_iter: F
      body: 
        (command.DoGroup
          children: [
            (C {<test_expect_success>} {<POSIXPERM>} 
              {(DQ <'shared=1 does not clear bits preset by umask '> ($ Id.VSub_DollarName '$u'))} 
              {
                (SQ <'\n'> <'\t\tmkdir sub && (\n'> <'\t\t\tcd sub &&\n'> <'\t\t\tumask $u &&\n'> 
                  <'\t\t\tgit init --shared=1 &&\n'> <'\t\t\ttest 1 = "$(git config core.sharedrepository)"\n'> <'\t\t) &&\n'> 
                  <'\t\tactual=$(ls -l sub/.git/HEAD) &&\n'> <'\t\tcase "$actual" in\n'> <'\t\t-rw-rw-r--*)\n'> <'\t\t\t: happy\n'> <'\t\t\t;;\n'> <'\t\t*)\n'> 
                  <'\t\t\techo Oops, .git/HEAD is not 0664 but $actual\n'> <'\t\t\tfalse\n'> <'\t\t\t;;\n'> <'\t\tesac\n'> <'\t'>
                )
              }
            )
            (C {<rm>} {<-rf>} {<sub>})
          ]
        )
    )
    (C {<test_expect_success>} {(SQ <'shared=all'>)} 
      {
        (SQ <'\n'> <'\tmkdir sub &&\n'> <'\tcd sub &&\n'> <'\tgit init --shared=all &&\n'> 
          <'\ttest 2 = $(git config core.sharedrepository)\n'>
        )
      }
    )
    (C {<test_expect_success>} {<POSIXPERM>} {(SQ <'update-server-info honors core.sharedRepository'>)} 
      {
        (SQ <'\n'> <'\t: > a1 &&\n'> <'\tgit add a1 &&\n'> <'\ttest_tick &&\n'> 
          <'\tgit commit -m a1 &&\n'> <'\tumask 0277 &&\n'> <'\tgit update-server-info &&\n'> <'\tactual="$(ls -l .git/info/refs)" &&\n'> 
          <'\tcase "$actual" in\n'> <'\t-r--r--r--*)\n'> <'\t\t: happy\n'> <'\t\t;;\n'> <'\t*)\n'> 
          <'\t\techo Oops, .git/info/refs is not 0444\n'> <'\t\tfalse\n'> <'\t\t;;\n'> <'\tesac\n'>
        )
      }
    )
    (command.ForEach
      iter_name: u
      iter_words: [
        {<0660> <Id.Lit_Colon ':'> <rw-rw---->}
        {<0640> <Id.Lit_Colon ':'> <rw-r----->}
        {<0600> <Id.Lit_Colon ':'> <rw------->}
        {<0666> <Id.Lit_Colon ':'> <rw-rw-rw->}
        {<0664> <Id.Lit_Colon ':'> <rw-rw-r-->}
      ]
      do_arg_iter: F
      body: 
        (command.DoGroup
          children: [
            (command.AndOr
              ops: [Id.Op_DAmp Id.Op_DAmp Id.Op_DAmp Id.Op_DAmp Id.Op_DAmp]
              children: [
                (command.ShAssignment
                  pairs: [
                    (assign_pair
                      lhs: (sh_lhs_expr.Name name:x)
                      op: assign_op.Equal
                      rhs: 
                        {
                          (command_sub
                            left_token: <Id.Left_DollarParen '$('>
                            child: 
                              (C {<expr>} {(DQ ($ Id.VSub_DollarName '$u'))} {<Id.Lit_Colon ':'>} 
                                {
                                  (DQ <'.*:'> <Id.Lit_Other '\\'> <'([rw-]*'> <Id.Lit_Other '\\'> <')'>)
                                }
                              )
                          )
                        }
                      spids: [219]
                    )
                  ]
                )
                (command.ShAssignment
                  pairs: [
                    (assign_pair
                      lhs: (sh_lhs_expr.Name name:y)
                      op: assign_op.Equal
                      rhs: 
                        {
                          (command_sub
                            left_token: <Id.Left_DollarParen '$('>
                            child: 
                              (command.Pipeline
                                children: [
                                  (C {<echo>} {(DQ ($ Id.VSub_DollarName '$x'))})
                                  (C {<sed>} {<-e>} {(DQ <'s/w/-/g'>)})
                                ]
                                negated: F
                              )
                          )
                        }
                      spids: [241]
                    )
                  ]
                )
                (command.ShAssignment
                  pairs: [
                    (assign_pair
                      lhs: (sh_lhs_expr.Name name:u)
                      op: assign_op.Equal
                      rhs: 
                        {
                          (command_sub
                            left_token: <Id.Left_DollarParen '$('>
                            child: 
                              (C {<expr>} {(DQ ($ Id.VSub_DollarName '$u'))} {<Id.Lit_Colon ':'>} 
                                {(DQ <Id.Lit_Other '\\'> <'([0-7]*'> <Id.Lit_Other '\\'> <')'>)}
                              )
                          )
                        }
                      spids: [263]
                    )
                  ]
                )
                (C {<git>} {<config>} {<core.sharedrepository>} {(DQ ($ Id.VSub_DollarName '$u'))})
                (C {<umask>} {<0277>})
                (C {<test_expect_success>} {<POSIXPERM>} 
                  {
                    (DQ <'shared = '> ($ Id.VSub_DollarName '$u') <' ('> ($ Id.VSub_DollarName '$y') 
                      <') ro'>
                    )
                  } 
                  {
                    (SQ <'\n'> <'\n'> <'\t\trm -f .git/info/refs &&\n'> 
                      <'\t\tgit update-server-info &&\n'> <'\t\tactual="$(modebits .git/info/refs)" &&\n'> <'\t\tverbose test "x$actual" = "x-$y"\n'> <'\n'> 
                      <'\t'>
                    )
                  }
                )
              ]
            )
            (command.AndOr
              ops: [Id.Op_DAmp]
              children: [
                (C {<umask>} {<077>})
                (C {<test_expect_success>} {<POSIXPERM>} 
                  {
                    (DQ <'shared = '> ($ Id.VSub_DollarName '$u') <' ('> ($ Id.VSub_DollarName '$x') 
                      <') rw'>
                    )
                  } 
                  {
                    (SQ <'\n'> <'\n'> <'\t\trm -f .git/info/refs &&\n'> 
                      <'\t\tgit update-server-info &&\n'> <'\t\tactual="$(modebits .git/info/refs)" &&\n'> <'\t\tverbose test "x$actual" = "x-$x"\n'> <'\n'> 
                      <'\t'>
                    )
                  }
                )
              ]
            )
          ]
        )
    )
    (C {<test_expect_success>} {<POSIXPERM>} {(SQ <'info/refs respects umask in unshared repo'>)} 
      {
        (SQ <'\n'> <'\trm -f .git/info/refs &&\n'> <'\ttest_unconfig core.sharedrepository &&\n'> 
          <'\tumask 002 &&\n'> <'\tgit update-server-info &&\n'> <'\techo "-rw-rw-r--" >expect &&\n'> 
          <'\tmodebits .git/info/refs >actual &&\n'> <'\ttest_cmp expect actual\n'>
        )
      }
    )
    (C {<test_expect_success>} {<POSIXPERM>} {(SQ <'git reflog expire honors core.sharedRepository'>)} 
      {
        (SQ <'\n'> <'\tumask 077 &&\n'> <'\tgit config core.sharedRepository group &&\n'> 
          <'\tgit reflog expire --all &&\n'> <'\tactual="$(ls -l .git/logs/refs/heads/master)" &&\n'> <'\tcase "$actual" in\n'> <'\t-rw-rw-*)\n'> 
          <'\t\t: happy\n'> <'\t\t;;\n'> <'\t*)\n'> <'\t\techo Ooops, .git/logs/refs/heads/master is not 0662 [$actual]\n'> 
          <'\t\tfalse\n'> <'\t\t;;\n'> <'\tesac\n'>
        )
      }
    )
    (C {<test_expect_success>} {<POSIXPERM>} {(SQ <'forced modes'>)} 
      {
        (SQ <'\n'> <'\tmkdir -p templates/hooks &&\n'> 
          <'\techo update-server-info >templates/hooks/post-update &&\n'> <'\tchmod +x templates/hooks/post-update &&\n'> <'\techo : >random-file &&\n'> <'\tmkdir new &&\n'> 
          <'\t(\n'> <'\t\tcd new &&\n'> <'\t\tumask 002 &&\n'> <'\t\tgit init --shared=0660 --template=../templates &&\n'> 
          <'\t\t>frotz &&\n'> <'\t\tgit add frotz &&\n'> <'\t\tgit commit -a -m initial &&\n'> <'\t\tgit repack\n'> <'\t) &&\n'> 
          <'\t# List repository files meant to be protected; note that\n'> <'\t# COMMIT_EDITMSG does not matter---0mode is not about a\n'> <'\t# repository with a work tree.\n'> 
          <'\tfind new/.git -type f -name COMMIT_EDITMSG -prune -o -print |\n'> <'\txargs ls -ld >actual &&\n'> <'\n'> <'\t# Everything must be unaccessible to others\n'> 
          <'\ttest -z "$(sed -e "/^.......---/d" actual)" &&\n'> <'\n'> <'\t# All directories must have either 2770 or 770\n'> 
          <'\ttest -z "$(sed -n -e "/^drwxrw[sx]---/d" -e "/^d/p" actual)" &&\n'> <'\n'> <'\t# post-update hook must be 0770\n'> <'\ttest -z "$(sed -n -e "/post-update/{\n'> 
          <'\t\t/^-rwxrwx---/d\n'> <'\t\tp\n'> <'\t}" actual)" &&\n'> <'\n'> <'\t# All files inside objects must be accessible by us\n'> 
          <'\ttest -z "$(sed -n -e "/objects\\//{\n'> <'\t\t/^d/d\n'> <'\t\t/^-r.-r.----/d\n'> <'\t\tp\n'> <'\t}" actual)"\n'>
        )
      }
    )
    (C {<test_expect_success>} {<POSIXPERM>} {(SQ <'remote init does not use config from cwd'>)} 
      {
        (SQ <'\n'> <'\tgit config core.sharedrepository 0666 &&\n'> <'\tumask 0022 &&\n'> 
          <'\tgit init --bare child.git &&\n'> <'\techo "-rw-r--r--" >expect &&\n'> <'\tmodebits child.git/config >actual &&\n'> 
          <'\ttest_cmp expect actual\n'>
        )
      }
    )
    (C {<test_expect_success>} {<POSIXPERM>} {(SQ <'re-init respects core.sharedrepository (local)'>)} 
      {
        (SQ <'\n'> <'\tgit config core.sharedrepository 0666 &&\n'> <'\tumask 0022 &&\n'> 
          <'\techo whatever >templates/foo &&\n'> <'\tgit init --template=templates &&\n'> <'\techo "-rw-rw-rw-" >expect &&\n'> 
          <'\tmodebits .git/foo >actual &&\n'> <'\ttest_cmp expect actual\n'>
        )
      }
    )
    (C {<test_expect_success>} {<POSIXPERM>} {(SQ <'re-init respects core.sharedrepository (remote)'>)} 
      {
        (SQ <'\n'> <'\trm -rf child.git &&\n'> <'\tumask 0022 &&\n'> 
          <'\tgit init --bare --shared=0666 child.git &&\n'> <'\ttest_path_is_missing child.git/foo &&\n'> 
          <'\tgit init --bare --template=../templates child.git &&\n'> <'\techo "-rw-rw-rw-" >expect &&\n'> <'\tmodebits child.git/foo >actual &&\n'> 
          <'\ttest_cmp expect actual\n'>
        )
      }
    )
    (C {<test_expect_success>} {<POSIXPERM>} {(SQ <'template can set core.sharedrepository'>)} 
      {
        (SQ <'\n'> <'\trm -rf child.git &&\n'> <'\tumask 0022 &&\n'> 
          <'\tgit config core.sharedrepository 0666 &&\n'> <'\tcp .git/config templates/config &&\n'> 
          <'\tgit init --bare --template=../templates child.git &&\n'> <'\techo "-rw-rw-rw-" >expect &&\n'> <'\tmodebits child.git/HEAD >actual &&\n'> 
          <'\ttest_cmp expect actual\n'>
        )
      }
    )
    (C {<test_done>})
  ]
)