#!/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 "