#!/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
'
# Prints the options of the branch switcher that carry selected.
selected_options() {
sed -n "//p" "$1" | grep " selected"
}
# The switch button submits the select as h, so whatever head the request
# follows has to sit in the list selected, or submitting would quietly move
# the visitor to the first branch.
test_expect_success 'a detached head stays selected in the switcher' '
sha=$(git -C repos/foo rev-parse master~1) &&
cgit_ok_url "foo/log&h=$sha" >tmp &&
selected_options tmp >selected &&
test_line_count = 1 selected &&
test_grep "option value=.$sha. selected" selected
'
test_expect_success 'a tag head stays selected in the switcher' '
git -C repos/foo tag t-switch master~1 &&
test_when_finished "git -C repos/foo tag -d t-switch" &&
cgit_ok_url "foo/log&h=t-switch" >tmp &&
selected_options tmp >selected &&
test_line_count = 1 selected &&
test_grep "option value=.t-switch. selected>t-switch (detached)" selected
'
test_expect_success 'a branch head keeps its plain option' '
cgit_ok_url "foo/log&h=master" >tmp &&
selected_options tmp >selected &&
test_line_count = 1 selected &&
test_grep "option value=.master. selected>master<" selected &&
test_grep ! "detached" tmp
'
# A page pinned to a commit by id lists that commit in the switcher, selected
# in place of the branch it was reached from.
test_expect_success 'a pinned commit is selected in place of its branch' '
sha=$(git -C repos/foo rev-parse master~1) &&
cgit_ok_url "foo/commit&id=$sha" >tmp &&
selected_options tmp >selected &&
test_line_count = 1 selected &&
short=$(echo "$sha" | cut -c1-10) &&
test_grep "option value=.$sha. selected>$short (detached)<" selected &&
test_grep "master " tmp
'
test_expect_success 'a search escapes the space in its links' '
cgit_ok_url "with+space/log&qt=grep&q=commit+1" >tmp &&
test_grep "/with%20space/log/?qt=grep" tmp &&
test_grep "/log/?qt=grep&q=commit+1" tmp &&
test_grep ! "href=./with space/" tmp &&
test_grep ! "q=commit 1" tmp
'
test_expect_success 'a search lists only the commits it matches' '
cgit_ok_url "with+space/log&qt=grep&q=commit+1" >tmp &&
test_grep ">commit 1<" tmp &&
test_grep ! "commit 2" tmp
'
# A search that matches nothing says so in a row of its own, rather than
# leaving the table a header with nothing under it.
test_expect_success 'a search matching nothing says so' '
cgit_ok_url "foo/log&qt=grep&q=no+such+commit" >tmp &&
test_grep "No commits match the search " tmp &&
cgit_ok_url "foo/log&qt=grep&q=commit+1" >tmp &&
test_grep ">commit 1<" tmp &&
test_grep ! "No commits match" tmp
'
# A tag's label says which kind it is, which only peeling the tag tells, and
# a branch label leads to that branch's log.
test_expect_success 'the log labels branches and both kinds of tag' '
mkrepo repos/deco 3 &&
git -C repos/deco branch side HEAD~1 &&
git -C repos/deco tag deco-light HEAD~1 &&
git -C repos/deco tag -a -m annotated deco-annotated HEAD~2 &&
cgitrc_repo decorc deco &&
cgit_ok decorc "url=deco/log/" >tmp &&
test_grep "master " tmp &&
test_grep "side " tmp &&
test_grep "deco-light " tmp &&
test_grep "deco-annotated " tmp
'
# Following a file diffs each commit for the name the file had there, so the
# root commit that created it has to be diffed too, and paging has to go on
# asking about the name the visitor followed rather than the older one.
test_expect_success 'set up a renamed file to follow' '
test_create_repo repos/fol &&
(
cd repos/fol &&
echo 1 >a.txt &&
git add a.txt &&
git commit -m "create a" &&
for i in 2 3 4
do
echo $i >>a.txt &&
git commit -am "edit a $i" || return 1
done &&
git mv a.txt b.txt &&
git commit -m "rename to b" &&
for i in 6 7 8
do
echo $i >>b.txt &&
git commit -am "edit b $i" || return 1
done
) &&
cgitrc_repo folrc fol enable-follow-links=1 max-commit-count=3
'
test_expect_success 'a followed log reaches the root commit' '
cgit_ok folrc "url=fol/log/b.txt&follow=1&ofs=6" >tmp &&
grep ">edit a 2<" tmp &&
grep ">create a<" tmp
'
test_expect_success 'the pager of a followed log keeps the name followed' '
cgit_ok folrc "url=fol/log/b.txt&follow=1&ofs=3" >tmp &&
grep ">edit a 3<" tmp &&
grep "href=./fol/log/b.txt?follow=1.>\[prev\]" tmp &&
grep "href=./fol/log/b.txt?ofs=6&follow=1.>\[next\]" tmp
'
test_expect_success 'a cut subject keeps whole characters' '
git -C repos/foo commit --allow-empty -m "日本語の説明文です日本語の説明文です" &&
cgitrc_copy subjectrc max-message-length=20 &&
cgit_ok subjectrc "url=foo/log/" >tmp &&
grep ">日本語の説\.\.\." tmp
'
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