#!/bin/sh test_description='Check the ref listing and diff size limits' . ./setup.sh if [ $CGIT_HAS_LUA -eq 1 ]; then test_set_prereq LUA fi # A repo with several branches and tags, one commit with an oversized file # diff beside a small one, and configs that pin tiny limits. test_expect_success 'set up limit fixtures' ' mkrepo repos/limits 1 && ( cd repos/limits && seq 1 60 >big.c && printf "int x;\n" >small.c && git add -A && git commit -m sources && seq 301 360 >big.c && printf "int y;\n" >small.c && git commit -am change && for i in 1 2 3; do git branch branch-$i || exit 1; done && for i in 1 2 3; do git tag tag-$i || exit 1; done ) && { echo "virtual-root=/" && echo "cache-size=0" && echo "max-ref-count=2" && echo "max-diff-lines=20" && echo "max-diff-files=0" && echo "repo.url=limits" && echo "repo.path=$PWD/repos/limits/.git" } >limitrc && { echo "virtual-root=/" && echo "cache-size=0" && echo "max-diff-files=1" && echo "repo.url=limits" && echo "repo.path=$PWD/repos/limits/.git" } >limitfilesrc ' limitq() { CGIT_CONFIG="$PWD/limitrc" QUERY_STRING="$1" cgit; } # --- The refs page caps each section and links to the category pages -------- test_expect_success 'refs page lists max-ref-count branches and tags' ' limitq "url=limits/refs/" >tmp && test $(grep -c "log/?h=" tmp) -eq 2 && test $(grep -c "/tag/?h=tag-" tmp) -eq 2 ' test_expect_success 'refs page links each overflow to its own category' ' grep "refs/heads" tmp && grep "refs/tags" tmp ' test_expect_success 'branch page paginates independently' ' limitq "url=limits/refs/heads/" >tmp && test $(grep -c "log/?h=" tmp) -eq 2 && grep "\[next\]" tmp && limitq "url=limits/refs/heads/&ofs=2" >tmp && grep "\[prev\]" tmp && ! grep "/tag/?h=tag-" tmp ' test_expect_success 'tag page paginates independently' ' limitq "url=limits/refs/tags/&ofs=2" >tmp && grep "/tag/?h=tag-" tmp && grep "\[prev\]" tmp && ! grep "log/?h=" tmp ' # --- Oversized file diffs link out instead of rendering inline -------------- test_expect_success 'oversized file diff is replaced by a link' ' limitq "url=limits/commit/" >tmp && grep "too large to be rendered inline" tmp && grep "View it on its own page" tmp ' test_expect_success 'small file in the same commit still renders inline' ' grep "class=.add.>+int y;" tmp ' test_expect_success 'the single-file diff page always renders in full' ' limitq "url=limits/diff/big.c" >tmp && grep "class=.hunk." tmp && ! grep "too large to be rendered inline" tmp ' # --- Commits over max-diff-files fall back to the diffstat ------------------ test_expect_success 'a commit changing too many files shows stat only' ' CGIT_CONFIG="$PWD/limitfilesrc" QUERY_STRING="url=limits/commit/" cgit >tmp && grep "too large to be rendered inline" tmp && ! grep "class=.hunk." tmp ' test_expect_success 'the single-file page is not limited by max-diff-files' ' CGIT_CONFIG="$PWD/limitfilesrc" QUERY_STRING="url=limits/diff/small.c" cgit >tmp && grep "class=.hunk." tmp ' # --- max-blob-size also bounds the diff path -------------------------------- # The diff family must not inflate a blob larger than max-blob-size just to # render it. Such a file is reported as binary instead of inlined. test_expect_success 'a diff of an oversized blob is not inlined' ' mkrepo repos/blobdiff 1 && ( cd repos/blobdiff && awk "BEGIN{for(i=0;i<400;i++)print \"aaaaaaaa\"}" >big.txt && git add -A && git commit -m add && awk "BEGIN{for(i=0;i<401;i++)print \"aaaaaaaa\"}" >big.txt && git commit -am change ) && { echo "virtual-root=/" && echo "cache-size=0" && echo "max-blob-size=1" && echo "repo.url=blobdiff" && echo "repo.path=$PWD/repos/blobdiff/.git" } >blobdiffrc && sha=$(git -C repos/blobdiff rev-parse HEAD) && CGIT_CONFIG="$PWD/blobdiffrc" QUERY_STRING="url=blobdiff/commit/&id=$sha" cgit >tmp && grep "Binary files differ" tmp && ! grep "aaaaaaaa" tmp ' # --- The shipped highlight filter degrades to escaped passthrough ----------- test_expect_success LUA 'highlight filter passes text through without scintillua' ' { echo "virtual-root=/" && echo "cache-size=0" && echo "source-filter=lua:$(cd ../../extensions && pwd)/syntax-highlight.lua" && echo "repo.url=limits" && echo "repo.path=$PWD/repos/limits/.git" } >hlrc && CGIT_SCINTILLUA_PATH=/nonexistent CGIT_CONFIG="$PWD/hlrc" \ QUERY_STRING="url=limits/tree/small.c" cgit >tmp && grep "int y;" tmp ' test_done