t / t4205-log-pretty-formats.shon commit Merge branch 'fc/show-non-empty-errors-in-test' (01c0615)
   1#!/bin/sh
   2#
   3# Copyright (c) 2010, Will Palmer
   4#
   5
   6test_description='Test pretty formats'
   7. ./test-lib.sh
   8
   9test_expect_success 'set up basic repos' '
  10        >foo &&
  11        >bar &&
  12        git add foo &&
  13        test_tick &&
  14        git commit -m initial &&
  15        git add bar &&
  16        test_tick &&
  17        git commit -m "add bar"
  18'
  19
  20test_expect_success 'alias builtin format' '
  21        git log --pretty=oneline >expected &&
  22        git config pretty.test-alias oneline &&
  23        git log --pretty=test-alias >actual &&
  24        test_cmp expected actual
  25'
  26
  27test_expect_success 'alias masking builtin format' '
  28        git log --pretty=oneline >expected &&
  29        git config pretty.oneline "%H" &&
  30        git log --pretty=oneline >actual &&
  31        test_cmp expected actual
  32'
  33
  34test_expect_success 'alias user-defined format' '
  35        git log --pretty="format:%h" >expected &&
  36        git config pretty.test-alias "format:%h" &&
  37        git log --pretty=test-alias >actual &&
  38        test_cmp expected actual
  39'
  40
  41test_expect_success 'alias user-defined tformat' '
  42        git log --pretty="tformat:%h" >expected &&
  43        git config pretty.test-alias "tformat:%h" &&
  44        git log --pretty=test-alias >actual &&
  45        test_cmp expected actual
  46'
  47
  48test_expect_success 'alias non-existent format' '
  49        git config pretty.test-alias format-that-will-never-exist &&
  50        test_must_fail git log --pretty=test-alias
  51'
  52
  53test_expect_success 'alias of an alias' '
  54        git log --pretty="tformat:%h" >expected &&
  55        git config pretty.test-foo "tformat:%h" &&
  56        git config pretty.test-bar test-foo &&
  57        git log --pretty=test-bar >actual && test_cmp expected actual
  58'
  59
  60test_expect_success 'alias masking an alias' '
  61        git log --pretty=format:"Two %H" >expected &&
  62        git config pretty.duplicate "format:One %H" &&
  63        git config --add pretty.duplicate "format:Two %H" &&
  64        git log --pretty=duplicate >actual &&
  65        test_cmp expected actual
  66'
  67
  68test_expect_success 'alias loop' '
  69        git config pretty.test-foo test-bar &&
  70        git config pretty.test-bar test-foo &&
  71        test_must_fail git log --pretty=test-foo
  72'
  73
  74test_expect_success 'NUL separation' '
  75        printf "add bar\0initial" >expected &&
  76        git log -z --pretty="format:%s" >actual &&
  77        test_cmp expected actual
  78'
  79
  80test_expect_success 'NUL termination' '
  81        printf "add bar\0initial\0" >expected &&
  82        git log -z --pretty="tformat:%s" >actual &&
  83        test_cmp expected actual
  84'
  85
  86test_expect_success 'NUL separation with --stat' '
  87        stat0_part=$(git diff --stat HEAD^ HEAD) &&
  88        stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
  89        printf "add bar\n$stat0_part\n\0initial\n$stat1_part\n" >expected &&
  90        git log -z --stat --pretty="format:%s" >actual &&
  91        test_i18ncmp expected actual
  92'
  93
  94test_expect_failure 'NUL termination with --stat' '
  95        stat0_part=$(git diff --stat HEAD^ HEAD) &&
  96        stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
  97        printf "add bar\n$stat0_part\n\0initial\n$stat1_part\n\0" >expected &&
  98        git log -z --stat --pretty="tformat:%s" >actual &&
  99        test_i18ncmp expected actual
 100'
 101
 102test_expect_success 'setup more commits' '
 103        test_commit "message one" one one message-one &&
 104        test_commit "message two" two two message-two
 105'
 106
 107test_expect_success 'left alignment formatting' '
 108        git log --pretty="format:%<(40)%s" >actual &&
 109        # complete the incomplete line at the end
 110        echo >>actual &&
 111        qz_to_tab_space <<\EOF >expected &&
 112message two                            Z
 113message one                            Z
 114add bar                                Z
 115initial                                Z
 116EOF
 117        test_cmp expected actual
 118'
 119
 120test_expect_success 'left alignment formatting at the nth column' '
 121        git log --pretty="format:%h %<|(40)%s" >actual &&
 122        # complete the incomplete line at the end
 123        echo >>actual &&
 124        qz_to_tab_space <<\EOF >expected &&
 125fa33ab1 message two                    Z
 1267cd6c63 message one                    Z
 1271711bf9 add bar                        Z
 128af20c06 initial                        Z
 129EOF
 130        test_cmp expected actual
 131'
 132
 133test_expect_success 'left alignment formatting with no padding' '
 134        git log --pretty="format:%<(1)%s" >actual &&
 135        # complete the incomplete line at the end
 136        echo >>actual &&
 137        cat <<\EOF >expected &&
 138message two
 139message one
 140add bar
 141initial
 142EOF
 143        test_cmp expected actual
 144'
 145
 146test_expect_success 'left alignment formatting with trunc' '
 147        git log --pretty="format:%<(10,trunc)%s" >actual &&
 148        # complete the incomplete line at the end
 149        echo >>actual &&
 150        qz_to_tab_space <<\EOF >expected &&
 151message ..
 152message ..
 153add bar  Z
 154initial  Z
 155EOF
 156        test_cmp expected actual
 157'
 158
 159test_expect_success 'left alignment formatting with ltrunc' '
 160        git log --pretty="format:%<(10,ltrunc)%s" >actual &&
 161        # complete the incomplete line at the end
 162        echo >>actual &&
 163        qz_to_tab_space <<\EOF >expected &&
 164..sage two
 165..sage one
 166add bar  Z
 167initial  Z
 168EOF
 169        test_cmp expected actual
 170'
 171
 172test_expect_success 'left alignment formatting with mtrunc' '
 173        git log --pretty="format:%<(10,mtrunc)%s" >actual &&
 174        # complete the incomplete line at the end
 175        echo >>actual &&
 176        qz_to_tab_space <<\EOF >expected &&
 177mess.. two
 178mess.. one
 179add bar  Z
 180initial  Z
 181EOF
 182        test_cmp expected actual
 183'
 184
 185test_expect_success 'right alignment formatting' '
 186        git log --pretty="format:%>(40)%s" >actual &&
 187        # complete the incomplete line at the end
 188        echo >>actual &&
 189        qz_to_tab_space <<\EOF >expected &&
 190Z                            message two
 191Z                            message one
 192Z                                add bar
 193Z                                initial
 194EOF
 195        test_cmp expected actual
 196'
 197
 198test_expect_success 'right alignment formatting at the nth column' '
 199        git log --pretty="format:%h %>|(40)%s" >actual &&
 200        # complete the incomplete line at the end
 201        echo >>actual &&
 202        qz_to_tab_space <<\EOF >expected &&
 203fa33ab1                      message two
 2047cd6c63                      message one
 2051711bf9                          add bar
 206af20c06                          initial
 207EOF
 208        test_cmp expected actual
 209'
 210
 211test_expect_success 'right alignment formatting with no padding' '
 212        git log --pretty="format:%>(1)%s" >actual &&
 213        # complete the incomplete line at the end
 214        echo >>actual &&
 215        cat <<\EOF >expected &&
 216message two
 217message one
 218add bar
 219initial
 220EOF
 221        test_cmp expected actual
 222'
 223
 224test_expect_success 'center alignment formatting' '
 225        git log --pretty="format:%><(40)%s" >actual &&
 226        # complete the incomplete line at the end
 227        echo >>actual &&
 228        qz_to_tab_space <<\EOF >expected &&
 229Z             message two              Z
 230Z             message one              Z
 231Z               add bar                Z
 232Z               initial                Z
 233EOF
 234        test_cmp expected actual
 235'
 236
 237test_expect_success 'center alignment formatting at the nth column' '
 238        git log --pretty="format:%h %><|(40)%s" >actual &&
 239        # complete the incomplete line at the end
 240        echo >>actual &&
 241        qz_to_tab_space <<\EOF >expected &&
 242fa33ab1           message two          Z
 2437cd6c63           message one          Z
 2441711bf9             add bar            Z
 245af20c06             initial            Z
 246EOF
 247        test_cmp expected actual
 248'
 249
 250test_expect_success 'center alignment formatting with no padding' '
 251        git log --pretty="format:%><(1)%s" >actual &&
 252        # complete the incomplete line at the end
 253        echo >>actual &&
 254        cat <<\EOF >expected &&
 255message two
 256message one
 257add bar
 258initial
 259EOF
 260        test_cmp expected actual
 261'
 262
 263test_expect_success 'left/right alignment formatting with stealing' '
 264        git commit --amend -m short --author "long long long <long@me.com>" &&
 265        git log --pretty="format:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
 266        # complete the incomplete line at the end
 267        echo >>actual &&
 268        cat <<\EOF >expected &&
 269short long  long long
 270message ..   A U Thor
 271add bar      A U Thor
 272initial      A U Thor
 273EOF
 274        test_cmp expected actual
 275'
 276
 277test_done