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