#!/bin/sh
# The log page and its search. The searching checks use the repository whose
# name contains a space and a term containing a space, so every link cgit
# writes back has to escape the path and the query, which escape differently.
test_description='Check content on log page'
. ./setup.sh
test_expect_success 'the log lists the whole of a short history' '
cgit_ok_url "foo/log" >tmp &&
test_grep ">commit 1<" tmp &&
test_grep ">commit 5<" tmp
'
test_expect_success 'the first log page holds fifty commits' '
cgit_ok_url "bar/log" >tmp &&
test_grep ">commit 1<" tmp &&
test_grep ">commit 50<" tmp
'
test_expect_success 'the log counts the files and lines a commit changed' '
test_create_repo repos/counts &&
(
cd repos/counts &&
printf "1\n2\n3\n" >a.txt &&
git add a.txt &&
git commit -m "add a" &&
printf "1\n3\n4\n5\n" >a.txt &&
echo x >b.txt &&
git add a.txt b.txt &&
git commit -m "change both"
) &&
cgitrc_repo countsrc counts enable-log-filecount=1 enable-log-linecount=1 &&
cgit_ok countsrc "url=counts/log/" >tmp &&
test_grep ">change both.*
2
-1/+3
" tmp
'
# The commit dates run against the history, so the plain walk shows x ahead
# of z1, its child, which date order never does, and topo order keeps each
# line of the merge together where date order interleaves them.
test_expect_success 'set up a history the commit orders tell apart' '
test_create_repo repos/order &&
(
cd repos/order &&
tree=$(git mktree ../../order.plain &&
git log --date-order --format=%s >../../order.date &&
git log --topo-order --format=%s >../../order.topo
) &&
! cmp -s order.plain order.date &&
! cmp -s order.date order.topo &&
! cmp -s order.plain order.topo &&
cgitrc_repo orderrc order &&
cgitrc_repo orderdaterc order commit-sort=date &&
cgitrc_repo ordertoporc order repo.commit-sort=topo
'
test_expect_success 'commit-sort orders the log as git log does' '
for sort in plain date topo
do
case $sort in
plain) rc=orderrc ;;
date) rc=orderdaterc ;;
topo) rc=ordertoporc ;;
esac &&
cgit_ok $rc "url=order/log/" >tmp &&
sed -n "s/.*\([a-z0-9]*\)<\/a>.*/\1/p" tmp >actual &&
test_cmp order.$sort actual || return 1
done
'
# Prints the options of the branch switcher that carry selected.
selected_options() {
sed -n "/" tmp
'
test_expect_success 'a message limit below 15 turns the cut off' '
git -C repos/foo commit --allow-empty -m "a subject well past fourteen bytes" &&
cgitrc_copy cutrc max-message-length=15 &&
cgit_ok cutrc "url=foo/log/" >tmp &&
test_grep ">a subject we\.\.\." tmp &&
cgitrc_copy nocutrc max-message-length=14 &&
cgit_ok nocutrc "url=foo/log/" >tmp &&
test_grep ">a subject well past fourteen bytes" tmp
'
# With the messages expanded, a subject past the limit is cut at a space and
# the rest of it opens the message below.
test_expect_success 'an expanded log moves the cut part of a subject down' '
mkrepo repos/wrap 1 &&
git -C repos/wrap commit --allow-empty -m "one two three four five six seven eight" &&
cgitrc_repo wraprc wrap max-message-length=30 &&
cgit_ok wraprc "url=wrap/log/&showmsg=1" >tmp &&
test_grep ">one two three four five \.\.\." tmp &&
sed -n "/class=.logmsg.>\$/{n;p;q;}" tmp >msg &&
echo "six seven eight" >expect &&
test_cmp expect msg
'
test_expect_success 'the log draws the commit graph when enabled' '
cgitrc_copy graphrc enable-commit-graph=1 &&
cgit_ok graphrc "url=foo/log/" >tmp &&
grep "class=.commitgraph." tmp &&
grep "
" tmp
'
# A followed log is walked without the graph, so its first column holds the
# age whatever enable-commit-graph says.
test_expect_success 'a followed log heads its age column with the graph on' '
{
echo "enable-commit-graph=1" &&
cat folrc
} >folgraphrc &&
cgit_ok folgraphrc "url=fol/log/b.txt&follow=1" >tmp &&
grep "
Age
Commit message" tmp &&
test_grep ! "aria-label=.Graph." tmp
'
# The search is literal, so text that is no valid regular expression still
# finds the commit holding it.
test_expect_success 'a search for brackets matches them literally' '
git -C repos/foo commit --allow-empty -m "fix [brackets] in docs" &&
cgit_ok_url "foo/log&qt=grep&q=%5Bbrackets" >tmp &&
grep "fix \\[brackets\\] in docs" tmp
'
# A range is walked in full before the first row, so a missing parent fails
# the walk while the page can still answer with an error of its own.
test_expect_success 'a walk that cannot start answers one error page' '
git clone -q repos/foo gap &&
old=$(git -C gap rev-parse HEAD~4) &&
parent=$(git -C gap rev-parse HEAD~2) &&
rm gap/.git/objects/$(echo $parent | cut -c1-2)/$(echo $parent | cut -c3-) &&
cgitrc_repo gaprc gap "repo.path=$PWD/gap/.git" &&
cgit_rc gaprc "url=gap/log/&qt=range&q=$old..master" >tmp 2>err &&
test $(grep -c "^Status:" tmp) = 1 &&
grep "^Status: 500" tmp &&
grep "Unable to read the history" tmp &&
test_grep "Could not read $parent" err
'
test_done