(CommandList
  children: [
    (Assignment
      keyword: Assign_None
      pairs: [
        (assign_pair
          lhs: (LhsName name:test_description)
          op: Equal
          rhs: 
            {
              (SQ <"gitweb as standalone script (parsing script output).\n"> <"\n"> 
                <"This test runs gitweb (git web interface) as a CGI script from the\n"> <"commandline, and checks that it produces the correct output, either\n"> 
                <"in the HTTP header or the actual script output.">
              )
            }
          spids: [13]
        )
      ]
      spids: [13]
    )
    (C {(.)} {(./gitweb-lib.sh)})
    (SimpleCommand
      words: [{(cat)}]
      redirects: [
        (Redir op_id:Redir_DGreat fd:-1 arg_word:{(gitweb_config.perl)} spids:[38])
        (HereDoc
          op_id: Redir_DLess
          fd: -1
          body: 
            {("\n") ("$known_snapshot_formats{'tar'} = {\n") ("\t'display' => 'tar',\n") 
              ("\t'type' => 'application/x-tar',\n") ("\t'suffix' => '.tar',\n") ("\t'format' => 'tar',\n") ("};\n") ("\n") 
              ("$feature{'snapshot'}{'default'} = ['tar'];\n")
            }
          do_expansion: False
          here_end: EOF
          was_filled: True
          spids: [41]
        )
      ]
    )
    (FuncDef
      name: check_snapshot
      body: 
        (BraceGroup
          children: [
            (Assignment
              keyword: Assign_None
              pairs: [
                (assign_pair
                  lhs: (LhsName name:basename)
                  op: Equal
                  rhs: {($ VSub_Number "$1")}
                  spids: [75]
                )
              ]
              spids: [75]
            )
            (Assignment
              keyword: Assign_None
              pairs: [
                (assign_pair
                  lhs: (LhsName name:prefix)
                  op: Equal
                  rhs: 
                    {
                      (BracedVarSub
                        token: <VSub_Number 2>
                        suffix_op: 
                          (StringUnary
                            op_id: VTest_ColonHyphen
                            arg_word: {(DQ ($ VSub_Number "$1"))}
                          )
                        spids: [80 86]
                      )
                    }
                  spids: [79]
                )
              ]
              spids: [79]
            )
            (C {(echo)} {(DQ ("basename=") ($ VSub_Name "$basename"))})
            (AndOr
              children: [
                (SimpleCommand
                  words: [
                    {(grep)}
                    {(DQ ("filename=.*") ($ VSub_Name "$basename") (.tar))}
                    {(gitweb.headers)}
                  ]
                  redirects: [
                    (Redir
                      op_id: Redir_Great
                      fd: -1
                      arg_word: {(/dev/null)}
                      spids: [107]
                    )
                    (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[110])
                  ]
                )
                (AndOr
                  children: [
                    (SimpleCommand
                      words: [{(DQ ($ VSub_Name "$TAR"))} {(tf)} {(gitweb.body)}]
                      redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(file_list)} spids:[124])]
                    )
                    (Pipeline
                      children: [
                        (C {(grep)} {(-v)} {(-e)} {(DQ ("^") ($ VSub_Name "$prefix") (Lit_Other "$"))} 
                          {(-e)} {(DQ ("^") ($ VSub_Name "$prefix") (/))} {(-e)} {(DQ ("^pax_global_header") (Lit_Other "$"))} 
                          {(file_list)}
                        )
                      ]
                      negated: True
                    )
                  ]
                  op_id: Op_DAmp
                )
              ]
              op_id: Op_DAmp
            )
          ]
          spids: [72]
        )
      spids: [67 71]
    )
    (C {(test_expect_success)} {(setup)} 
      {
        (SQ <"\n"> <"\ttest_commit first foo &&\n"> <"\tgit branch xx/test &&\n"> 
          <"\tFULL_ID=$(git rev-parse --verify HEAD) &&\n"> <"\tSHORT_ID=$(git rev-parse --verify --short=7 HEAD)\n">
        )
      }
    )
    (C {(test_debug)} 
      {(SQ <"\n"> <"\techo \"FULL_ID  = $FULL_ID\"\n"> <"\techo \"SHORT_ID = $SHORT_ID\"\n">)}
    )
    (C {(test_expect_success)} {(SQ <"snapshot: full sha1">)} 
      {
        (SQ <"\n"> <"\tgitweb_run \"p=.git;a=snapshot;h=$FULL_ID;sf=tar\" &&\n"> 
          <"\tcheck_snapshot \".git-$SHORT_ID\"\n">
        )
      }
    )
    (C {(test_debug)} {(SQ <"cat gitweb.headers && cat file_list">)})
    (C {(test_expect_success)} {(SQ <"snapshot: shortened sha1">)} 
      {
        (SQ <"\n"> <"\tgitweb_run \"p=.git;a=snapshot;h=$SHORT_ID;sf=tar\" &&\n"> 
          <"\tcheck_snapshot \".git-$SHORT_ID\"\n">
        )
      }
    )
    (C {(test_debug)} {(SQ <"cat gitweb.headers && cat file_list">)})
    (C {(test_expect_success)} {(SQ <"snapshot: almost full sha1">)} 
      {
        (SQ <"\n"> <"\tID=$(git rev-parse --short=30 HEAD) &&\n"> 
          <"\tgitweb_run \"p=.git;a=snapshot;h=$ID;sf=tar\" &&\n"> <"\tcheck_snapshot \".git-$SHORT_ID\"\n">
        )
      }
    )
    (C {(test_debug)} {(SQ <"cat gitweb.headers && cat file_list">)})
    (C {(test_expect_success)} {(SQ <"snapshot: HEAD">)} 
      {
        (SQ <"\n"> <"\tgitweb_run \"p=.git;a=snapshot;h=HEAD;sf=tar\" &&\n"> 
          <"\tcheck_snapshot \".git-HEAD-$SHORT_ID\"\n">
        )
      }
    )
    (C {(test_debug)} {(SQ <"cat gitweb.headers && cat file_list">)})
    (C {(test_expect_success)} {(SQ <"snapshot: short branch name (master)">)} 
      {
        (SQ <"\n"> <"\tgitweb_run \"p=.git;a=snapshot;h=master;sf=tar\" &&\n"> 
          <"\tID=$(git rev-parse --verify --short=7 master) &&\n"> <"\tcheck_snapshot \".git-master-$ID\"\n">
        )
      }
    )
    (C {(test_debug)} {(SQ <"cat gitweb.headers && cat file_list">)})
    (C {(test_expect_success)} {(SQ <"snapshot: short tag name (first)">)} 
      {
        (SQ <"\n"> <"\tgitweb_run \"p=.git;a=snapshot;h=first;sf=tar\" &&\n"> 
          <"\tID=$(git rev-parse --verify --short=7 first) &&\n"> <"\tcheck_snapshot \".git-first-$ID\"\n">
        )
      }
    )
    (C {(test_debug)} {(SQ <"cat gitweb.headers && cat file_list">)})
    (C {(test_expect_success)} {(SQ <"snapshot: full branch name (refs/heads/master)">)} 
      {
        (SQ <"\n"> <"\tgitweb_run \"p=.git;a=snapshot;h=refs/heads/master;sf=tar\" &&\n"> 
          <"\tID=$(git rev-parse --verify --short=7 master) &&\n"> <"\tcheck_snapshot \".git-master-$ID\"\n">
        )
      }
    )
    (C {(test_debug)} {(SQ <"cat gitweb.headers && cat file_list">)})
    (C {(test_expect_success)} {(SQ <"snapshot: full tag name (refs/tags/first)">)} 
      {
        (SQ <"\n"> <"\tgitweb_run \"p=.git;a=snapshot;h=refs/tags/first;sf=tar\" &&\n"> 
          <"\tcheck_snapshot \".git-first\"\n">
        )
      }
    )
    (C {(test_debug)} {(SQ <"cat gitweb.headers && cat file_list">)})
    (C {(test_expect_success)} {(SQ <"snapshot: hierarchical branch name (xx/test)">)} 
      {
        (SQ <"\n"> <"\tgitweb_run \"p=.git;a=snapshot;h=xx/test;sf=tar\" &&\n"> 
          <"\t! grep \"filename=.*/\" gitweb.headers\n">
        )
      }
    )
    (C {(test_debug)} {(SQ <"cat gitweb.headers">)})
    (C {(test_expect_success)} {(SQ <"forks: setup">)} 
      {
        (SQ <"\n"> <"\tgit init --bare foo.git &&\n"> <"\techo file > file &&\n"> 
          <"\tgit --git-dir=foo.git --work-tree=. add file &&\n"> <"\tgit --git-dir=foo.git --work-tree=. commit -m \"Initial commit\" &&\n"> 
          <"\techo \"foo\" > foo.git/description &&\n"> <"\tgit clone --bare foo.git foo.bar.git &&\n"> <"\techo \"foo.bar\" > foo.bar.git/description &&\n"> 
          <"\tgit clone --bare foo.git foo_baz.git &&\n"> <"\techo \"foo_baz\" > foo_baz.git/description &&\n"> <"\trm -fr   foo &&\n"> <"\tmkdir -p foo &&\n"> 
          <"\t(\n"> <"\t\tcd foo &&\n"> <"\t\tgit clone --shared --bare ../foo.git foo-forked.git &&\n"> 
          <"\t\techo \"fork of foo\" > foo-forked.git/description\n"> <"\t)\n">
        )
      }
    )
    (C {(test_expect_success)} {(SQ <"forks: not skipped unless \"forks\" feature enabled">)} 
      {
        (SQ <"\n"> <"\tgitweb_run \"a=project_list\" &&\n"> 
          <"\tgrep -q \">\\\\.git<\"               gitweb.body &&\n"> <"\tgrep -q \">foo\\\\.git<\"            gitweb.body &&\n"> 
          <"\tgrep -q \">foo_baz\\\\.git<\"        gitweb.body &&\n"> <"\tgrep -q \">foo\\\\.bar\\\\.git<\"      gitweb.body &&\n"> 
          <"\tgrep -q \">foo_baz\\\\.git<\"        gitweb.body &&\n"> <"\tgrep -q \">foo/foo-forked\\\\.git<\" gitweb.body &&\n"> 
          <"\tgrep -q \">fork of .*<\"           gitweb.body\n">
        )
      }
    )
    (C {(test_expect_success)} {(SQ <"enable forks feature">)} 
      {
        (SQ <"\n"> <"\tcat >>gitweb_config.perl <<-\\EOF\n"> 
          <"\t$feature{\"forks\"}{\"default\"} = [1];\n"> <"\tEOF\n">
        )
      }
    )
    (C {(test_expect_success)} {(SQ <"forks: forks skipped if \"forks\" feature enabled">)} 
      {
        (SQ <"\n"> <"\tgitweb_run \"a=project_list\" &&\n"> 
          <"\tgrep -q \">\\\\.git<\"               gitweb.body &&\n"> <"\tgrep -q \">foo\\\\.git<\"            gitweb.body &&\n"> 
          <"\tgrep -q \">foo_baz\\\\.git<\"        gitweb.body &&\n"> <"\tgrep -q \">foo\\\\.bar\\\\.git<\"      gitweb.body &&\n"> 
          <"\tgrep -q \">foo_baz\\\\.git<\"        gitweb.body &&\n"> <"\tgrep -v \">foo/foo-forked\\\\.git<\" gitweb.body &&\n"> 
          <"\tgrep -v \">fork of .*<\"           gitweb.body\n">
        )
      }
    )
    (C {(test_expect_success)} {(SQ <"forks: \"forks\" action for forked repository">)} 
      {
        (SQ <"\n"> <"\tgitweb_run \"p=foo.git;a=forks\" &&\n"> 
          <"\tgrep -q \">foo/foo-forked\\\\.git<\" gitweb.body &&\n"> <"\tgrep -q \">fork of foo<\"          gitweb.body\n">
        )
      }
    )
    (C {(test_expect_success)} {(SQ <"forks: can access forked repository">)} 
      {
        (SQ <"\n"> <"\tgitweb_run \"p=foo/foo-forked.git;a=summary\" &&\n"> 
          <"\tgrep -q \"200 OK\"        gitweb.headers &&\n"> <"\tgrep -q \">fork of foo<\" gitweb.body\n">
        )
      }
    )
    (C {(test_expect_success)} {(SQ <"forks: project_index lists all projects (incl. forks)">)} 
      {
        (SQ <"\n"> <"\tcat >expected <<-\\EOF &&\n"> <"\t.git\n"> <"\tfoo.bar.git\n"> <"\tfoo.git\n"> 
          <"\tfoo/foo-forked.git\n"> <"\tfoo_baz.git\n"> <"\tEOF\n"> <"\tgitweb_run \"a=project_index\" &&\n"> 
          <"\tsed -e \"s/ .*//\" <gitweb.body | sort >actual &&\n"> <"\ttest_cmp expected actual\n">
        )
      }
    )
    (FuncDef
      name: xss
      body: 
        (BraceGroup
          children: [
            (AndOr
              children: [
                (SimpleCommand
                  words: [{(echo)} {(DQ ("Checking ") ($ VSub_Number "$1") (...))}]
                  redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[504])]
                )
                (AndOr
                  children: [
                    (C {(gitweb_run)} {(DQ ($ VSub_Number "$1"))})
                    (If
                      arms: [
                        (if_arm
                          cond: [
                            (Sentence
                              child: (C {(grep)} {(DQ ($ VSub_Name "$TAG"))} {(gitweb.body)})
                              terminator: <Op_Semi ";">
                            )
                          ]
                          action: [
                            (SimpleCommand
                              words: [
                                {(echo)}
                                {
                                  (DQ ("xss: ") ($ VSub_Name "$TAG") 
                                    (" should have been quoted in output")
                                  )
                                }
                              ]
                              redirects: [
                                (Redir
                                  op_id: Redir_GreatAnd
                                  fd: -1
                                  arg_word: {(2)}
                                  spids: [541]
                                )
                              ]
                            )
                            (ControlFlow
                              token: <ControlFlow_Return return>
                              arg_word: {(1)}
                            )
                          ]
                          spids: [-1 536]
                        )
                      ]
                      spids: [-1 556]
                    )
                  ]
                  op_id: Op_DAmp
                )
              ]
              op_id: Op_DAmp
            )
            (ControlFlow token:<ControlFlow_Return return> arg_word:{(0)})
          ]
          spids: [499]
        )
      spids: [495 498]
    )
    (C {(test_expect_success)} {(SQ <"xss checks">)} 
      {
        (SQ <"\n"> <"\tTAG=\"<magic-xss-tag>\" &&\n"> <"\txss \"a=rss&p=$TAG\" &&\n"> 
          <"\txss \"a=rss&p=foo.git&f=$TAG\"\n">
        )
      }
    )
    (C {(test_done)})
  ]
)