t / t4202-log.shon commit Introduce usagef() that takes a printf-style format (64b1cb7)
   1#!/bin/sh
   2
   3test_description='git log'
   4
   5. ./test-lib.sh
   6
   7test_expect_success setup '
   8
   9        echo one >one &&
  10        git add one &&
  11        test_tick &&
  12        git commit -m initial &&
  13
  14        echo ichi >one &&
  15        git add one &&
  16        test_tick &&
  17        git commit -m second &&
  18
  19        git mv one ichi &&
  20        test_tick &&
  21        git commit -m third &&
  22
  23        cp ichi ein &&
  24        git add ein &&
  25        test_tick &&
  26        git commit -m fourth &&
  27
  28        mkdir a &&
  29        echo ni >a/two &&
  30        git add a/two &&
  31        test_tick &&
  32        git commit -m fifth  &&
  33
  34        git rm a/two &&
  35        test_tick &&
  36        git commit -m sixth
  37
  38'
  39
  40printf "sixth\nfifth\nfourth\nthird\nsecond\ninitial" > expect
  41test_expect_success 'pretty' '
  42
  43        git log --pretty="format:%s" > actual &&
  44        test_cmp expect actual
  45'
  46
  47printf "sixth\nfifth\nfourth\nthird\nsecond\ninitial\n" > expect
  48test_expect_success 'pretty (tformat)' '
  49
  50        git log --pretty="tformat:%s" > actual &&
  51        test_cmp expect actual
  52'
  53
  54test_expect_success 'pretty (shortcut)' '
  55
  56        git log --pretty="%s" > actual &&
  57        test_cmp expect actual
  58'
  59
  60test_expect_success 'format' '
  61
  62        git log --format="%s" > actual &&
  63        test_cmp expect actual
  64'
  65
  66cat > expect << EOF
  67804a787 sixth
  68394ef78 fifth
  695d31159 fourth
  702fbe8c0 third
  71f7dab8e second
  723a2fdcb initial
  73EOF
  74test_expect_success 'oneline' '
  75
  76        git log --oneline > actual &&
  77        test_cmp expect actual
  78'
  79
  80test_expect_success 'diff-filter=A' '
  81
  82        actual=$(git log --pretty="format:%s" --diff-filter=A HEAD) &&
  83        expect=$(echo fifth ; echo fourth ; echo third ; echo initial) &&
  84        test "$actual" = "$expect" || {
  85                echo Oops
  86                echo "Actual: $actual"
  87                false
  88        }
  89
  90'
  91
  92test_expect_success 'diff-filter=M' '
  93
  94        actual=$(git log --pretty="format:%s" --diff-filter=M HEAD) &&
  95        expect=$(echo second) &&
  96        test "$actual" = "$expect" || {
  97                echo Oops
  98                echo "Actual: $actual"
  99                false
 100        }
 101
 102'
 103
 104test_expect_success 'diff-filter=D' '
 105
 106        actual=$(git log --pretty="format:%s" --diff-filter=D HEAD) &&
 107        expect=$(echo sixth ; echo third) &&
 108        test "$actual" = "$expect" || {
 109                echo Oops
 110                echo "Actual: $actual"
 111                false
 112        }
 113
 114'
 115
 116test_expect_success 'diff-filter=R' '
 117
 118        actual=$(git log -M --pretty="format:%s" --diff-filter=R HEAD) &&
 119        expect=$(echo third) &&
 120        test "$actual" = "$expect" || {
 121                echo Oops
 122                echo "Actual: $actual"
 123                false
 124        }
 125
 126'
 127
 128test_expect_success 'diff-filter=C' '
 129
 130        actual=$(git log -C -C --pretty="format:%s" --diff-filter=C HEAD) &&
 131        expect=$(echo fourth) &&
 132        test "$actual" = "$expect" || {
 133                echo Oops
 134                echo "Actual: $actual"
 135                false
 136        }
 137
 138'
 139
 140test_expect_success 'git log --follow' '
 141
 142        actual=$(git log --follow --pretty="format:%s" ichi) &&
 143        expect=$(echo third ; echo second ; echo initial) &&
 144        test "$actual" = "$expect" || {
 145                echo Oops
 146                echo "Actual: $actual"
 147                false
 148        }
 149
 150'
 151
 152cat > expect << EOF
 153804a787 sixth
 154394ef78 fifth
 1555d31159 fourth
 156EOF
 157test_expect_success 'git log --no-walk <commits> sorts by commit time' '
 158        git log --no-walk --oneline 5d31159 804a787 394ef78 > actual &&
 159        test_cmp expect actual
 160'
 161
 162cat > expect << EOF
 1635d31159 fourth
 164804a787 sixth
 165394ef78 fifth
 166EOF
 167test_expect_success 'git show <commits> leaves list of commits as given' '
 168        git show --oneline -s 5d31159 804a787 394ef78 > actual &&
 169        test_cmp expect actual
 170'
 171
 172test_expect_success 'setup case sensitivity tests' '
 173        echo case >one &&
 174        test_tick &&
 175        git add one
 176        git commit -a -m Second
 177'
 178
 179test_expect_success 'log --grep' '
 180        echo second >expect &&
 181        git log -1 --pretty="tformat:%s" --grep=sec >actual &&
 182        test_cmp expect actual
 183'
 184
 185test_expect_success 'log -i --grep' '
 186        echo Second >expect &&
 187        git log -1 --pretty="tformat:%s" -i --grep=sec >actual &&
 188        test_cmp expect actual
 189'
 190
 191test_expect_success 'log --grep -i' '
 192        echo Second >expect &&
 193        git log -1 --pretty="tformat:%s" --grep=sec -i >actual &&
 194        test_cmp expect actual
 195'
 196
 197cat > expect <<EOF
 198* Second
 199* sixth
 200* fifth
 201* fourth
 202* third
 203* second
 204* initial
 205EOF
 206
 207test_expect_success 'simple log --graph' '
 208        git log --graph --pretty=tformat:%s >actual &&
 209        test_cmp expect actual
 210'
 211
 212test_expect_success 'set up merge history' '
 213        git checkout -b side HEAD~4 &&
 214        test_commit side-1 1 1 &&
 215        test_commit side-2 2 2 &&
 216        git checkout master &&
 217        git merge side
 218'
 219
 220cat > expect <<\EOF
 221*   Merge branch 'side'
 222|\
 223| * side-2
 224| * side-1
 225* | Second
 226* | sixth
 227* | fifth
 228* | fourth
 229|/
 230* third
 231* second
 232* initial
 233EOF
 234
 235test_expect_success 'log --graph with merge' '
 236        git log --graph --date-order --pretty=tformat:%s |
 237                sed "s/ *$//" >actual &&
 238        test_cmp expect actual
 239'
 240
 241cat > expect <<\EOF
 242*   commit master
 243|\  Merge: A B
 244| | Author: A U Thor <author@example.com>
 245| |
 246| |     Merge branch 'side'
 247| |
 248| * commit side
 249| | Author: A U Thor <author@example.com>
 250| |
 251| |     side-2
 252| |
 253| * commit tags/side-1
 254| | Author: A U Thor <author@example.com>
 255| |
 256| |     side-1
 257| |
 258* | commit master~1
 259| | Author: A U Thor <author@example.com>
 260| |
 261| |     Second
 262| |
 263* | commit master~2
 264| | Author: A U Thor <author@example.com>
 265| |
 266| |     sixth
 267| |
 268* | commit master~3
 269| | Author: A U Thor <author@example.com>
 270| |
 271| |     fifth
 272| |
 273* | commit master~4
 274|/  Author: A U Thor <author@example.com>
 275|
 276|       fourth
 277|
 278* commit tags/side-1~1
 279| Author: A U Thor <author@example.com>
 280|
 281|     third
 282|
 283* commit tags/side-1~2
 284| Author: A U Thor <author@example.com>
 285|
 286|     second
 287|
 288* commit tags/side-1~3
 289  Author: A U Thor <author@example.com>
 290
 291      initial
 292EOF
 293
 294test_expect_success 'log --graph with full output' '
 295        git log --graph --date-order --pretty=short |
 296                git name-rev --name-only --stdin |
 297                sed "s/Merge:.*/Merge: A B/;s/ *$//" >actual &&
 298        test_cmp expect actual
 299'
 300
 301test_expect_success 'set up more tangled history' '
 302        git checkout -b tangle HEAD~6 &&
 303        test_commit tangle-a tangle-a a &&
 304        git merge master~3 &&
 305        git merge side~1 &&
 306        git checkout master &&
 307        git merge tangle &&
 308        git checkout -b reach &&
 309        test_commit reach &&
 310        git checkout master &&
 311        git checkout -b octopus-a &&
 312        test_commit octopus-a &&
 313        git checkout master &&
 314        git checkout -b octopus-b &&
 315        test_commit octopus-b &&
 316        git checkout master &&
 317        test_commit seventh &&
 318        git merge octopus-a octopus-b
 319        git merge reach
 320'
 321
 322cat > expect <<\EOF
 323*   Merge commit 'reach'
 324|\
 325| \
 326|  \
 327*-. \   Merge commit 'octopus-a'; commit 'octopus-b'
 328|\ \ \
 329* | | | seventh
 330| | * | octopus-b
 331| |/ /
 332|/| |
 333| * | octopus-a
 334|/ /
 335| * reach
 336|/
 337*   Merge branch 'tangle'
 338|\
 339| *   Merge branch 'side' (early part) into tangle
 340| |\
 341| * \   Merge branch 'master' (early part) into tangle
 342| |\ \
 343| * | | tangle-a
 344* | | |   Merge branch 'side'
 345|\ \ \ \
 346| * | | | side-2
 347| | |_|/
 348| |/| |
 349| * | | side-1
 350* | | | Second
 351* | | | sixth
 352| |_|/
 353|/| |
 354* | | fifth
 355* | | fourth
 356|/ /
 357* | third
 358|/
 359* second
 360* initial
 361EOF
 362
 363test_expect_success 'log --graph with merge' '
 364        git log --graph --date-order --pretty=tformat:%s |
 365                sed "s/ *$//" >actual &&
 366        test_cmp expect actual
 367'
 368
 369test_done
 370