#!/bin/sh # The tree page. The checks against foo+bar cover a file name and a branch # name that both contain a plus, which cgit percent-encodes in a path as # well as in a query, since a bare plus in a served path reads back as a # space through a query string. test_description='Check content on tree page' . ./setup.sh test_expect_success 'generate bar/tree' 'cgit_url "bar/tree" >tmp' test_expect_success 'find file-1' 'grep ">file-1<" tmp' test_expect_success 'find file-50' 'grep "file-50" tmp' test_expect_success 'the links column has a name' ' grep "
a\\\\rb\\\\vc" tmp &&
grep "c\\\\fd\\\\u0085e" tmp &&
grep "e\\\\u2028f\\\\u2029g$" tmp
'
test_expect_success 'only a carriage return before a line feed is left as it is' '
printf "h\\r\\n" >expect &&
grep "^h" tmp >actual &&
test_cmp expect actual &&
grep "^i\\\\r" tmp
'
test_expect_success 'the numbers count only the lines git counts' '
grep "3" tmp &&
! grep "4" tmp
'
test_expect_success 'the blame page escapes them the same way' '
cgit_rc breaksrc "url=breaks/blame/breaks.txt" >tmp &&
grep "a\\\\rb\\\\vc" tmp &&
grep "e\\\\u2028f\\\\u2029g$" tmp &&
grep "^i\\\\r" tmp
'
# The striped background is padded with spaces to the widest line, which is
# 31 columns once its six escapes are written out, though it is 18 bytes.
test_expect_success 'the blame stripes are as wide as the escaped line' '
grep "^ \\{31\\}" tmp
'
# Blame takes a file alone, so on its page the crumbs for the folders above
# the file lead to the tree.
test_expect_success 'the folder crumbs of a blame page lead to the tree' '
mkrepo repos/nested 1 &&
(
cd repos/nested &&
mkdir -p a/b &&
echo x >a/b/file.txt &&
git add a &&
git commit -m nested
) &&
cgitrc_repo nestedrc nested enable-blame=1 &&
cgit_rc nestedrc "url=nested/blame/a/b/file.txt" >tmp &&
grep "path: root/a/b/file.txt" tmp
'
# A commit's lines link to the file as the parent had it, under the name it
# had there, and the commit that created the file has nothing to link to.
test_expect_success 'blame links a commit to the file before it' '
mkrepo repos/renamed 1 &&
(
cd repos/renamed &&
test_seq 1 10 >a.txt &&
git add a.txt &&
git commit -m "add a.txt" &&
git mv a.txt b.txt &&
test_seq 1 9 >b.txt &&
echo ten >>b.txt &&
git commit -am "rename a.txt"
) &&
cgitrc_repo renamedrc renamed enable-blame=1 &&
cgit_rc renamedrc "url=renamed/blame/b.txt" >tmp &&
added=$(git -C repos/renamed rev-parse HEAD~1) &&
grep "title=.Blame the previous revision. href=./renamed/blame/a.txt?id=$added.>^" tmp &&
test $(grep -c "Blame the previous revision" tmp) = 1
'
test_expect_success 'generate foo+bar/tree' 'cgit_url "foo%2bbar/tree" >tmp'
test_expect_success 'verify a+b link' '
grep "/foo%2Bbar/tree/a%2Bb" tmp
'
test_expect_success 'generate foo+bar/tree?h=1+2' 'cgit_url "foo%2bbar/tree&h=1%2b2" >tmp'
test_expect_success 'verify a+b?h=1+2 link' '
grep "/foo%2Bbar/tree/a%2Bb?h=1%2B2" tmp
'
test_expect_success 'set up a repo with a nested submodule' '
mkrepo repos/submodules 1 &&
(
cd repos/submodules &&
sub=$(git rev-parse HEAD) &&
git update-index --add --cacheinfo 160000,$sub,vendor/sub &&
git commit -m gitlink
) &&
cgitrc_repo submodrc submodules enable-blame=1
'
test_expect_success 'generate submodules/tree/vendor' '
cgit_rc submodrc "url=submodules/tree/vendor" >tmp
'
test_expect_success 'a submodule row shows the entry name alone' '
grep "class=.ls-mod.>sub" tmp &&
! grep ">vendor/sub" tmp
'
test_expect_success 'the submodule hash is titled with the full id' '
sub=$(git -C repos/submodules rev-parse HEAD~1) &&
grep "class=.ls-mod-hash. title=.$sub.>" tmp
'
test_expect_success 'a submodule row shows no size' '
grep "ls-mod" tmp >row &&
grep "class=.ls-size.>-" row
'
test_expect_success 'a submodule row offers log but not blame or plain' '
grep ">log" row &&
! grep ">blame" row &&
! grep ">plain" row
'
test_expect_success 'a file row still offers blame' '
cgit_rc submodrc "url=submodules/tree/" >tmp &&
grep ">blame" tmp
'
# A link target inside the tree becomes a link, while an absolute one names a
# file on whatever machine checks the tree out, not a path in the tree.
test_expect_success 'only a link target inside the tree is linked' '
test_create_repo repos/links &&
(
cd repos/links &&
echo hi >target.txt &&
git add target.txt &&
rel=$(printf target.txt | git hash-object -w --stdin) &&
abs=$(printf /etc/passwd | git hash-object -w --stdin) &&
git update-index --add --cacheinfo 120000,$rel,rel &&
git update-index --add --cacheinfo 120000,$abs,abs &&
git commit -m links
) &&
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
'
# Blame takes a regular file alone, so a symlink is not offered it.
test_expect_success 'a symlink is not offered blame' '
cgitrc_repo linksblamerc links enable-blame=1 &&
cgit_rc linksblamerc "url=links/tree/" >tmp &&
grep "href=./links/blame/target.txt.>blame" tmp &&
! grep "href=./links/blame/rel.>blame" tmp &&
cgit_rc linksblamerc "url=links/tree/rel" >tmp &&
grep "| 0000 | 00 01 02 62 69 6e" tmp && ! grep "class=.truncated." tmp ' # Each byte of the dump costs several bytes of markup, so a large binary is # dumped up to its first 64 KB and links to the whole file. test_expect_success 'a large binary is dumped only in part' ' ( cd repos/bin && printf "\\000" >big.bin && test_seq 1 20000 >>big.bin && git add big.bin && git commit -m "large binary" ) && cgit_rc binrc "url=bin/tree/big.bin" >tmp && grep " | ffe0 | " tmp && ! grep "10000 | " tmp && grep "