1#!/bin/sh
   2test_description='.mailmap configurations'
   4. ./test-lib.sh
   6test_expect_success setup '
   8        echo one >one &&
   9        git add one &&
  10        test_tick &&
  11        git commit -m initial &&
  12        echo two >>one &&
  13        git add one &&
  14        git commit --author "nick1 <bugs@company.xx>" -m second
  15'
  16cat >expect <<\EOF
  18A U Thor (1):
  19      initial
  20nick1 (1):
  22      second
  23EOF
  25test_expect_success 'No mailmap' '
  27        git shortlog HEAD >actual &&
  28        test_cmp expect actual
  29'
  30cat >expect <<\EOF
  32Repo Guy (1):
  33      initial
  34nick1 (1):
  36      second
  37EOF
  39test_expect_success 'default .mailmap' '
  41        echo "Repo Guy <author@example.com>" > .mailmap &&
  42        git shortlog HEAD >actual &&
  43        test_cmp expect actual
  44'
  45# Using a mailmap file in a subdirectory of the repo here, but
  47# could just as well have been a file outside of the repository
  48cat >expect <<\EOF
  49Internal Guy (1):
  50      second
  51Repo Guy (1):
  53      initial
  54EOF
  56test_expect_success 'mailmap.file set' '
  57        mkdir internal_mailmap &&
  58        echo "Internal Guy <bugs@company.xx>" > internal_mailmap/.mailmap &&
  59        git config mailmap.file internal_mailmap/.mailmap &&
  60        git shortlog HEAD >actual &&
  61        test_cmp expect actual
  62'
  63cat >expect <<\EOF
  65External Guy (1):
  66      initial
  67Internal Guy (1):
  69      second
  70EOF
  72test_expect_success 'mailmap.file override' '
  73        echo "External Guy <author@example.com>" >> internal_mailmap/.mailmap &&
  74        git config mailmap.file internal_mailmap/.mailmap &&
  75        git shortlog HEAD >actual &&
  76        test_cmp expect actual
  77'
  78cat >expect <<\EOF
  80Repo Guy (1):
  81      initial
  82nick1 (1):
  84      second
  85EOF
  87test_expect_success 'mailmap.file non-existant' '
  89        rm internal_mailmap/.mailmap &&
  90        rmdir internal_mailmap &&
  91        git shortlog HEAD >actual &&
  92        test_cmp expect actual
  93'
  94cat >expect <<\EOF
  96A U Thor (1):
  97      initial
  98nick1 (1):
 100      second
 101EOF
 103test_expect_success 'No mailmap files, but configured' '
 104        rm .mailmap &&
 105        git shortlog HEAD >actual &&
 106        test_cmp expect actual
 107'
 108# Extended mailmap configurations should give us the following output for shortlog
 110cat >expect <<\EOF
 111A U Thor <author@example.com> (1):
 112      initial
 113CTO <cto@company.xx> (1):
 115      seventh
 116Other Author <other@author.xx> (2):
 118      third
 119      fourth
 120Santa Claus <santa.claus@northpole.xx> (2):
 122      fifth
 123      sixth
 124Some Dude <some@dude.xx> (1):
 126      second
 127EOF
 129test_expect_success 'Shortlog output (complex mapping)' '
 131        echo three >>one &&
 132        git add one &&
 133        test_tick &&
 134        git commit --author "nick2 <bugs@company.xx>" -m third &&
 135        echo four >>one &&
 137        git add one &&
 138        test_tick &&
 139        git commit --author "nick2 <nick2@company.xx>" -m fourth &&
 140        echo five >>one &&
 142        git add one &&
 143        test_tick &&
 144        git commit --author "santa <me@company.xx>" -m fifth &&
 145        echo six >>one &&
 147        git add one &&
 148        test_tick &&
 149        git commit --author "claus <me@company.xx>" -m sixth &&
 150        echo seven >>one &&
 152        git add one &&
 153        test_tick &&
 154        git commit --author "CTO <cto@coompany.xx>" -m seventh &&
 155        mkdir internal_mailmap &&
 157        echo "Committed <committer@example.com>" > internal_mailmap/.mailmap &&
 158        echo "<cto@company.xx>                       <cto@coompany.xx>" >> internal_mailmap/.mailmap &&
 159        echo "Some Dude <some@dude.xx>         nick1 <bugs@company.xx>" >> internal_mailmap/.mailmap &&
 160        echo "Other Author <other@author.xx>   nick2 <bugs@company.xx>" >> internal_mailmap/.mailmap &&
 161        echo "Other Author <other@author.xx>         <nick2@company.xx>" >> internal_mailmap/.mailmap &&
 162        echo "Santa Claus <santa.claus@northpole.xx> <me@company.xx>" >> internal_mailmap/.mailmap &&
 163        echo "Santa Claus <santa.claus@northpole.xx> <me@company.xx>" >> internal_mailmap/.mailmap &&
 164        git shortlog -e HEAD >actual &&
 166        test_cmp expect actual
 167'
 169# git log with --pretty format which uses the name and email mailmap placemarkers
 171cat >expect <<\EOF
 172Author CTO <cto@coompany.xx> maps to CTO <cto@company.xx>
 173Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
 174Author claus <me@company.xx> maps to Santa Claus <santa.claus@northpole.xx>
 176Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
 177Author santa <me@company.xx> maps to Santa Claus <santa.claus@northpole.xx>
 179Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
 180Author nick2 <nick2@company.xx> maps to Other Author <other@author.xx>
 182Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
 183Author nick2 <bugs@company.xx> maps to Other Author <other@author.xx>
 185Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
 186Author nick1 <bugs@company.xx> maps to Some Dude <some@dude.xx>
 188Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
 189Author A U Thor <author@example.com> maps to A U Thor <author@example.com>
 191Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
 192EOF
 193test_expect_success 'Log output (complex mapping)' '
 195        git log --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
 196        test_cmp expect actual
 197'
 198# git blame
 200cat >expect <<\EOF
 201^3a2fdcb (A U Thor     2005-04-07 15:13:13 -0700 1) one
 2027de6f99b (Some Dude    2005-04-07 15:13:13 -0700 2) two
 2035815879d (Other Author 2005-04-07 15:14:13 -0700 3) three
 204ff859d96 (Other Author 2005-04-07 15:15:13 -0700 4) four
 2055ab6d4fa (Santa Claus  2005-04-07 15:16:13 -0700 5) five
 20638a42d8b (Santa Claus  2005-04-07 15:17:13 -0700 6) six
 2078ddc0386 (CTO          2005-04-07 15:18:13 -0700 7) seven
 208EOF
 209test_expect_success 'Blame output (complex mapping)' '
 211        git blame one >actual &&
 212        test_cmp expect actual
 213'
 214test_done