blob: ca08de06b6ec5a6c0bcafd0596c581e2f58241ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/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.

test_description='Check the mailmap is applied to idents'
CGIT_TEST_NO_CREATE_REPOS=YesPlease
. ./setup.sh

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 commit -m "first commit" &&
		GIT_COMMITTER_NAME="Old Name" GIT_COMMITTER_EMAIL=old@example.com \
			git tag -a -m "a tag" v1 &&
		echo "New Name <new@example.com> <old@example.com>" >.mailmap &&
		git add .mailmap &&
		git commit -m "add the mailmap"
	)
'

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_url "mapped/log/" >tmp &&
	grep ">first commit</a>" tmp &&
	grep "<td class=.col-author.>New Name</td>" 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 &&
	grep "<th>author</th><td>New Name &lt;new@example.com&gt;</td>" 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 &lt;new@example.com&gt;" tmp &&
	! grep "Old Name" tmp
'

test_expect_success 'the atom feed uses the mapped name and address' '
	cgit_url "mapped/atom/" >tmp &&
	grep "<name>New Name</name>" tmp &&
	grep "<email>new@example.com</email>" tmp &&
	! grep "Old Name" tmp
'

test_expect_success 'the author search matches the mapped name' '
	cgit_query "url=mapped/log/&qt=author&q=New+Name" >tmp &&
	grep ">first commit</a>" tmp &&
	cgit_query "url=mapped/log/&qt=author&q=Nobody" >tmp &&
	! grep ">first commit</a>" tmp
'

test_expect_success 'with the flag off the old ident shows' '
	{
		echo "enable-mailmap=0" &&
		cat cgitrc
	} >cgitrc-off &&
	CGIT_CONFIG="$PWD/cgitrc-off" QUERY_STRING="url=mapped/log/" cgit >tmp &&
	grep "<td class=.col-author.>Old Name</td>" tmp
'

test_expect_success 'the repository flag overrides the global one' '
	echo "repo.enable-mailmap=0" >>cgitrc &&
	cgit_url "mapped/log/" >tmp &&
	grep "<td class=.col-author.>Old Name</td>" tmp
'

test_done