t / t4201-shortlog.shon commit remote: add a macro for "refs/tags/*:refs/tags/*" (750d0da)
   1#!/bin/sh
   2#
   3# Copyright (c) 2006 Johannes E. Schindelin
   4#
   5
   6test_description='git shortlog
   7'
   8
   9. ./test-lib.sh
  10
  11test_expect_success 'setup' '
  12        test_tick &&
  13        echo 1 >a1 &&
  14        git add a1 &&
  15        tree=$(git write-tree) &&
  16        commit=$(printf "%s\n" "Test" "" | git commit-tree "$tree") &&
  17        git update-ref HEAD "$commit" &&
  18
  19        echo 2 >a1 &&
  20        git commit --quiet -m "This is a very, very long first line for the commit message to see if it is wrapped correctly" a1 &&
  21
  22        # test if the wrapping is still valid
  23        # when replacing all is by treble clefs.
  24        echo 3 >a1 &&
  25        git commit --quiet -m "$(
  26                echo "This is a very, very long first line for the commit message to see if it is wrapped correctly" |
  27                sed "s/i/1234/g" |
  28                tr 1234 "\360\235\204\236")" a1 &&
  29
  30        # now fsck up the utf8
  31        git config i18n.commitencoding non-utf-8 &&
  32        echo 4 >a1 &&
  33        git commit --quiet -m "$(
  34                echo "This is a very, very long first line for the commit message to see if it is wrapped correctly" |
  35                sed "s/i/1234/g" |
  36                tr 1234 "\370\235\204\236")" a1 &&
  37
  38        echo 5 >a1 &&
  39        git commit --quiet -m "a                                                                12      34      56      78" a1 &&
  40
  41        echo 6 >a1 &&
  42        git commit --quiet -m "Commit by someone else" \
  43                --author="Someone else <not!me>" a1 &&
  44
  45        cat >expect.template <<-\EOF
  46        A U Thor (5):
  47              SUBJECT
  48              SUBJECT
  49              SUBJECT
  50              SUBJECT
  51              SUBJECT
  52
  53        Someone else (1):
  54              SUBJECT
  55
  56        EOF
  57'
  58
  59fuzz() {
  60        file=$1 &&
  61        sed "
  62                        s/$_x40/OBJECT_NAME/g
  63                        s/$_x35/OBJID/g
  64                        s/^ \{6\}[CTa].*/      SUBJECT/g
  65                        s/^ \{8\}[^ ].*/        CONTINUATION/g
  66                " <"$file" >"$file.fuzzy" &&
  67        sed "/CONTINUATION/ d" <"$file.fuzzy"
  68}
  69
  70test_expect_success 'default output format' '
  71        git shortlog HEAD >log &&
  72        fuzz log >log.predictable &&
  73        test_cmp expect.template log.predictable
  74'
  75
  76test_expect_success 'pretty format' '
  77        sed s/SUBJECT/OBJECT_NAME/ expect.template >expect &&
  78        git shortlog --format="%H" HEAD >log &&
  79        fuzz log >log.predictable &&
  80        test_cmp expect log.predictable
  81'
  82
  83test_expect_success '--abbrev' '
  84        sed s/SUBJECT/OBJID/ expect.template >expect &&
  85        git shortlog --format="%h" --abbrev=35 HEAD >log &&
  86        fuzz log >log.predictable &&
  87        test_cmp expect log.predictable
  88'
  89
  90test_expect_success 'output from user-defined format is re-wrapped' '
  91        sed "s/SUBJECT/two lines/" expect.template >expect &&
  92        git shortlog --format="two%nlines" HEAD >log &&
  93        fuzz log >log.predictable &&
  94        test_cmp expect log.predictable
  95'
  96
  97test_expect_success !MINGW 'shortlog wrapping' '
  98        cat >expect <<\EOF &&
  99A U Thor (5):
 100      Test
 101      This is a very, very long first line for the commit message to see if
 102         it is wrapped correctly
 103      Th𝄞s 𝄞s a very, very long f𝄞rst l𝄞ne for the comm𝄞t message to see 𝄞f
 104         𝄞t 𝄞s wrapped correctly
 105      Thø\9d\84\9es ø\9d\84\9es a very, very long fø\9d\84\9erst lø\9d\84\9ene for the commø\9d\84\9et
 106         message to see ø\9d\84\9ef ø\9d\84\9et ø\9d\84\9es wrapped correctly
 107      a                                                         12      34
 108         56     78
 109
 110Someone else (1):
 111      Commit by someone else
 112
 113EOF
 114        git shortlog -w HEAD >out &&
 115        test_cmp expect out
 116'
 117
 118test_expect_success !MINGW 'shortlog from non-git directory' '
 119        git log --no-expand-tabs HEAD >log &&
 120        GIT_DIR=non-existing git shortlog -w <log >out &&
 121        test_cmp expect out
 122'
 123
 124test_expect_success !MINGW 'shortlog can read --format=raw output' '
 125        git log --format=raw HEAD >log &&
 126        GIT_DIR=non-existing git shortlog -w <log >out &&
 127        test_cmp expect out
 128'
 129
 130test_expect_success 'shortlog should add newline when input line matches wraplen' '
 131        cat >expect <<\EOF &&
 132A U Thor (2):
 133      bbbbbbbbbbbbbbbbbb: bbbbbbbb bbb bbbb bbbbbbb bb bbbb bbb bbbbb bbbbbb
 134      aaaaaaaaaaaaaaaaaaaaaa: aaaaaa aaaaaaaaaa aaaa aaaaaaaa aa aaaa aa aaa
 135
 136EOF
 137        git shortlog -w >out <<\EOF &&
 138commit 0000000000000000000000000000000000000001
 139Author: A U Thor <author@example.com>
 140Date:   Thu Apr 7 15:14:13 2005 -0700
 141
 142    aaaaaaaaaaaaaaaaaaaaaa: aaaaaa aaaaaaaaaa aaaa aaaaaaaa aa aaaa aa aaa
 143
 144commit 0000000000000000000000000000000000000002
 145Author: A U Thor <author@example.com>
 146Date:   Thu Apr 7 15:14:13 2005 -0700
 147
 148    bbbbbbbbbbbbbbbbbb: bbbbbbbb bbb bbbb bbbbbbb bb bbbb bbb bbbbb bbbbbb
 149
 150EOF
 151        test_cmp expect out
 152'
 153
 154iconvfromutf8toiso88591() {
 155        printf "%s" "$*" | iconv -f UTF-8 -t ISO8859-1
 156}
 157
 158DSCHO="Jöhännës \"Dschö\" Schindëlin"
 159DSCHOE="$DSCHO <Johannes.Schindelin@gmx.de>"
 160MSG1="set a1 to 2 and some non-ASCII chars: Äßø"
 161MSG2="set a1 to 3 and some non-ASCII chars: áæï"
 162cat > expect << EOF
 163$DSCHO (2):
 164      $MSG1
 165      $MSG2
 166
 167EOF
 168
 169test_expect_success !MINGW 'shortlog encoding' '
 170        git reset --hard "$commit" &&
 171        git config --unset i18n.commitencoding &&
 172        echo 2 > a1 &&
 173        git commit --quiet -m "$MSG1" --author="$DSCHOE" a1 &&
 174        git config i18n.commitencoding "ISO8859-1" &&
 175        echo 3 > a1 &&
 176        git commit --quiet -m "$(iconvfromutf8toiso88591 "$MSG2")" \
 177                --author="$(iconvfromutf8toiso88591 "$DSCHOE")" a1 &&
 178        git config --unset i18n.commitencoding &&
 179        git shortlog HEAD~2.. > out &&
 180test_cmp expect out'
 181
 182test_expect_success 'shortlog with revision pseudo options' '
 183        git shortlog --all &&
 184        git shortlog --branches &&
 185        git shortlog --exclude=refs/heads/m* --all
 186'
 187
 188test_expect_success 'shortlog with --output=<file>' '
 189        git shortlog --output=shortlog -1 master >output &&
 190        test ! -s output &&
 191        test_line_count = 3 shortlog
 192'
 193
 194test_expect_success 'shortlog --committer (internal)' '
 195        git checkout --orphan side &&
 196        git commit --allow-empty -m one &&
 197        git commit --allow-empty -m two &&
 198        GIT_COMMITTER_NAME="Sin Nombre" git commit --allow-empty -m three &&
 199
 200        cat >expect <<-\EOF &&
 201             2  C O Mitter
 202             1  Sin Nombre
 203        EOF
 204        git shortlog -nsc HEAD >actual &&
 205        test_cmp expect actual
 206'
 207
 208test_expect_success 'shortlog --committer (external)' '
 209        git log --format=full | git shortlog -nsc >actual &&
 210        test_cmp expect actual
 211'
 212
 213test_done