t / t4205-log-pretty-formats.shon commit lib-gpg.sh: use the $( ... ) construct for command substitution (be194d5)
   1#!/bin/sh
   2#
   3# Copyright (c) 2010, Will Palmer
   4# Copyright (c) 2011, Alexey Shumkin (+ non-UTF-8 commit encoding tests)
   5#
   6
   7test_description='Test pretty formats'
   8. ./test-lib.sh
   9
  10sample_utf8_part=$(printf "f\303\244ng")
  11
  12commit_msg () {
  13        # String "initial. initial" partly in German
  14        # (translated with Google Translate),
  15        # encoded in UTF-8, used as a commit log message below.
  16        msg="initial. an${sample_utf8_part}lich\n"
  17        if test -n "$1"
  18        then
  19                printf "$msg" | iconv -f utf-8 -t "$1"
  20        else
  21                printf "$msg"
  22        fi
  23}
  24
  25test_expect_success 'set up basic repos' '
  26        >foo &&
  27        >bar &&
  28        git add foo &&
  29        test_tick &&
  30        git config i18n.commitEncoding iso8859-1 &&
  31        git commit -m "$(commit_msg iso8859-1)" &&
  32        git add bar &&
  33        test_tick &&
  34        git commit -m "add bar" &&
  35        git config --unset i18n.commitEncoding
  36'
  37
  38test_expect_success 'alias builtin format' '
  39        git log --pretty=oneline >expected &&
  40        git config pretty.test-alias oneline &&
  41        git log --pretty=test-alias >actual &&
  42        test_cmp expected actual
  43'
  44
  45test_expect_success 'alias masking builtin format' '
  46        git log --pretty=oneline >expected &&
  47        git config pretty.oneline "%H" &&
  48        git log --pretty=oneline >actual &&
  49        test_cmp expected actual
  50'
  51
  52test_expect_success 'alias user-defined format' '
  53        git log --pretty="format:%h" >expected &&
  54        git config pretty.test-alias "format:%h" &&
  55        git log --pretty=test-alias >actual &&
  56        test_cmp expected actual
  57'
  58
  59test_expect_success 'alias user-defined tformat with %s (iso8859-1 encoding)' '
  60        git config i18n.logOutputEncoding iso8859-1 &&
  61        git log --oneline >expected-s &&
  62        git log --pretty="tformat:%h %s" >actual-s &&
  63        git config --unset i18n.logOutputEncoding &&
  64        test_cmp expected-s actual-s
  65'
  66
  67test_expect_success 'alias user-defined tformat with %s (utf-8 encoding)' '
  68        git log --oneline >expected-s &&
  69        git log --pretty="tformat:%h %s" >actual-s &&
  70        test_cmp expected-s actual-s
  71'
  72
  73test_expect_success 'alias user-defined tformat' '
  74        git log --pretty="tformat:%h" >expected &&
  75        git config pretty.test-alias "tformat:%h" &&
  76        git log --pretty=test-alias >actual &&
  77        test_cmp expected actual
  78'
  79
  80test_expect_success 'alias non-existent format' '
  81        git config pretty.test-alias format-that-will-never-exist &&
  82        test_must_fail git log --pretty=test-alias
  83'
  84
  85test_expect_success 'alias of an alias' '
  86        git log --pretty="tformat:%h" >expected &&
  87        git config pretty.test-foo "tformat:%h" &&
  88        git config pretty.test-bar test-foo &&
  89        git log --pretty=test-bar >actual && test_cmp expected actual
  90'
  91
  92test_expect_success 'alias masking an alias' '
  93        git log --pretty=format:"Two %H" >expected &&
  94        git config pretty.duplicate "format:One %H" &&
  95        git config --add pretty.duplicate "format:Two %H" &&
  96        git log --pretty=duplicate >actual &&
  97        test_cmp expected actual
  98'
  99
 100test_expect_success 'alias loop' '
 101        git config pretty.test-foo test-bar &&
 102        git config pretty.test-bar test-foo &&
 103        test_must_fail git log --pretty=test-foo
 104'
 105
 106test_expect_success 'NUL separation' '
 107        printf "add bar\0$(commit_msg)" >expected &&
 108        git log -z --pretty="format:%s" >actual &&
 109        test_cmp expected actual
 110'
 111
 112test_expect_success 'NUL termination' '
 113        printf "add bar\0$(commit_msg)\0" >expected &&
 114        git log -z --pretty="tformat:%s" >actual &&
 115        test_cmp expected actual
 116'
 117
 118test_expect_success 'NUL separation with --stat' '
 119        stat0_part=$(git diff --stat HEAD^ HEAD) &&
 120        stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
 121        printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n" >expected &&
 122        git log -z --stat --pretty="format:%s" >actual &&
 123        test_i18ncmp expected actual
 124'
 125
 126test_expect_failure 'NUL termination with --stat' '
 127        stat0_part=$(git diff --stat HEAD^ HEAD) &&
 128        stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
 129        printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n0" >expected &&
 130        git log -z --stat --pretty="tformat:%s" >actual &&
 131        test_i18ncmp expected actual
 132'
 133
 134test_expect_success 'setup more commits' '
 135        test_commit "message one" one one message-one &&
 136        test_commit "message two" two two message-two &&
 137        head1=$(git rev-parse --verify --short HEAD~0) &&
 138        head2=$(git rev-parse --verify --short HEAD~1) &&
 139        head3=$(git rev-parse --verify --short HEAD~2) &&
 140        head4=$(git rev-parse --verify --short HEAD~3)
 141'
 142
 143test_expect_success 'left alignment formatting' '
 144        git log --pretty="format:%<(40)%s" >actual &&
 145        # complete the incomplete line at the end
 146        echo >>actual &&
 147        qz_to_tab_space <<EOF >expected &&
 148message two                            Z
 149message one                            Z
 150add bar                                Z
 151$(commit_msg)                    Z
 152EOF
 153        test_cmp expected actual
 154'
 155
 156test_expect_success 'left alignment formatting at the nth column' '
 157        git log --pretty="format:%h %<|(40)%s" >actual &&
 158        # complete the incomplete line at the end
 159        echo >>actual &&
 160        qz_to_tab_space <<EOF >expected &&
 161$head1 message two                    Z
 162$head2 message one                    Z
 163$head3 add bar                        Z
 164$head4 $(commit_msg)            Z
 165EOF
 166        test_cmp expected actual
 167'
 168
 169test_expect_success 'left alignment formatting with no padding' '
 170        git log --pretty="format:%<(1)%s" >actual &&
 171        # complete the incomplete line at the end
 172        echo >>actual &&
 173        cat <<EOF >expected &&
 174message two
 175message one
 176add bar
 177$(commit_msg)
 178EOF
 179        test_cmp expected actual
 180'
 181
 182test_expect_success 'left alignment formatting with trunc' '
 183        git log --pretty="format:%<(10,trunc)%s" >actual &&
 184        # complete the incomplete line at the end
 185        echo >>actual &&
 186        qz_to_tab_space <<EOF >expected &&
 187message ..
 188message ..
 189add bar  Z
 190initial...
 191EOF
 192        test_cmp expected actual
 193'
 194
 195test_expect_success 'left alignment formatting with ltrunc' '
 196        git log --pretty="format:%<(10,ltrunc)%s" >actual &&
 197        # complete the incomplete line at the end
 198        echo >>actual &&
 199        qz_to_tab_space <<EOF >expected &&
 200..sage two
 201..sage one
 202add bar  Z
 203..${sample_utf8_part}lich
 204EOF
 205        test_cmp expected actual
 206'
 207
 208test_expect_success 'left alignment formatting with mtrunc' '
 209        git log --pretty="format:%<(10,mtrunc)%s" >actual &&
 210        # complete the incomplete line at the end
 211        echo >>actual &&
 212        qz_to_tab_space <<EOF >expected &&
 213mess.. two
 214mess.. one
 215add bar  Z
 216init..lich
 217EOF
 218        test_cmp expected actual
 219'
 220
 221test_expect_success 'right alignment formatting' '
 222        git log --pretty="format:%>(40)%s" >actual &&
 223        # complete the incomplete line at the end
 224        echo >>actual &&
 225        qz_to_tab_space <<EOF >expected &&
 226Z                            message two
 227Z                            message one
 228Z                                add bar
 229Z                    $(commit_msg)
 230EOF
 231        test_cmp expected actual
 232'
 233
 234test_expect_success 'right alignment formatting at the nth column' '
 235        git log --pretty="format:%h %>|(40)%s" >actual &&
 236        # complete the incomplete line at the end
 237        echo >>actual &&
 238        qz_to_tab_space <<EOF >expected &&
 239$head1                      message two
 240$head2                      message one
 241$head3                          add bar
 242$head4              $(commit_msg)
 243EOF
 244        test_cmp expected actual
 245'
 246
 247test_expect_success 'right alignment formatting with no padding' '
 248        git log --pretty="format:%>(1)%s" >actual &&
 249        # complete the incomplete line at the end
 250        echo >>actual &&
 251        cat <<EOF >expected &&
 252message two
 253message one
 254add bar
 255$(commit_msg)
 256EOF
 257        test_cmp expected actual
 258'
 259
 260test_expect_success 'center alignment formatting' '
 261        git log --pretty="format:%><(40)%s" >actual &&
 262        # complete the incomplete line at the end
 263        echo >>actual &&
 264        qz_to_tab_space <<EOF >expected &&
 265Z             message two              Z
 266Z             message one              Z
 267Z               add bar                Z
 268Z         $(commit_msg)          Z
 269EOF
 270        test_cmp expected actual
 271'
 272
 273test_expect_success 'center alignment formatting at the nth column' '
 274        git log --pretty="format:%h %><|(40)%s" >actual &&
 275        # complete the incomplete line at the end
 276        echo >>actual &&
 277        qz_to_tab_space <<EOF >expected &&
 278$head1           message two          Z
 279$head2           message one          Z
 280$head3             add bar            Z
 281$head4       $(commit_msg)      Z
 282EOF
 283        test_cmp expected actual
 284'
 285
 286test_expect_success 'center alignment formatting with no padding' '
 287        git log --pretty="format:%><(1)%s" >actual &&
 288        # complete the incomplete line at the end
 289        echo >>actual &&
 290        cat <<EOF >expected &&
 291message two
 292message one
 293add bar
 294$(commit_msg)
 295EOF
 296        test_cmp expected actual
 297'
 298
 299test_expect_success 'left/right alignment formatting with stealing' '
 300        git commit --amend -m short --author "long long long <long@me.com>" &&
 301        git log --pretty="format:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
 302        # complete the incomplete line at the end
 303        echo >>actual &&
 304        cat <<EOF >expected &&
 305short long  long long
 306message ..   A U Thor
 307add bar      A U Thor
 308initial...   A U Thor
 309EOF
 310        test_cmp expected actual
 311'
 312
 313test_expect_success 'log decoration properly follows tag chain' '
 314        git tag -a tag1 -m tag1 &&
 315        git tag -a tag2 -m tag2 tag1 &&
 316        git tag -d tag1 &&
 317        git commit --amend -m shorter &&
 318        git log --no-walk --tags --pretty="%H %d" --decorate=full >actual &&
 319        cat <<EOF >expected &&
 3206a908c10688b2503073c39c9ba26322c73902bb5  (tag: refs/tags/tag2)
 3219f716384d92283fb915a4eee5073f030638e05f9  (tag: refs/tags/message-one)
 322b87e4cccdb77336ea79d89224737be7ea8e95367  (tag: refs/tags/message-two)
 323EOF
 324        sort actual >actual1 &&
 325        test_cmp expected actual1
 326'
 327
 328test_done