#!/bin/sh # Checks the repository scan. scan-path and the command line both walk a # directory for repositories, and the settings read before scan-path decide # which repositories a scan takes, what it names them, where it files them # and in what order. test_description='Check the repository scan' CGIT_TEST_NO_CREATE_REPOS=YesPlease . ./setup.sh # The index sorts by name, so a scan's own order shows only in the list it # caches, which keeps the repositories in the order the scan found them. scan_index() { cgitrc_file=$1 shift { echo "virtual-root=/" && echo "cache-size=0" && printf '%s\n' "$@" } >"$cgitrc_file" && cgit_ok "$cgitrc_file" "url=" } test_expect_success 'a scan from the command line prints its list sorted by url' ' mkrepo cmdscan/x 1 && mkrepo cmdscan/x.git 1 && mv cmdscan/x/.git cmdscan/x/a.git && echo "snapshots=zip" >cmdscan/x.git/.git/cgitrc && cgit --scan-path="$PWD/cmdscan" >scan.out && sed -n "s/^repo.url=//p" scan.out >urls && test_write_lines x.git x/a.git >expect && test_cmp expect urls && test_grep "^repo.snapshots=\\.zip$" scan.out && cgit --scan-tree="$PWD/cmdscan" >tree.out && test_cmp scan.out tree.out ' test_expect_success 'the command line can stand in for the web server' ' mkrepo repos/foo 1 && cgitrc_repo cmdrc foo && CGIT_CONFIG="$PWD/cmdrc" cgit --nohttp --query="url=foo/log/" >nohttp.out && test_grep ! "^Status:" nohttp.out && test_grep "data-page=.log. data-repo=.foo." nohttp.out && sed "s/^cache-size=0$/cache-size=64/" cmdrc >cmdcacherc && mkdir cmdcache && CGIT_CONFIG="$PWD/cmdcacherc" cgit --cache="$PWD/cmdcache" --query="url=foo/log/" >cache.out && test_grep "^Status: 200" cache.out && ls cmdcache >slots && test_line_count = 1 slots ' # A noweb file in a repository keeps the scan from listing it. test_expect_success 'a repository holding noweb is left out' ' mkrepo noweb/shown 1 && mkrepo noweb/hidden 1 && touch noweb/hidden/.git/noweb && scan_index nowebrc "scan-path=$PWD/noweb" >tmp && test_grep ">shown" tmp && test_grep ! ">hidden" tmp ' test_expect_success 'a dot directory is scanned only with scan-hidden-path' ' mkrepo dotted/shown 1 && mkrepo dotted/.secret 1 && scan_index dottedrc "scan-path=$PWD/dotted" >tmp && test_grep ">shown" tmp && test_grep ! ">.secret" tmp && scan_index dottedrc "scan-hidden-path=1" "scan-path=$PWD/dotted" >tmp && test_grep ">.secret" tmp ' # The section is taken from the path a number of separators in from the left, # or back from the right when the number is negative, and the name keeps what # follows it. A path too short for the number keeps no section. test_expect_success 'section-from-path files a repository under its path' ' mkrepo sectioned/top/mid/repo 1 && mkrepo sectioned/solo 1 && scan_index sectionrc "section-from-path=1" "scan-path=$PWD/sectioned" >tmp && test_grep "top" tmp && test_grep "href=./top/mid/repo/.>mid/repo" tmp && scan_index sectionrc "section-from-path=-1" "scan-path=$PWD/sectioned" >tmp && test_grep "top/mid" tmp && test_grep "href=./top/mid/repo/.>repo" tmp && test_grep "href=./solo/.>solo" tmp && scan_index sectionrc "scan-path=$PWD/sectioned" >tmp && test_grep ! "class=.reposection." tmp && test_grep "href=./top/mid/repo/.>top/mid/repo" tmp ' test_expect_success 'a project list scans only what it names, in its order' ' mkrepo listed/one 1 && mkrepo listed/two 1 && mkrepo listed/unlisted 1 && test_write_lines two one >projects && mkdir listcache && { echo "virtual-root=/" && echo "cache-root=$PWD/listcache" && echo "cache-size=64" && echo "cache-index-ttl=0" && echo "project-list=$PWD/projects" && echo "scan-path=$PWD/listed" } >listrc && cgit_ok listrc "url=" >tmp && test_grep ">one" tmp && test_grep ">two" tmp && test_grep ! ">unlisted" tmp && sed -n "s/^repo.url=//p" listcache/rc-* >urls && test_write_lines two one >expect && test_cmp expect urls ' test_expect_success 'a scan reads the gitweb settings of a repository' ' mkrepo gitweb/repo 1 && git -C gitweb/repo config gitweb.owner "Some Owner" && git -C gitweb/repo config gitweb.description "Described by gitweb" && git -C gitweb/repo config gitweb.category "Category" && scan_index gitwebrc "enable-git-config=1" "scan-path=$PWD/gitweb" >tmp && test_grep "Category" tmp && test_grep ">Described by gitweb" tmp && test_grep "Some Owner" tmp && scan_index gitwebrc "scan-path=$PWD/gitweb" >tmp && test_grep ! "Described by gitweb" tmp && test_grep ! "Some Owner" tmp ' # A url can name a repository whose own url holds another's as a prefix, so # the longest one that matches is the repository, and the rest is the page. test_expect_success 'a nested repository url goes to the deepest match' ' mkrepo nest/outer 1 && mkrepo nest/inner 2 && { echo "virtual-root=/" && echo "cache-size=0" && echo "repo.url=a" && echo "repo.path=$PWD/nest/outer/.git" && echo "repo.url=a/b" && echo "repo.path=$PWD/nest/inner/.git" } >nestrc && cgit_ok nestrc "url=a/b/log/" >tmp && test_grep "data-page=.log. data-repo=.a/b." tmp && test_grep "commit 2" tmp && cgit_ok nestrc "url=a/log/" >tmp && test_grep "data-page=.log. data-repo=.a." tmp && test_grep ! "commit 2" tmp && cgit_ok nestrc "url=a/b/tree/file-1" >tmp && test_grep "data-page=.tree. data-repo=.a/b." tmp ' test_done