Johannes Schindelin | 3714e7c | 2006-12-22 22:15:59 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2006 Johannes E. Schindelin |
| 4 | # |
| 5 | |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 6 | test_description='git shortlog |
Johannes Schindelin | 3714e7c | 2006-12-22 22:15:59 +0100 | [diff] [blame] | 7 | ' |
| 8 | |
| 9 | . ./test-lib.sh |
| 10 | |
Jonathan Nieder | ae00dc1 | 2010-05-03 21:57:36 -0500 | [diff] [blame] | 11 | test_expect_success 'setup' ' |
Charles Bailey | 5555a2a | 2017-11-12 15:25:23 +0000 | [diff] [blame] | 12 | test_tick && |
Jonathan Nieder | ae00dc1 | 2010-05-03 21:57:36 -0500 | [diff] [blame] | 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" && |
Johannes Schindelin | 3714e7c | 2006-12-22 22:15:59 +0100 | [diff] [blame] | 18 | |
Jonathan Nieder | ae00dc1 | 2010-05-03 21:57:36 -0500 | [diff] [blame] | 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 && |
Johannes Schindelin | 3714e7c | 2006-12-22 22:15:59 +0100 | [diff] [blame] | 21 | |
Jonathan Nieder | ae00dc1 | 2010-05-03 21:57:36 -0500 | [diff] [blame] | 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 && |
Johannes Schindelin | 3714e7c | 2006-12-22 22:15:59 +0100 | [diff] [blame] | 29 | |
Jonathan Nieder | ae00dc1 | 2010-05-03 21:57:36 -0500 | [diff] [blame] | 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 && |
Johannes Schindelin | 3714e7c | 2006-12-22 22:15:59 +0100 | [diff] [blame] | 37 | |
Jonathan Nieder | ae00dc1 | 2010-05-03 21:57:36 -0500 | [diff] [blame] | 38 | echo 5 >a1 && |
Jonathan Nieder | a48fcd8 | 2010-10-30 20:46:54 -0500 | [diff] [blame] | 39 | git commit --quiet -m "a 12 34 56 78" a1 && |
Jonathan Nieder | ed715b5 | 2010-05-03 21:58:04 -0500 | [diff] [blame] | 40 | |
| 41 | echo 6 >a1 && |
| 42 | git commit --quiet -m "Commit by someone else" \ |
Jonathan Nieder | 6003724 | 2010-05-03 21:59:55 -0500 | [diff] [blame] | 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 | |
| 59 | fuzz() { |
| 60 | file=$1 && |
| 61 | sed " |
brian m. carlson | 2ece6ad | 2018-05-13 02:24:15 +0000 | [diff] [blame] | 62 | s/$OID_REGEX/OBJECT_NAME/g |
Charles Bailey | 5555a2a | 2017-11-12 15:25:23 +0000 | [diff] [blame] | 63 | s/$_x35/OBJID/g |
Jonathan Nieder | 6003724 | 2010-05-03 21:59:55 -0500 | [diff] [blame] | 64 | s/^ \{6\}[CTa].*/ SUBJECT/g |
| 65 | s/^ \{8\}[^ ].*/ CONTINUATION/g |
| 66 | " <"$file" >"$file.fuzzy" && |
| 67 | sed "/CONTINUATION/ d" <"$file.fuzzy" |
| 68 | } |
| 69 | |
| 70 | test_expect_success 'default output format' ' |
| 71 | git shortlog HEAD >log && |
| 72 | fuzz log >log.predictable && |
| 73 | test_cmp expect.template log.predictable |
| 74 | ' |
| 75 | |
| 76 | test_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 | |
Will Palmer | c197702 | 2010-05-03 22:18:57 -0500 | [diff] [blame] | 83 | test_expect_success '--abbrev' ' |
Jonathan Nieder | 6003724 | 2010-05-03 21:59:55 -0500 | [diff] [blame] | 84 | sed s/SUBJECT/OBJID/ expect.template >expect && |
Charles Bailey | 5555a2a | 2017-11-12 15:25:23 +0000 | [diff] [blame] | 85 | git shortlog --format="%h" --abbrev=35 HEAD >log && |
Jonathan Nieder | 6003724 | 2010-05-03 21:59:55 -0500 | [diff] [blame] | 86 | fuzz log >log.predictable && |
| 87 | test_cmp expect log.predictable |
| 88 | ' |
| 89 | |
| 90 | test_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 |
Jonathan Nieder | ae00dc1 | 2010-05-03 21:57:36 -0500 | [diff] [blame] | 95 | ' |
Johannes Schindelin | 3714e7c | 2006-12-22 22:15:59 +0100 | [diff] [blame] | 96 | |
Junio C Hamano | f57a871 | 2014-07-21 15:09:27 -0700 | [diff] [blame] | 97 | test_expect_success !MINGW 'shortlog wrapping' ' |
Jonathan Nieder | ae00dc1 | 2010-05-03 21:57:36 -0500 | [diff] [blame] | 98 | cat >expect <<\EOF && |
Johannes Schindelin | 3714e7c | 2006-12-22 22:15:59 +0100 | [diff] [blame] | 99 | A 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øs øs a very, very long først løne for the commøt |
| 106 | message to see øf øt øs wrapped correctly |
| 107 | a 12 34 |
| 108 | 56 78 |
| 109 | |
Jonathan Nieder | ed715b5 | 2010-05-03 21:58:04 -0500 | [diff] [blame] | 110 | Someone else (1): |
| 111 | Commit by someone else |
| 112 | |
Johannes Schindelin | 3714e7c | 2006-12-22 22:15:59 +0100 | [diff] [blame] | 113 | EOF |
Jonathan Nieder | ae00dc1 | 2010-05-03 21:57:36 -0500 | [diff] [blame] | 114 | git shortlog -w HEAD >out && |
| 115 | test_cmp expect out |
| 116 | ' |
Johannes Schindelin | 3714e7c | 2006-12-22 22:15:59 +0100 | [diff] [blame] | 117 | |
Junio C Hamano | f57a871 | 2014-07-21 15:09:27 -0700 | [diff] [blame] | 118 | test_expect_success !MINGW 'shortlog from non-git directory' ' |
Junio C Hamano | 0893eec | 2016-03-29 15:49:24 -0700 | [diff] [blame] | 119 | git log --no-expand-tabs HEAD >log && |
Jonathan Nieder | ae00dc1 | 2010-05-03 21:57:36 -0500 | [diff] [blame] | 120 | GIT_DIR=non-existing git shortlog -w <log >out && |
| 121 | test_cmp expect out |
| 122 | ' |
Jonas Fonseca | abe549e | 2008-03-14 22:35:24 +0100 | [diff] [blame] | 123 | |
Jeff King | 5c3894c | 2016-01-18 15:02:40 -0500 | [diff] [blame] | 124 | test_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 | |
Martin Ågren | 4aa0161 | 2018-03-14 22:34:19 +0100 | [diff] [blame] | 130 | test_expect_success 'shortlog from non-git directory refuses extra arguments' ' |
| 131 | test_must_fail env GIT_DIR=non-existing git shortlog foo 2>out && |
| 132 | test_i18ngrep "too many arguments" out |
| 133 | ' |
| 134 | |
Steffen Prohaska | 5b59708 | 2012-12-11 06:59:21 +0100 | [diff] [blame] | 135 | test_expect_success 'shortlog should add newline when input line matches wraplen' ' |
| 136 | cat >expect <<\EOF && |
| 137 | A U Thor (2): |
| 138 | bbbbbbbbbbbbbbbbbb: bbbbbbbb bbb bbbb bbbbbbb bb bbbb bbb bbbbb bbbbbb |
| 139 | aaaaaaaaaaaaaaaaaaaaaa: aaaaaa aaaaaaaaaa aaaa aaaaaaaa aa aaaa aa aaa |
| 140 | |
| 141 | EOF |
| 142 | git shortlog -w >out <<\EOF && |
| 143 | commit 0000000000000000000000000000000000000001 |
| 144 | Author: A U Thor <author@example.com> |
| 145 | Date: Thu Apr 7 15:14:13 2005 -0700 |
| 146 | |
| 147 | aaaaaaaaaaaaaaaaaaaaaa: aaaaaa aaaaaaaaaa aaaa aaaaaaaa aa aaaa aa aaa |
| 148 | |
| 149 | commit 0000000000000000000000000000000000000002 |
| 150 | Author: A U Thor <author@example.com> |
| 151 | Date: Thu Apr 7 15:14:13 2005 -0700 |
| 152 | |
| 153 | bbbbbbbbbbbbbbbbbb: bbbbbbbb bbb bbbb bbbbbbb bb bbbb bbb bbbbb bbbbbb |
| 154 | |
| 155 | EOF |
| 156 | test_cmp expect out |
| 157 | ' |
| 158 | |
Uwe Kleine-König | 79f7ca0 | 2009-11-25 20:33:28 +0100 | [diff] [blame] | 159 | iconvfromutf8toiso88591() { |
Brandon Casey | 3994e8a | 2009-12-03 11:52:45 -0600 | [diff] [blame] | 160 | printf "%s" "$*" | iconv -f UTF-8 -t ISO8859-1 |
Uwe Kleine-König | 79f7ca0 | 2009-11-25 20:33:28 +0100 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | DSCHO="Jöhännës \"Dschö\" Schindëlin" |
| 164 | DSCHOE="$DSCHO <Johannes.Schindelin@gmx.de>" |
| 165 | MSG1="set a1 to 2 and some non-ASCII chars: ÃÃø" |
| 166 | MSG2="set a1 to 3 and some non-ASCII chars: áæï" |
| 167 | cat > expect << EOF |
| 168 | $DSCHO (2): |
| 169 | $MSG1 |
| 170 | $MSG2 |
| 171 | |
| 172 | EOF |
| 173 | |
Junio C Hamano | f57a871 | 2014-07-21 15:09:27 -0700 | [diff] [blame] | 174 | test_expect_success !MINGW 'shortlog encoding' ' |
Uwe Kleine-König | 79f7ca0 | 2009-11-25 20:33:28 +0100 | [diff] [blame] | 175 | git reset --hard "$commit" && |
| 176 | git config --unset i18n.commitencoding && |
| 177 | echo 2 > a1 && |
| 178 | git commit --quiet -m "$MSG1" --author="$DSCHOE" a1 && |
Brandon Casey | 3994e8a | 2009-12-03 11:52:45 -0600 | [diff] [blame] | 179 | git config i18n.commitencoding "ISO8859-1" && |
Uwe Kleine-König | 79f7ca0 | 2009-11-25 20:33:28 +0100 | [diff] [blame] | 180 | echo 3 > a1 && |
| 181 | git commit --quiet -m "$(iconvfromutf8toiso88591 "$MSG2")" \ |
| 182 | --author="$(iconvfromutf8toiso88591 "$DSCHOE")" a1 && |
| 183 | git config --unset i18n.commitencoding && |
| 184 | git shortlog HEAD~2.. > out && |
| 185 | test_cmp expect out' |
| 186 | |
Junio C Hamano | eb07774 | 2014-05-30 12:57:25 -0700 | [diff] [blame] | 187 | test_expect_success 'shortlog with revision pseudo options' ' |
| 188 | git shortlog --all && |
| 189 | git shortlog --branches && |
| 190 | git shortlog --exclude=refs/heads/m* --all |
| 191 | ' |
| 192 | |
Johannes Schindelin | 7f7d712 | 2016-06-22 17:02:07 +0200 | [diff] [blame] | 193 | test_expect_success 'shortlog with --output=<file>' ' |
Johannes Schindelin | bac233f | 2016-07-11 15:11:37 +0200 | [diff] [blame] | 194 | git shortlog --output=shortlog -1 master >output && |
Johannes Schindelin | 7f7d712 | 2016-06-22 17:02:07 +0200 | [diff] [blame] | 195 | test ! -s output && |
Johannes Schindelin | bac233f | 2016-07-11 15:11:37 +0200 | [diff] [blame] | 196 | test_line_count = 3 shortlog |
Johannes Schindelin | 7f7d712 | 2016-06-22 17:02:07 +0200 | [diff] [blame] | 197 | ' |
| 198 | |
Jeff King | 03f4082 | 2016-12-16 08:51:41 -0500 | [diff] [blame] | 199 | test_expect_success 'shortlog --committer (internal)' ' |
Junio C Hamano | bc44f93 | 2016-12-20 10:35:54 -0800 | [diff] [blame] | 200 | git checkout --orphan side && |
| 201 | git commit --allow-empty -m one && |
| 202 | git commit --allow-empty -m two && |
| 203 | GIT_COMMITTER_NAME="Sin Nombre" git commit --allow-empty -m three && |
| 204 | |
Jeff King | 03f4082 | 2016-12-16 08:51:41 -0500 | [diff] [blame] | 205 | cat >expect <<-\EOF && |
Junio C Hamano | bc44f93 | 2016-12-20 10:35:54 -0800 | [diff] [blame] | 206 | 2 C O Mitter |
| 207 | 1 Sin Nombre |
Jeff King | 03f4082 | 2016-12-16 08:51:41 -0500 | [diff] [blame] | 208 | EOF |
| 209 | git shortlog -nsc HEAD >actual && |
| 210 | test_cmp expect actual |
| 211 | ' |
| 212 | |
| 213 | test_expect_success 'shortlog --committer (external)' ' |
| 214 | git log --format=full | git shortlog -nsc >actual && |
| 215 | test_cmp expect actual |
| 216 | ' |
| 217 | |
Johannes Schindelin | 3714e7c | 2006-12-22 22:15:59 +0100 | [diff] [blame] | 218 | test_done |