Skip to content

Commit 05b5ff2

Browse files
avargitster
authored andcommitted
mailmap doc + tests: add better examples & test them
Change the mailmap documentation added in 0925ce4 (Add map_user() and clear_mailmap() to mailmap, 2009-02-08) to continue discussing the Jane/Joe example. I think this makes things a lot less confusing as we're building up more complex examples using one set of data which covers all the things we'd like to discuss. Also add tests to assert that what our documentation says is what's actually happening. This is mostly (or entirely) covered by existing tests which I'm not deleting, but having these tests for the synopsis makes it easier to follow-along while reading the tests & docs. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f5d79bf commit 05b5ff2

File tree

2 files changed

+117
-20
lines changed

2 files changed

+117
-20
lines changed

Documentation/gitmailmap.txt

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ commit matching both the specified commit name and email address.
5353
EXAMPLES
5454
--------
5555

56-
Example 1: Your history contains commits by two authors, Jane
56+
Your history contains commits by two authors, Jane
5757
and Joe, whose names appear in the repository under several forms:
5858

5959
------------
@@ -65,36 +65,45 @@ Jane D. <jane@desktop.(none)>
6565
------------
6666

6767
Now suppose that Joe wants his middle name initial used, and Jane
68-
prefers her family name fully spelled out. A proper `.mailmap` file
69-
would look like:
68+
prefers her family name fully spelled out. A `.mailmap` file to
69+
correct the names would look like:
7070

7171
------------
72-
Jane Doe <jane@desktop.(none)>
7372
Joe R. Developer <[email protected]>
73+
74+
Jane Doe <jane@desktop.(none)>
7475
------------
7576

