From a3bb7c69c0295cb2fc7909559456e798b222fccd Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 31 Oct 2026 14:56:59 -0700 Subject: Add the shared config writers and cgit_rc The helpers are named by kind. cgitrc_repo and cgitrc_copy write the config file named first, and cgit_url, cgit_query and cgit_rc run cgit, each named after what it is handed first. A repository copies its defaults from the globals read before its repo.url, so cgitrc_repo places every setting itself, and a global can no longer land where it silently stops applying. The t00xx and t01xx files move to them here. --- tests/t0104-tree.sh | 60 +++++++++++++---------------------------------------- 1 file changed, 14 insertions(+), 46 deletions(-) (limited to 'tests/t0104-tree.sh') diff --git a/tests/t0104-tree.sh b/tests/t0104-tree.sh index e6985f9..26a0cb4 100755 --- a/tests/t0104-tree.sh +++ b/tests/t0104-tree.sh @@ -44,17 +44,11 @@ test_expect_success 'set up a file holding the characters a browser breaks at' ' git add breaks.txt && git commit -m breaks ) && - { - echo "virtual-root=/" && - echo "cache-size=0" && - echo "enable-blame=1" && - echo "repo.url=breaks" && - echo "repo.path=$PWD/repos/breaks/.git" - } >breaksrc + cgitrc_repo breaksrc breaks enable-blame=1 ' test_expect_success 'each of them is shown as an escape in the tree' ' - CGIT_CONFIG="$PWD/breaksrc" QUERY_STRING="url=breaks/tree/breaks.txt" cgit >tmp && + cgit_rc breaksrc "url=breaks/tree/breaks.txt" >tmp && grep "a\\\\rb\\\\vc" tmp && grep "c\\\\fd\\\\u0085e" tmp && grep "e\\\\u2028f\\\\u2029g$" tmp @@ -73,7 +67,7 @@ test_expect_success 'the numbers count only the lines git counts' ' ' test_expect_success 'the blame page escapes them the same way' ' - CGIT_CONFIG="$PWD/breaksrc" QUERY_STRING="url=breaks/blame/breaks.txt" cgit >tmp && + cgit_rc breaksrc "url=breaks/blame/breaks.txt" >tmp && grep "a\\\\rb\\\\vc" tmp && grep "e\\\\u2028f\\\\u2029g$" tmp && grep "^i\\\\r" tmp @@ -105,17 +99,11 @@ test_expect_success 'set up a repo with a nested submodule' ' git update-index --add --cacheinfo 160000,$sub,vendor/sub && git commit -m gitlink ) && - { - echo "virtual-root=/" && - echo "cache-size=0" && - echo "enable-blame=1" && - echo "repo.url=submodules" && - echo "repo.path=$PWD/repos/submodules/.git" - } >submodrc + cgitrc_repo submodrc submodules enable-blame=1 ' test_expect_success 'generate submodules/tree/vendor' ' - CGIT_CONFIG="$PWD/submodrc" QUERY_STRING="url=submodules/tree/vendor" cgit >tmp + cgit_rc submodrc "url=submodules/tree/vendor" >tmp ' test_expect_success 'a submodule row shows the entry name alone' ' @@ -140,7 +128,7 @@ test_expect_success 'a submodule row offers log but not blame or plain' ' ' test_expect_success 'a file row still offers blame' ' - CGIT_CONFIG="$PWD/submodrc" QUERY_STRING="url=submodules/tree/" cgit >tmp && + cgit_rc submodrc "url=submodules/tree/" >tmp && grep ">blame" tmp ' @@ -158,13 +146,8 @@ test_expect_success 'only a link target inside the tree is linked' ' git update-index --add --cacheinfo 120000,$abs,abs && git commit -m links ) && - { - echo "virtual-root=/" && - echo "cache-size=0" && - echo "repo.url=links" && - echo "repo.path=$PWD/repos/links/.git" - } >linksrc && - CGIT_CONFIG="$PWD/linksrc" QUERY_STRING="url=links/tree/" cgit >tmp && + cgitrc_repo linksrc links && + cgit_rc linksrc "url=links/tree/" >tmp && grep " -> target.txt" tmp && grep " -> /etc/passwd" tmp && ! grep "href=./links/tree/etc/passwd" tmp @@ -186,13 +169,8 @@ test_expect_success 'a long directory chain ends on a link' ' git add . && git commit -m deep ) && - { - echo "virtual-root=/" && - echo "cache-size=0" && - echo "repo.url=deep" && - echo "repo.path=$PWD/repos/deep/.git" - } >deeprc && - CGIT_CONFIG="$PWD/deeprc" QUERY_STRING="url=deep/tree/" cgit >tmp && + cgitrc_repo deeprc deep && + cgit_rc deeprc "url=deep/tree/" >tmp && grep ">d15" tmp && ! grep " / " tmp ' @@ -213,13 +191,8 @@ test_expect_success 'a broken chain keeps the row links on the first folder' ' git hash-object -t commit -w --stdin --literally) && git update-ref refs/heads/odd $odd ) && - { - echo "virtual-root=/" && - echo "cache-size=0" && - echo "repo.url=cut" && - echo "repo.path=$PWD/repos/cut/.git" - } >cutrc && - CGIT_CONFIG="$PWD/cutrc" QUERY_STRING="url=cut/tree/&h=odd" cgit >tmp && + cgitrc_repo cutrc cut && + cgit_rc cutrc "url=cut/tree/&h=odd" >tmp && grep ">b" tmp && grep "href=./cut/log/a?h=odd.>log" tmp ' @@ -232,13 +205,8 @@ test_expect_success 'a binary file in the tree shows as a hex dump' ' git add blob.bin && git commit -m binary ) && - { - echo "virtual-root=/" && - echo "cache-size=0" && - echo "repo.url=bin" && - echo "repo.path=$PWD/repos/bin/.git" - } >binrc && - CGIT_CONFIG="$PWD/binrc" QUERY_STRING="url=bin/tree/blob.bin" cgit >tmp && + cgitrc_repo binrc bin && + cgit_rc binrc "url=bin/tree/blob.bin" >tmp && grep "" tmp && grep "
0000 00 01 02 62 69 6e" tmp ' -- cgit