Imported Upstream version 2.14.5
[platform/upstream/git.git] / t / t4203-mailmap.sh
index 1f182f6..0dd8b65 100755 (executable)
@@ -13,6 +13,11 @@ fuzz_blame () {
 }
 
 test_expect_success setup '
+       cat >contacts <<-\EOF &&
+       A U Thor <author@example.com>
+       nick1 <bugs@company.xx>
+       EOF
+
        echo one >one &&
        git add one &&
        test_tick &&
@@ -23,6 +28,44 @@ test_expect_success setup '
        git commit --author "nick1 <bugs@company.xx>" -m second
 '
 
+test_expect_success 'check-mailmap no arguments' '
+       test_must_fail git check-mailmap
+'
+
+test_expect_success 'check-mailmap arguments' '
+       cat >expect <<-\EOF &&
+       A U Thor <author@example.com>
+       nick1 <bugs@company.xx>
+       EOF
+       git check-mailmap \
+               "A U Thor <author@example.com>" \
+               "nick1 <bugs@company.xx>" >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'check-mailmap --stdin' '
+       cat >expect <<-\EOF &&
+       A U Thor <author@example.com>
+       nick1 <bugs@company.xx>
+       EOF
+       git check-mailmap --stdin <contacts >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'check-mailmap --stdin arguments' '
+       cat >expect <<-\EOF &&
+       Internal Guy <bugs@company.xy>
+       EOF
+       cat <contacts >>expect &&
+       git check-mailmap --stdin "Internal Guy <bugs@company.xy>" \
+               <contacts >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'check-mailmap bogus contact' '
+       test_must_fail git check-mailmap bogus
+'
+
 cat >expect <<\EOF
 A U Thor (1):
       initial
@@ -149,6 +192,136 @@ test_expect_success 'No mailmap files, but configured' '
        test_cmp expect actual
 '
 
+test_expect_success 'setup mailmap blob tests' '
+       git checkout -b map &&
+       test_when_finished "git checkout master" &&
+       cat >just-bugs <<-\EOF &&
+       Blob Guy <bugs@company.xx>
+       EOF
+       cat >both <<-\EOF &&
+       Blob Guy <author@example.com>
+       Blob Guy <bugs@company.xx>
+       EOF
+       printf "Tricky Guy <author@example.com>" >no-newline &&
+       git add just-bugs both no-newline &&
+       git commit -m "my mailmaps" &&
+       echo "Repo Guy <author@example.com>" >.mailmap &&
+       echo "Internal Guy <author@example.com>" >internal.map
+'
+
+test_expect_success 'mailmap.blob set' '
+       cat >expect <<-\EOF &&
+       Blob Guy (1):
+             second
+
+       Repo Guy (1):
+             initial
+
+       EOF
+       git -c mailmap.blob=map:just-bugs shortlog HEAD >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'mailmap.blob overrides .mailmap' '
+       cat >expect <<-\EOF &&
+       Blob Guy (2):
+             initial
+             second
+
+       EOF
+       git -c mailmap.blob=map:both shortlog HEAD >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'mailmap.file overrides mailmap.blob' '
+       cat >expect <<-\EOF &&
+       Blob Guy (1):
+             second
+
+       Internal Guy (1):
+             initial
+
+       EOF
+       git \
+         -c mailmap.blob=map:both \
+         -c mailmap.file=internal.map \
+         shortlog HEAD >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'mailmap.blob can be missing' '
+       cat >expect <<-\EOF &&
+       Repo Guy (1):
+             initial
+
+       nick1 (1):
+             second
+
+       EOF
+       git -c mailmap.blob=map:nonexistent shortlog HEAD >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'mailmap.blob defaults to off in non-bare repo' '
+       git init non-bare &&
+       (
+               cd non-bare &&
+               test_commit one .mailmap "Fake Name <author@example.com>" &&
+               echo "     1    Fake Name" >expect &&
+               git shortlog -ns HEAD >actual &&
+               test_cmp expect actual &&
+               rm .mailmap &&
+               echo "     1    A U Thor" >expect &&
+               git shortlog -ns HEAD >actual &&
+               test_cmp expect actual
+       )
+'
+
+test_expect_success 'mailmap.blob defaults to HEAD:.mailmap in bare repo' '
+       git clone --bare non-bare bare &&
+       (
+               cd bare &&
+               echo "     1    Fake Name" >expect &&
+               git shortlog -ns HEAD >actual &&
+               test_cmp expect actual
+       )
+'
+
+test_expect_success 'mailmap.blob can handle blobs without trailing newline' '
+       cat >expect <<-\EOF &&
+       Tricky Guy (1):
+             initial
+
+       nick1 (1):
+             second
+
+       EOF
+       git -c mailmap.blob=map:no-newline shortlog HEAD >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'cleanup after mailmap.blob tests' '
+       rm -f .mailmap
+'
+
+test_expect_success 'single-character name' '
+       echo "     1    A <author@example.com>" >expect &&
+       echo "     1    nick1 <bugs@company.xx>" >>expect &&
+       echo "A <author@example.com>" >.mailmap &&
+       test_when_finished "rm .mailmap" &&
+       git shortlog -es HEAD >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'preserve canonical email case' '
+       echo "     1    A U Thor <AUTHOR@example.com>" >expect &&
+       echo "     1    nick1 <bugs@company.xx>" >>expect &&
+       echo "<AUTHOR@example.com> <author@example.com>" >.mailmap &&
+       test_when_finished "rm .mailmap" &&
+       git shortlog -es HEAD >actual &&
+       test_cmp expect actual
+'
+
 # Extended mailmap configurations should give us the following output for shortlog
 cat >expect <<\EOF
 A U Thor <author@example.com> (1):
