#!/bin/sh # Checks how cgit shows a commit date, which is either an age relative to now # or a calendar date in the format the config names. The config is rewritten # between cases so that each one names only the settings it is about and # leaves the rest at their defaults. test_description='Check the date display options' . ./setup.sh # One old commit and one fresh one, so a single page shows both the relative # rendering and the calendar fallback that takes over past the two week # cutoff. test_expect_success 'set up a dated repo' ' mkrepo repos/dated 1 && ( cd repos/dated && GIT_AUTHOR_DATE="@1112911993 +0000" \ GIT_COMMITTER_DATE="@1112911993 +0000" \ git commit --allow-empty -m old && GIT_AUTHOR_DATE="@$(date +%s) +0000" \ GIT_COMMITTER_DATE="@$(date +%s) +0000" \ git commit --allow-empty -m fresh ) ' # Writes the config afresh, one extra line per argument, which is what lets a # test below name a setting or two and say nothing about the rest. daterc() { { echo "virtual-root=/" echo "cache-size=0" printf '%s\n' "$@" echo "repo.url=dated" echo "repo.path=$PWD/repos/dated/.git" } >daterc } dateq() { CGIT_CONFIG="$PWD/daterc" QUERY_STRING="$1" cgit; } test_expect_success 'relative dates are on by default' ' daterc && dateq "url=dated/refs/" >tmp && grep "class=.age-" tmp ' test_expect_success 'enable-relative-dates=0 shows a calendar date' ' daterc "enable-relative-dates=0" && dateq "url=dated/refs/" >tmp && ! grep "class=.age-" tmp && grep "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]<" tmp ' test_expect_success 'the index and log columns follow the same flag' ' daterc "enable-relative-dates=0" && dateq "" >tmp && ! grep "class=.age-" tmp && dateq "url=dated/log/" >tmp && ! grep "class=.age-" tmp ' test_expect_success 'date-format selects the calendar format' ' daterc "enable-relative-dates=0" "date-format=iso8601" && dateq "url=dated/refs/" >tmp && grep ">[0-9-]* [0-9][0-9]:[0-9][0-9]:[0-9][0-9] +0000<" tmp ' test_expect_success 'date-format accepts a strftime format' ' daterc "enable-relative-dates=0" "date-format=format:%Y/%m/%d" && dateq "url=dated/refs/" >tmp && grep ">[0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9]<" tmp ' test_expect_success 'an unknown date-format falls back to short' ' daterc "enable-relative-dates=0" "date-format=nonsense" && dateq "url=dated/refs/" >tmp && grep "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]<" tmp && daterc "enable-relative-dates=0" "date-format=format:" && dateq "url=dated/refs/" >tmp && grep "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]<" tmp ' test_expect_success 'date-format still formats the log fallback' ' daterc "date-format=rfc2822" && dateq "url=dated/log/" >tmp && grep "class=.age-" tmp && grep ">[A-Z][a-z][a-z], [0-9]* Apr 2005 " tmp ' test_expect_success 'date-format leaves the commit page on ISO 8601' ' daterc "date-format=rfc2822" && sha=$(git -C repos/dated rev-parse HEAD~1) && dateq "url=dated/commit/&id=$sha" >tmp && grep "2005-04-07 [0-9:]* +0000" tmp && ! grep "Apr 2005" tmp ' test_done