From e6575e88eaba388e73186b0ea96dee1191786b3f Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 7 Nov 2026 13:51:32 -1000 Subject: Check the mailmap on every page it reaches The MANUAL promises the blame and stats pages and says mailmap.file and mailmap.blob are ignored, and none of it was tested. The summary, where v2.11.1 fixed a mailmap crash, was never loaded, and neither was a committer, a mailmap on another branch or the repository flag turning the map on. The empty search checked only that nothing matched, and one test appended to the shared config. --- tests/t0208-mailmap.sh | 114 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 83 insertions(+), 31 deletions(-) (limited to 'tests/t0208-mailmap.sh') diff --git a/tests/t0208-mailmap.sh b/tests/t0208-mailmap.sh index 9e9ae0f..ceb9b0f 100755 --- a/tests/t0208-mailmap.sh +++ b/tests/t0208-mailmap.sh @@ -1,14 +1,20 @@ #!/bin/sh # The mailmap. A repository whose commits and tag carry an old ident gets a -# .mailmap at HEAD renaming it, and the log, commit, tag, atom and search -# pages are checked for the new name, then the flag is turned off globally and -# for the one repository. +# .mailmap at HEAD renaming it, and every page that shows an ident is checked +# for the new name, along with the author search. Only that blob is read, so +# a mailmap set in the repository's config or kept on another branch is +# checked to change nothing. Then the flag is turned off globally and for the +# one repository. test_description='Check the mailmap is applied to idents' CGIT_TEST_NO_CREATE_REPOS=YesPlease . ./setup.sh +# The last commit is by the old ident and stamped now, so the stats page, +# which counts only recent periods, has it to show. The side branch holds a +# mailmap of its own, and the repository config points at two more, all of +# which cgit leaves alone. test_expect_success 'create a repository with a mailmap at its head' ' test_create_repo repos/mapped && ( @@ -16,71 +22,117 @@ test_expect_success 'create a repository with a mailmap at its head' ' echo content >file && git add file && GIT_AUTHOR_NAME="Old Name" GIT_AUTHOR_EMAIL=old@example.com \ + GIT_COMMITTER_NAME="Old Name" GIT_COMMITTER_EMAIL=old@example.com \ git commit -m "first commit" && GIT_COMMITTER_NAME="Old Name" GIT_COMMITTER_EMAIL=old@example.com \ git tag -a -m "a tag" v1 && + git checkout -b side && + echo "Branch Name " >.mailmap && + git add .mailmap && + git commit -m "a mailmap of its own" && + git checkout - && echo "New Name " >.mailmap && git add .mailmap && - git commit -m "add the mailmap" - ) + git commit -m "add the mailmap" && + echo "Leaked Blob " >other.mailmap && + git add other.mailmap && + git commit -m "add another mailmap" && + echo "Leaked File " >../file.mailmap && + git config mailmap.file "$(pwd)/../file.mailmap" && + git config mailmap.blob HEAD:other.mailmap && + unset GIT_AUTHOR_DATE GIT_COMMITTER_DATE && + GIT_AUTHOR_NAME="Old Name" GIT_AUTHOR_EMAIL=old@example.com \ + git commit --allow-empty -m "fresh commit" + ) && + cgitrc_repo mappedrc mapped ' -test_expect_success 'point cgit at it' ' - cat >cgitrc <<-EOF - virtual-root=/ - cache-size=0 - repo.url=mapped - repo.path=$PWD/repos/mapped/.git - EOF +test_expect_success 'the log shows the mapped author' ' + cgit_ok mappedrc "url=mapped/log/" >tmp && + grep ">first commit" tmp && + grep "New Name" tmp && + ! grep "Old Name" tmp ' -test_expect_success 'the log shows the mapped author' ' - cgit_url "mapped/log/" >tmp && +test_expect_success 'so does the summary' ' + cgit_ok mappedrc "url=mapped/" >tmp && grep ">first commit" tmp && grep "New Name" tmp && ! grep "Old Name" tmp ' -test_expect_success 'the commit page shows the mapped author and address' ' - first=$(git -C repos/mapped rev-parse HEAD~1) && - cgit_url "mapped/commit/&id=$first" >tmp && +test_expect_success 'the commit page maps both the author and the committer' ' + first=$(git -C repos/mapped rev-parse HEAD~3) && + cgit_ok mappedrc "url=mapped/commit/&id=$first" >tmp && grep "authorNew Name <new@example.com>" tmp && + grep "committerNew Name <new@example.com>" tmp && ! grep "old@example.com" tmp ' test_expect_success 'the tag page shows the mapped tagger' ' - cgit_url "mapped/tag/&h=v1" >tmp && - grep "New Name <new@example.com>" tmp && + cgit_ok mappedrc "url=mapped/tag/&h=v1" >tmp && + grep "tagged byNew Name <new@example.com>" tmp && ! grep "Old Name" tmp ' test_expect_success 'the atom feed uses the mapped name and address' ' - cgit_url "mapped/atom/" >tmp && + cgit_ok mappedrc "url=mapped/atom/" >tmp && grep "New Name" tmp && grep "new@example.com" tmp && ! grep "Old Name" tmp ' -test_expect_success 'the author search matches the mapped name' ' - cgit_url "mapped/log/&qt=author&q=New+Name" >tmp && +test_expect_success 'the blame page shows the mapped author' ' + cgitrc_repo blamerc mapped enable-blame=1 && + cgit_ok blamerc "url=mapped/blame/file" >tmp && + grep "title=.author New Name <new@example.com> " tmp && + ! grep "Old Name" tmp +' + +test_expect_success 'the stats page counts the mapped author' ' + cgitrc_repo statsrc mapped max-stats=year && + cgit_ok statsrc "url=mapped/stats/&period=y" >tmp && + grep "New Name" tmp && + ! grep "Old Name" tmp +' + +test_expect_success 'the author search matches the mapped name alone' ' + cgit_ok mappedrc "url=mapped/log/&qt=author&q=New+Name" >tmp && grep ">first commit" tmp && - cgit_url "mapped/log/&qt=author&q=Nobody" >tmp && + cgit_ok mappedrc "url=mapped/log/&qt=author&q=Old+Name" >tmp && + grep "No commits match the search" tmp && + ! grep ">first commit" tmp && + cgit_ok mappedrc "url=mapped/log/&qt=author&q=Nobody" >tmp && + grep "No commits match the search" tmp && ! grep ">first commit" tmp ' +test_expect_success 'a mailmap anywhere but the blob at HEAD changes nothing' ' + cgit_ok mappedrc "url=mapped/log/&h=side" >tmp && + grep "New Name" tmp && + ! grep "Branch Name" tmp && + first=$(git -C repos/mapped rev-parse HEAD~3) && + cgit_ok mappedrc "url=mapped/commit/&id=$first" >tmp && + grep "committerNew Name" tmp && + cgit_ok mappedrc "url=mapped/commit/" >tmp && + grep "committerC O Mitter <committer@example.com>" tmp && + ! grep "Leaked" tmp +' + test_expect_success 'with the flag off the old ident shows' ' - { - echo "enable-mailmap=0" && - cat cgitrc - } >cgitrc-off && - cgit_rc cgitrc-off "url=mapped/log/" >tmp && + cgitrc_repo offrc mapped enable-mailmap=0 && + cgit_ok offrc "url=mapped/log/" >tmp && grep "Old Name" tmp ' test_expect_success 'the repository flag overrides the global one' ' - echo "repo.enable-mailmap=0" >>cgitrc && - cgit_url "mapped/log/" >tmp && - grep "Old Name" tmp + cgitrc_repo repooffrc mapped repo.enable-mailmap=0 && + cgit_ok repooffrc "url=mapped/log/" >tmp && + grep "Old Name" tmp && + cgitrc_repo repoonrc mapped enable-mailmap=0 repo.enable-mailmap=1 && + cgit_ok repoonrc "url=mapped/log/" >tmp && + grep "New Name" tmp && + ! grep "Old Name" tmp ' test_done -- cgit 2.12.1