76-
Note how there is no need for an entry for `<jane@laptop.(none)>`, because the
77-
real name of that author is already correct.
77+
Note that there's no need to map the name for 'jane@laptop.(none)' to
78+
only correct the names. However, leaving the obviously broken
79+
`<jane@laptop.(none)>' and '<jane@desktop.(none)>' E-Mails as-is is
80+
usually not what you want. A `.mailmap` file which also corrects those
81+
is:
7882

79-
Example 2: Your repository contains commits from the following
80-
authors:
83+
------------
84+
Joe R. Developer <[email protected]>
85+
Jane Doe <[email protected]> <jane@laptop.(none)>
86+
Jane Doe <[email protected]> <jane@desktop.(none)>
87+
------------
88+
89+
Finally, let's say that Joe and Jane shared an E-Mail address, but not
90+
a name, e.g. by having these two commits in the history generated by a
91+
bug reporting system. I.e. names appearing in history as:
8192

8293
------------
83-
84-
85-
86-
87-
88-
94+
95+
8996
------------
9097

91-
Then you might want a `.mailmap` file that looks like:
98+
A full `.mailmap` file which also handles those cases (an addition of
99+
two lines to the above example) would be:
100+
92101
------------
93-
94-
95-
Other Author <[email protected]> nick2 <[email protected]>
96-
97-
102+
Joe R. Developer <[email protected]>
103+
Jane Doe <[email protected]> <jane@laptop.(none)>
104+
Jane Doe <[email protected]> <jane@desktop.(none)>
105+
Joe R. Developer <[email protected]> Joe <[email protected]>
106+
98107
------------
99108

100109

t/t4203-mailmap.sh

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,94 @@ test_expect_success 'preserve canonical email case' '
419419
test_cmp expect actual
420420
'
421421

422+
test_expect_success 'gitmailmap(5) example output: setup' '
423+
test_create_repo doc &&
424+
test_commit -C doc --author "Joe Developer <[email protected]>" A &&
425+
test_commit -C doc --author "Joe R. Developer <[email protected]>" B &&
426+
test_commit -C doc --author "Jane Doe <[email protected]>" C &&
427+
test_commit -C doc --author "Jane Doe <jane@laptop.(none)>" D &&
428+
test_commit -C doc --author "Jane D. <jane@desktop.(none)>" E
429+
'
430+
431+
test_expect_success 'gitmailmap(5) example output: example #1' '
432+
test_config -C doc mailmap.file ../doc.map &&
433+
cat >doc.map <<-\EOF &&
434+
Joe R. Developer <[email protected]>
435+
Jane Doe <[email protected]>
436+
Jane Doe <jane@desktop.(none)>
437+
EOF
438+
439+
cat >expect <<-\EOF &&
440+
Author Joe Developer <[email protected]> maps to Joe R. Developer <[email protected]>
441+
Committer C O Mitter <[email protected]> maps to C O Mitter <[email protected]>
442+
443+
Author Joe R. Developer <[email protected]> maps to Joe R. Developer <[email protected]>
444+
Committer C O Mitter <[email protected]> maps to C O Mitter <[email protected]>
445+
446+
Author Jane Doe <[email protected]> maps to Jane Doe <[email protected]>
447+
Committer C O Mitter <[email protected]> maps to C O Mitter <[email protected]>
448+
449+
Author Jane Doe <jane@laptop.(none)> maps to Jane Doe <jane@laptop.(none)>
450+
Committer C O Mitter <[email protected]> maps to C O Mitter <[email protected]>
451+
452+
Author Jane D <jane@desktop.(none)> maps to Jane Doe <jane@desktop.(none)>
453+
Committer C O Mitter <[email protected]> maps to C O Mitter <[email protected]>
454+
EOF
455+
git -C doc log --reverse --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
456+
test_cmp expect actual
457+
'
458+
459+
test_expect_success 'gitmailmap(5) example output: example #2' '
460+
test_config -C doc mailmap.file ../doc.map &&
461+
cat >doc.map <<-\EOF &&
462+
Joe R. Developer <[email protected]>
463+
Jane Doe <[email protected]> <jane@laptop.(none)>
464+
Jane Doe <[email protected]> <jane@desktop.(none)>
465+
EOF
466+
467+
cat >expect <<-\EOF &&
468+
Author Joe Developer <[email protected]> maps to Joe R. Developer <[email protected]>
469+
Committer C O Mitter <[email protected]> maps to C O Mitter <[email protected]>
470+
471+
Author Joe R. Developer <[email protected]> maps to Joe R. Developer <[email protected]>
472+
Committer C O Mitter <[email protected]> maps to C O Mitter <[email protected]>
473+
474+
Author Jane Doe <[email protected]> maps to Jane Doe <[email protected]>
475+
Committer C O Mitter <[email protected]> maps to C O Mitter <[email protected]>
476+
477+
Author Jane Doe <jane@laptop.(none)> maps to Jane Doe <[email protected]>
478+
Committer C O Mitter <[email protected]> maps to C O Mitter <[email protected]>
479+
480+
Author Jane D <jane@desktop.(none)> maps to Jane Doe <[email protected]>
481+
Committer C O Mitter <[email protected]> maps to C O Mitter <[email protected]>
482+
EOF
483+
git -C doc log --reverse --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
484+
test_cmp expect actual
485+
'
486+
487+
test_expect_success 'gitmailmap(5) example output: example #3' '
488+
test_config -C doc mailmap.file ../doc.map &&
489+
cat >>doc.map <<-\EOF &&
490+
Joe R. Developer <[email protected]> Joe <[email protected]>
491+
492+
EOF
493+
494+
test_commit -C doc --author "Joe <[email protected]>" F &&
495+
test_commit -C doc --author "Jane <[email protected]>" G &&
496+
497+
cat >>expect <<-\EOF &&
498+
499+
Author Joe <[email protected]> maps to Joe R. Developer <[email protected]>
500+
Committer C O Mitter <[email protected]> maps to C O Mitter <[email protected]>
501+
502+
Author Jane <[email protected]> maps to Jane Doe <[email protected]>
503+
Committer C O Mitter <[email protected]> maps to C O Mitter <[email protected]>
504+
EOF
505+
git -C doc log --reverse --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
506+
test_cmp expect actual
507+
'
508+
509+
422510
test_expect_success 'Shortlog output (complex mapping)' '
423511
test_config mailmap.file complex.map &&
424512
cat >complex.map <<-EOF &&

0 commit comments

Comments
 (0)