#!/bin/sh # The mailmap. A repository whose commits and tag carry an old ident gets a # .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 && ( cd repos/mapped && 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" && 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 '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 '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 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_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_ok mappedrc "url=mapped/atom/" >tmp && grep "New Name" tmp && grep "new@example.com" tmp && ! grep "Old 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_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' ' 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' ' 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