t / t4202-log.shon commit Test git-patch-id (b26d8d2)
   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
  40test_expect_success 'diff-filter=A' '
  41
  42        actual=$(git log --pretty="format:%s" --diff-filter=A HEAD) &&
  43        expect=$(echo fifth ; echo fourth ; echo third ; echo initial) &&
  44        test "$actual" = "$expect" || {
  45                echo Oops
  46                echo "Actual: $actual"
  47                false
  48        }
  49
  50'
  51
  52test_expect_success 'diff-filter=M' '
  53
  54        actual=$(git log --pretty="format:%s" --diff-filter=M HEAD) &&
  55        expect=$(echo second) &&
  56        test "$actual" = "$expect" || {
  57                echo Oops
  58                echo "Actual: $actual"
  59                false
  60        }
  61
  62'
  63
  64test_expect_success 'diff-filter=D' '
  65
  66        actual=$(git log --pretty="format:%s" --diff-filter=D HEAD) &&
  67        expect=$(echo sixth ; echo third) &&
  68        test "$actual" = "$expect" || {
  69                echo Oops
  70                echo "Actual: $actual"
  71                false
  72        }
  73
  74'
  75
  76test_expect_success 'diff-filter=R' '
  77
  78        actual=$(git log -M --pretty="format:%s" --diff-filter=R HEAD) &&
  79        expect=$(echo third) &&
  80        test "$actual" = "$expect" || {
  81                echo Oops
  82                echo "Actual: $actual"
  83                false
  84        }
  85
  86'
  87
  88test_expect_success 'diff-filter=C' '
  89
  90        actual=$(git log -C -C --pretty="format:%s" --diff-filter=C HEAD) &&
  91        expect=$(echo fourth) &&
  92        test "$actual" = "$expect" || {
  93                echo Oops
  94                echo "Actual: $actual"
  95                false
  96        }
  97
  98'
  99
 100test_expect_success 'git log --follow' '
 101
 102        actual=$(git log --follow --pretty="format:%s" ichi) &&
 103        expect=$(echo third ; echo second ; echo initial) &&
 104        test "$actual" = "$expect" || {
 105                echo Oops
 106                echo "Actual: $actual"
 107                false
 108        }
 109
 110'
 111
 112test_expect_success 'setup case sensitivity tests' '
 113        echo case >one &&
 114        test_tick &&
 115        git add one
 116        git commit -a -m Second
 117'
 118
 119test_expect_success 'log --grep' '
 120        echo second >expect &&
 121        git log -1 --pretty="tformat:%s" --grep=sec >actual &&
 122        test_cmp expect actual
 123'
 124
 125test_expect_success 'log -i --grep' '
 126        echo Second >expect &&
 127        git log -1 --pretty="tformat:%s" -i --grep=sec >actual &&
 128        test_cmp expect actual
 129'
 130
 131test_expect_success 'log --grep -i' '
 132        echo Second >expect &&
 133        git log -1 --pretty="tformat:%s" --grep=sec -i >actual &&
 134        test_cmp expect actual
 135'
 136
 137cat > expect <<EOF
 138* Second
 139* sixth
 140* fifth
 141* fourth
 142* third
 143* second
 144* initial
 145EOF
 146
 147test_expect_success 'simple log --graph' '
 148        git log --graph --pretty=tformat:%s >actual &&
 149        test_cmp expect actual
 150'
 151
 152test_expect_success 'set up merge history' '
 153        git checkout -b side HEAD~4 &&
 154        test_commit side-1 1 1 &&
 155        test_commit side-2 2 2 &&
 156        git checkout master &&
 157        git merge side
 158'
 159
 160cat > expect <<\EOF
 161*   Merge branch 'side'
 162|\
 163| * side-2
 164| * side-1
 165* | Second
 166* | sixth
 167* | fifth
 168* | fourth
 169|/
 170* third
 171* second
 172* initial
 173EOF
 174
 175test_expect_success 'log --graph with merge' '
 176        git log --graph --date-order --pretty=tformat:%s |
 177                sed "s/ *$//" >actual &&
 178        test_cmp expect actual
 179'
 180
 181cat > expect <<\EOF
 182*   commit master
 183|\  Merge: A B
 184| | Author: A U Thor <author@example.com>
 185| |
 186| |     Merge branch 'side'
 187| |
 188| * commit side
 189| | Author: A U Thor <author@example.com>
 190| |
 191| |     side-2
 192| |
 193| * commit tags/side-1
 194| | Author: A U Thor <author@example.com>
 195| |
 196| |     side-1
 197| |
 198* | commit master~1
 199| | Author: A U Thor <author@example.com>
 200| |
 201| |     Second
 202| |
 203* | commit master~2
 204| | Author: A U Thor <author@example.com>
 205| |
 206| |     sixth
 207| |
 208* | commit master~3
 209| | Author: A U Thor <author@example.com>
 210| |
 211| |     fifth
 212| |
 213* | commit master~4
 214|/  Author: A U Thor <author@example.com>
 215|
 216|       fourth
 217|
 218* commit tags/side-1~1
 219| Author: A U Thor <author@example.com>
 220|
 221|     third
 222|
 223* commit tags/side-1~2
 224| Author: A U Thor <author@example.com>
 225|
 226|     second
 227|
 228* commit tags/side-1~3
 229  Author: A U Thor <author@example.com>
 230
 231      initial
 232EOF
 233
 234test_expect_success 'log --graph with full output' '
 235        git log --graph --date-order --pretty=short |
 236                git name-rev --name-only --stdin |
 237                sed "s/Merge:.*/Merge: A B/;s/ *$//" >actual &&
 238        test_cmp expect actual
 239'
 240
 241test_expect_success 'set up more tangled history' '
 242        git checkout -b tangle HEAD~6 &&
 243        test_commit tangle-a tangle-a a &&
 244        git merge master~3 &&
 245        git merge side~1 &&
 246        git checkout master &&
 247        git merge tangle
 248'
 249
 250cat > expect <<\EOF
 251*   Merge branch 'tangle'
 252|\
 253| *   Merge branch 'side' (early part) into tangle
 254| |\
 255| * \   Merge branch 'master' (early part) into tangle
 256| |\ \
 257| * | | tangle-a
 258* | | |   Merge branch 'side'
 259|\ \ \ \
 260| * | | | side-2
 261| | | |/
 262| | |/|
 263| |/| |
 264| * | | side-1
 265* | | | Second
 266* | | | sixth
 267| | |/
 268| |/|
 269|/| |
 270* | | fifth
 271* | | fourth
 272|/ /
 273* | third
 274|/
 275* second
 276* initial
 277EOF
 278
 279test_expect_success 'log --graph with merge' '
 280        git log --graph --date-order --pretty=tformat:%s |
 281                sed "s/ *$//" >actual &&
 282        test_cmp expect actual
 283'
 284
 285test_done
 286