#!/bin/sh # The summary page for a single repository. The shared setup caps its log at # five entries, so the checks against the fifty commit repository prove the # cut lands where it should, and the clone url template has the repository # name substituted in. test_description='Check content on summary page' . ./setup.sh # The branch row shows the newest subject as well, so the log rows are looked # for in the log's own section. test_expect_success 'generate foo summary' ' cgit_ok_url "foo" >tmp && sed -n "//,/<\/tbody>/p" tmp >log ' test_expect_success 'find commit 1' 'test_grep ">commit 1<" log' test_expect_success 'find commit 5' 'test_grep ">commit 5<" log' test_expect_success 'find branch master' 'grep "]*>master" tmp' test_expect_success 'a repository without tags draws no tag table' ' cgit_ok_url "foo" >tmp && test_grep "" tmp && test_grep ! "Tag" tmp ' test_expect_success 'clone-url expanded correctly' ' grep "git://example.org/foo.git" tmp ' test_expect_success 'generate bar summary' ' cgit_ok_url "bar" >tmp && sed -n "//,/<\/tbody>/p" tmp >log ' test_expect_success 'repo description reaches the meta tag' ' grep "" tmp ' test_expect_success 'the summary log stops at summary-log commits' ' test_grep ">commit 46<" log && test_grep ! ">commit 45<" log ' test_expect_success 'find commit 50' 'test_grep ">commit 50<" log' # A clone url is shown as written, but a browser cannot follow the ssh, scp # or git forms, so those rows link to the first http url in the list, or to # the repository's own page when the list has none. test_expect_success 'a git clone url row falls back to the page url' ' grep "clone-url.>git://example.org/bar.git" tmp ' test_expect_success 'an scp clone url row links to the http url' ' cgitrc_repo clonerc foo "repo.clone-url=git@example.org:foo https://example.org/foo" && cgit_ok clonerc "url=foo" >tmp && grep "title=.foo Git repository. href=.https://example.org/foo.>git@example.org:foo" tmp ' # A link element's href has to hold a URI, so the scp form is left out of # the head while the http url gets a link there. test_expect_success 'the head links only the clone urls with a scheme' ' cgit_ok clonerc "url=foo" >tmp && test_grep "" tmp && test_grep ! "tmp && test_grep "clone-url.>https://a/foo" tmp && test_grep "clone-url.>git://b/foo" tmp ' # The list is split into its templates before each is expanded, so a space in # the repository url stays inside one clone url, in the rows and in the head # alike. A clone-prefix has the url joined to it after the split. test_expect_success 'a space in the repository url stays inside one clone url' ' cgit_ok_url "with+space" >tmp && test_grep "clone-url.>git://example.org/with space.git" tmp && test $(grep -c "class=.clone-url." tmp) = 1 && test_grep "" tmp && test $(grep -c "tmp && test_grep ">https://a/with space" tmp && test_grep ">git://b/with space" tmp && test $(grep -c "class=.clone-url." tmp) = 2 ' # A clone url is shown as written, but linked with each byte a url cannot # carry percent-encoded. Its scheme, its delimiters and any escape it was # written with are left as they are. test_expect_success 'a clone url is linked percent-encoded' ' url=$(printf "d\303\251p\303\264t") && encoded=d%C3%A9p%C3%B4t && cgitrc_repo encrc "$url" "repo.path=$PWD/repos/foo/.git" \ "repo.clone-url=git+ssh://example.org/my%20repos/\$CGIT_REPO_URL.git https://example.org/\$CGIT_REPO_URL" && cgit_ok encrc "url=$encoded" >tmp && test_grep "" tmp && test_grep "" tmp && test_grep "title=.$url Git repository. href=.https://example.org/$encoded.>git+ssh://example.org/my%20repos/$url\.git" tmp && test_grep "title=.$url Git repository. href=.https://example.org/$encoded.>https://example.org/$url" tmp && test_grep ! "href=.[^ >]*$url" tmp && cgit_ok spacerc "url=with+space" >tmp && test_grep "" tmp && test_grep "" tmp && test_grep "href=.https://a/with%20space.>git://b/with space" tmp ' # The macros read the request as well, so a clone url built from the Host # header has to stay inside the attribute it is linked from. test_expect_success 'a clone url from the request stays inside its attribute' ' cgitrc_repo hostrc foo "repo.clone-url=https://\$HTTP_HOST/\$CGIT_REPO_URL" && ( HTTP_HOST="h'\''\"" && export HTTP_HOST && cgit_ok hostrc "url=foo" >tmp ) && test_grep "" tmp && test_grep "href=.https://h'%22%3Cx%3E/foo.>https://h..<x>/foo" tmp && test_grep ! "" tmp ' # A repository can turn the global clone-url off with an empty one of its own. # Neither its summary nor the page an empty repository gets then draws a Clone # heading over no rows. test_expect_success 'an empty clone url draws no clone heading' ' git init -q --bare repos/empty.git && { echo "virtual-root=/" && echo "cache-size=0" && echo "clone-url=https://example.org/\$CGIT_REPO_URL" && echo "repo.url=foo" && echo "repo.path=$PWD/repos/foo/.git" && echo "repo.clone-url=" && echo "repo.url=empty" && echo "repo.path=$PWD/repos/empty.git" && echo "repo.clone-url=" && echo "repo.url=cloned" && echo "repo.path=$PWD/repos/empty.git" } >emptyrc && cgit_ok emptyrc "url=foo" >tmp && test_grep ">commit 1<" tmp && test_grep ! "Clone" tmp && cgit_ok emptyrc "url=empty" >tmp && test_grep "Repository seems to be empty" tmp && test_grep ! "Clone" tmp && cgit_ok emptyrc "url=cloned" >tmp && grep "Clone" tmp && grep "https://example.org/cloned" tmp ' # A remote-tracking branch is shown only when enable-remote-branches asks for # it, in the branch list, in the switcher and as a label in the log. test_expect_success 'set up a repository with a remote-tracking branch' ' mkrepo repos/remotes 2 && git -C repos/remotes update-ref refs/remotes/origin/topic HEAD~1 && cgitrc_repo remotesrc remotes repo.enable-remote-branches=1 && cgitrc_repo noremotesrc remotes ' test_expect_success 'remote branches are shown when enabled' ' topic=$(git -C repos/remotes rev-parse origin/topic) && cgit_ok remotesrc "url=remotes/refs/" >tmp && test_grep "origin/topic" tmp && test_grep "" tmp && cgit_ok remotesrc "url=remotes/log/" >tmp && test_grep "origin/topic" tmp ' test_expect_success 'remote branches stay hidden by default' ' cgit_ok noremotesrc "url=remotes/refs/" >tmp && test_grep "master" tmp && test_grep ! "origin/topic" tmp && cgit_ok noremotesrc "url=remotes/log/" >tmp && test_grep ">commit 1<" tmp && test_grep ! "origin/topic" tmp ' # Prints how many columns each row of the page's list table spans, one row to # a line, counting a cell without a colspan as one. row_widths() { sed -n "/]/ { width = 0 row = $0 while (match(row, /]/)) { row = substr(row, RSTART + 3) cell = substr(row, 1, index(row, ">")) if (match(cell, /colspan=.[0-9]+/)) width += substr(cell, RSTART + 9, RLENGTH - 9) else width++ } print width } ' } # Fails unless every row of the list table at the url is as many columns wide # as the second argument says. A third names a config other than colsrc. test_widths() { cgit_ok "${3:-colsrc}" "url=$1" >tmp && row_widths tmp | sort -u >actual && echo "$2" >expect && test_cmp expect actual } # The summary's sections share one table, so every row has to fill it, or the # stripe of a shorter row stops short of the table's edge. The table is as # wide as the log when both counts are on and as wide as a ref row otherwise. # Each repo below shows the same history with different counts, and every # section is cut short so that its [...] row is drawn too. test_expect_success 'set up a repo cut short in every section' ' mkrepo repos/cols 3 && git -C repos/cols branch other HEAD~1 && git -C repos/cols tag one HEAD~1 && git -C repos/cols tag -a -m two two && { echo "virtual-root=/" && echo "cache-size=0" && echo "summary-branches=1" && echo "summary-tags=1" && echo "summary-log=2" && echo "max-ref-count=1" && echo "clone-url=https://example.org/\$CGIT_REPO_URL" && echo "repo.url=none" && echo "repo.path=$PWD/repos/cols/.git" && echo "repo.url=lines" && echo "repo.path=$PWD/repos/cols/.git" && echo "repo.enable-log-linecount=1" && echo "repo.url=both" && echo "repo.path=$PWD/repos/cols/.git" && echo "repo.enable-log-filecount=1" && echo "repo.enable-log-linecount=1" } >colsrc && cgit_ok colsrc "url=none" >tmp && grep "" tmp && grep "" tmp && test $(grep -c ">\[\.\.\.\]" tmp) = 3 ' test_expect_success 'a summary without counts fills four columns' 'test_widths none 4' test_expect_success 'a summary with one count fills four columns' 'test_widths lines 4' test_expect_success 'a summary with both counts fills five columns' 'test_widths both 5' test_expect_success 'a summary without a log fills four columns' ' sed "s/^summary-log=2$/summary-log=0/" colsrc >nologrc && test_widths both 4 nologrc ' # The refs page draws the same rows with nothing wider beside them. test_expect_success 'the refs page fills four columns' 'test_widths both/refs/ 4' test_expect_success 'a page of branches fills four columns' 'test_widths both/refs/heads 4' test_expect_success 'a page of tags fills four columns' 'test_widths both/refs/tags 4' # The tag table's second column holds the downloads, or with no snapshot # format the object each tag points at, and is headed for what it holds. # Both tags carry the same date, so either may be the one row shown. test_expect_success 'the tag table heads its second column for what it holds' ' cgit_ok colsrc "url=none/refs/" >tmp && grep "" tmp && test_grep "" tmp && test_grep "
TagCommit
[a-z]*commit " tmp && { echo "snapshots=tar" && cat colsrc } >snaprc && cgit_ok snaprc "url=none/refs/" >tmp && grep "TagDownload
[a-z]*" tmp ' # A lightweight tag has no tagger, so its row takes the author and the date # of the commit it names. test_expect_success 'a lightweight tag row shows its commit author and age' ' mkrepo repos/light 1 && git -C repos/light tag light && cgitrc_repo lightrc light && cgit_ok lightrc "url=light/refs/tags" >tmp && test_grep "
light]*>commit [0-9a-f]*\.\.\.A U Thor