#!/bin/sh # The commit page. Most checks read the markup for the tree link, the parent # link, the subject and the diffstat. test_description='Check content on commit page' . ./setup.sh test_expect_success 'generate foo/commit' 'cgit_ok_url "foo/commit" >tmp' test_expect_success 'find tree link' ' tree=$(git -C repos/foo rev-parse master^{tree}) && test_grep "tree
$tree" tmp ' test_expect_success 'find parent link' ' parent=$(git -C repos/foo rev-parse master~1) && test_grep "parent
$parent" tmp ' test_expect_success 'subject links name a parent by its subject' ' cgitrc_copy subjectrc enable-subject-links=1 && parent=$(git -C repos/foo rev-parse master~1) && cgit_ok subjectrc "url=foo/commit" >tmp && test_grep "parent
commit 4" tmp ' test_expect_success 'find commit subject' ' grep "
commit 5<" tmp ' test_expect_success 'find commit msg' 'grep "
" tmp' test_expect_success 'find diffstat' 'grep "" tmp' test_expect_success 'find diff summary' ' grep "1 file changed, 1 insertion, 0 deletions" tmp ' # A strict CSP refuses an inline style, so the bar takes its widths from SVG # attributes, which also leave the page valid. test_expect_success 'the diffstat bar is an SVG sized by its attributes' ' grep "" tmp ' test_expect_success 'a commit that changes no files draws no diffstat table' ' ( cd repos/foo && git update-ref refs/heads/empty $(git commit-tree HEAD^{tree} -p HEAD -m empty) ) && cgit_ok_url "foo/commit/&h=empty" >tmp && grep "0 files changed, 0 insertions, 0 deletions" tmp && test_grep ! "
" tmp ' # A root commit has no parent, so it diffs against the empty tree. test_expect_success 'a root commit diffs against the empty tree' ' root=$(git -C repos/foo rev-list --max-parents=0 HEAD) && cgit_ok_url "foo/commit&id=$root" >tmp && test_grep "file-1" tmp && test_grep ">diff --git a/file-1 b/file-1<" tmp && test_grep "
+1
" tmp ' # A message that is not UTF-8, because its encoding header names something # iconv cannot convert or is missing altogether, would otherwise reach a # page declared UTF-8 as it is, so its stray bytes become question marks. test_expect_success 'a message that is not UTF-8 has its stray bytes replaced' ' ( cd repos/foo && tree=$(git rev-parse HEAD^{tree}) && printf "tree %s\nauthor A U Thor 1735689600 +0000\n" "$tree" >raw && printf "committer A U Thor 1735689600 +0000\n" >>raw && printf "encoding no-such-charset\n\ncaf\351 subject\n\nbody \377 end\n" >>raw && cid=$(git hash-object --literally -t commit -w raw) && git update-ref refs/heads/latin "$cid" && printf "tree %s\nauthor A U Thor 1735689600 +0000\n" "$tree" >raw && printf "committer A U Thor 1735689600 +0000\n" >>raw && printf "\nbare caf\351 subject\n" >>raw && cid=$(git hash-object --literally -t commit -w raw) && git update-ref refs/heads/bare "$cid" ) && cgit_ok_url "foo/commit&h=latin" >tmp && grep "
caf? subject<" tmp && grep "body ? end" tmp && test_grep ! "caf$(printf "\351")" tmp && cgit_ok_url "foo/commit&h=bare" >tmp && test_grep "
bare caf? subject<" tmp && test_grep ! "caf$(printf "\351")" tmp ' # The diff is taken against the first parent alone, which says little about # a merge of three branches or more, so such a merge draws none and offers # no diff options. A merge of two still draws its diff. Both merges take a # tree their first parent lacks a file of, so a diff would have a row. test_expect_success 'an octopus merge draws no diff and offers no diff options' ' ( cd repos/foo && tree=$(git rev-parse HEAD~1^{tree}) && cid=$(git commit-tree -p HEAD -p HEAD~1 -p HEAD~2 -m octopus $tree) && git update-ref refs/heads/octopus "$cid" && cid=$(git commit-tree -p HEAD -p HEAD~2 -m twofold $tree) && git update-ref refs/heads/twofold "$cid" ) && cgit_ok_url "foo/commit&h=octopus" >tmp && test_grep "
octopus<" tmp && test $(grep -c "
" tmp) = 3 && test_grep ! "cgit-panel" tmp && test_grep ! "
parent
" tmp && cgit_ok_url "foo/commit&h=twofold" >tmp && test $(grep -c "" tmp) = 2 && test_grep "cgit-panel" tmp && test_grep "
parent
" tmp ' test_expect_success 'the commit page offers a download per snapshot format' ' cgit_ok_url "foo/commit" >tmp && test_grep "" tmp && test_grep ! ">download" tmp ' test_expect_success 'a note is shown below the message' ' git -C repos/foo notes add -m "a note on five" master && test_when_finished "git -C repos/foo notes remove master" && cgit_ok_url "foo/commit" >tmp && test_grep "
Notes
" tmp && test_grep "
a note on five$" tmp ' test_done
download
foo-master.tar
" tmp && test_grep "foo-master.zip" tmp && cgitrc_repo nosnaprc foo && cgit_ok nosnaprc "url=foo/commit" >tmp && test_grep "
tree