@@ -239,6 +412,62 @@ test_expect_success 'Log output (complex mapping)' '
        test_cmp expect actual
 '
 
+cat >expect <<\EOF
+Author: CTO <cto@company.xx>
+Author: Santa Claus <santa.claus@northpole.xx>
+Author: Santa Claus <santa.claus@northpole.xx>
+Author: Other Author <other@author.xx>
+Author: Other Author <other@author.xx>
+Author: Some Dude <some@dude.xx>
+Author: A U Thor <author@example.com>
+EOF
+
+test_expect_success 'Log output with --use-mailmap' '
+       git log --use-mailmap | grep Author >actual &&
+       test_cmp expect actual
+'
+
+cat >expect <<\EOF
+Author: CTO <cto@company.xx>
+Author: Santa Claus <santa.claus@northpole.xx>
+Author: Santa Claus <santa.claus@northpole.xx>
+Author: Other Author <other@author.xx>
+Author: Other Author <other@author.xx>
+Author: Some Dude <some@dude.xx>
+Author: A U Thor <author@example.com>
+EOF
+
+test_expect_success 'Log output with log.mailmap' '
+       git -c log.mailmap=True log | grep Author >actual &&
+       test_cmp expect actual
+'
+
+cat >expect <<\EOF
+Author: Santa Claus <santa.claus@northpole.xx>
+Author: Santa Claus <santa.claus@northpole.xx>
+EOF
+
+test_expect_success 'Grep author with --use-mailmap' '
+       git log --use-mailmap --author Santa | grep Author >actual &&
+       test_cmp expect actual
+'
+cat >expect <<\EOF
+Author: Santa Claus <santa.claus@northpole.xx>
+Author: Santa Claus <santa.claus@northpole.xx>
+EOF
+
+test_expect_success 'Grep author with log.mailmap' '
+       git -c log.mailmap=True log --author Santa | grep Author >actual &&
+       test_cmp expect actual
+'
+
+>expect
+
+test_expect_success 'Only grep replaced author with --use-mailmap' '
+       git log --use-mailmap --author "<cto@coompany.xx>" >actual &&
+       test_cmp expect actual
+'
+
 # git blame
 cat >expect <<\EOF
 ^OBJI (A U Thor     DATE 1) one
@@ -255,4 +484,15 @@ test_expect_success 'Blame output (complex mapping)' '
        test_cmp expect actual.fuzz
 '
 
+cat >expect <<\EOF
+Some Dude <some@dude.xx>
+EOF
+
+test_expect_success 'commit --author honors mailmap' '
+       test_must_fail git commit --author "nick" --allow-empty -meight &&
+       git commit --author "Some Dude" --allow-empty -meight &&
+       git show --pretty=format:"%an <%ae>%n" >actual &&
+       test_cmp expect actual
+'
+
 test_done