t / t4013-diff-various.shon commit combine-diff: treat --shortstat like --stat (8290faa)
   1#!/bin/sh
   2#
   3# Copyright (c) 2006 Junio C Hamano
   4#
   5
   6test_description='Various diff formatting options'
   7
   8. ./test-lib.sh
   9
  10LF='
  11'
  12
  13test_expect_success setup '
  14
  15        GIT_AUTHOR_DATE="2006-06-26 00:00:00 +0000" &&
  16        GIT_COMMITTER_DATE="2006-06-26 00:00:00 +0000" &&
  17        export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
  18
  19        mkdir dir &&
  20        mkdir dir2 &&
  21        for i in 1 2 3; do echo $i; done >file0 &&
  22        for i in A B; do echo $i; done >dir/sub &&
  23        cat file0 >file2 &&
  24        git add file0 file2 dir/sub &&
  25        git commit -m Initial &&
  26
  27        git branch initial &&
  28        git branch side &&
  29
  30        GIT_AUTHOR_DATE="2006-06-26 00:01:00 +0000" &&
  31        GIT_COMMITTER_DATE="2006-06-26 00:01:00 +0000" &&
  32        export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
  33
  34        for i in 4 5 6; do echo $i; done >>file0 &&
  35        for i in C D; do echo $i; done >>dir/sub &&
  36        rm -f file2 &&
  37        git update-index --remove file0 file2 dir/sub &&
  38        git commit -m "Second${LF}${LF}This is the second commit." &&
  39
  40        GIT_AUTHOR_DATE="2006-06-26 00:02:00 +0000" &&
  41        GIT_COMMITTER_DATE="2006-06-26 00:02:00 +0000" &&
  42        export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
  43
  44        for i in A B C; do echo $i; done >file1 &&
  45        git add file1 &&
  46        for i in E F; do echo $i; done >>dir/sub &&
  47        git update-index dir/sub &&
  48        git commit -m Third &&
  49
  50        GIT_AUTHOR_DATE="2006-06-26 00:03:00 +0000" &&
  51        GIT_COMMITTER_DATE="2006-06-26 00:03:00 +0000" &&
  52        export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
  53
  54        git checkout side &&
  55        for i in A B C; do echo $i; done >>file0 &&
  56        for i in 1 2; do echo $i; done >>dir/sub &&
  57        cat dir/sub >file3 &&
  58        git add file3 &&
  59        git update-index file0 dir/sub &&
  60        git commit -m Side &&
  61
  62        GIT_AUTHOR_DATE="2006-06-26 00:04:00 +0000" &&
  63        GIT_COMMITTER_DATE="2006-06-26 00:04:00 +0000" &&
  64        export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
  65
  66        git checkout master &&
  67        git pull -s ours . side &&
  68
  69        GIT_AUTHOR_DATE="2006-06-26 00:05:00 +0000" &&
  70        GIT_COMMITTER_DATE="2006-06-26 00:05:00 +0000" &&
  71        export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
  72
  73        for i in A B C; do echo $i; done >>file0 &&
  74        for i in 1 2; do echo $i; done >>dir/sub &&
  75        git update-index file0 dir/sub &&
  76
  77        mkdir dir3 &&
  78        cp dir/sub dir3/sub &&
  79        test-tool chmtime +1 dir3/sub &&
  80
  81        git config log.showroot false &&
  82        git commit --amend &&
  83
  84        GIT_AUTHOR_DATE="2006-06-26 00:06:00 +0000" &&
  85        GIT_COMMITTER_DATE="2006-06-26 00:06:00 +0000" &&
  86        export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
  87        git checkout -b rearrange initial &&
  88        for i in B A; do echo $i; done >dir/sub &&
  89        git add dir/sub &&
  90        git commit -m "Rearranged lines in dir/sub" &&
  91        git checkout master &&
  92
  93        GIT_AUTHOR_DATE="2006-06-26 00:06:00 +0000" &&
  94        GIT_COMMITTER_DATE="2006-06-26 00:06:00 +0000" &&
  95        export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
  96        git checkout -b mode initial &&
  97        git update-index --chmod=+x file0 &&
  98        git commit -m "update mode" &&
  99        git checkout -f master &&
 100
 101        git config diff.renames false &&
 102
 103        git show-branch
 104'
 105
 106: <<\EOF
 107! [initial] Initial
 108 * [master] Merge branch 'side'
 109  ! [rearrange] Rearranged lines in dir/sub
 110   ! [side] Side
 111----
 112  +  [rearrange] Rearranged lines in dir/sub
 113 -   [master] Merge branch 'side'
 114 * + [side] Side
 115 *   [master^] Third
 116 *   [master~2] Second
 117+*++ [initial] Initial
 118EOF
 119
 120V=$(git version | sed -e 's/^git version //' -e 's/\./\\./g')
 121while read magic cmd
 122do
 123        case "$magic" in
 124        '' | '#'*)
 125                continue ;;
 126        :*)
 127                magic=${magic#:}
 128                label="$magic-$cmd"
 129                case "$magic" in
 130                noellipses) ;;
 131                *)
 132                        BUG "unknown magic $magic" ;;
 133                esac ;;
 134        *)
 135                cmd="$magic $cmd" magic=
 136                label="$cmd" ;;
 137        esac
 138        test=$(echo "$label" | sed -e 's|[/ ][/ ]*|_|g')
 139        pfx=$(printf "%04d" $test_count)
 140        expect="$TEST_DIRECTORY/t4013/diff.$test"
 141        actual="$pfx-diff.$test"
 142
 143        test_expect_success "git $cmd # magic is ${magic:-(not used)}" '
 144                {
 145                        echo "$ git $cmd"
 146                        case "$magic" in
 147                        "")
 148                                GIT_PRINT_SHA1_ELLIPSIS=yes git $cmd ;;
 149                        noellipses)
 150                                git $cmd ;;
 151                        esac |
 152                        sed -e "s/^\\(-*\\)$V\\(-*\\)\$/\\1g-i-t--v-e-r-s-i-o-n\2/" \
 153                            -e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/"
 154                        echo "\$"
 155                } >"$actual" &&
 156                if test -f "$expect"
 157                then
 158                        case $cmd in
 159                        *format-patch* | *-stat*)
 160                                test_i18ncmp "$expect" "$actual";;
 161                        *)
 162                                test_cmp "$expect" "$actual";;
 163                        esac &&
 164                        rm -f "$actual"
 165                else
 166                        # this is to help developing new tests.
 167                        cp "$actual" "$expect"
 168                        false
 169                fi
 170        '
 171done <<\EOF
 172diff-tree initial
 173diff-tree -r initial
 174diff-tree -r --abbrev initial
 175diff-tree -r --abbrev=4 initial
 176diff-tree --root initial
 177diff-tree --root --abbrev initial
 178:noellipses diff-tree --root --abbrev initial
 179diff-tree --root -r initial
 180diff-tree --root -r --abbrev initial
 181:noellipses diff-tree --root -r --abbrev initial
 182diff-tree --root -r --abbrev=4 initial
 183:noellipses diff-tree --root -r --abbrev=4 initial
 184diff-tree -p initial
 185diff-tree --root -p initial
 186diff-tree --patch-with-stat initial
 187diff-tree --root --patch-with-stat initial
 188diff-tree --patch-with-raw initial
 189diff-tree --root --patch-with-raw initial
 190
 191diff-tree --pretty initial
 192diff-tree --pretty --root initial
 193diff-tree --pretty -p initial
 194diff-tree --pretty --stat initial
 195diff-tree --pretty --summary initial
 196diff-tree --pretty --stat --summary initial
 197diff-tree --pretty --root -p initial
 198diff-tree --pretty --root --stat initial
 199# improved by Timo's patch
 200diff-tree --pretty --root --summary initial
 201# improved by Timo's patch
 202diff-tree --pretty --root --summary -r initial
 203diff-tree --pretty --root --stat --summary initial
 204diff-tree --pretty --patch-with-stat initial
 205diff-tree --pretty --root --patch-with-stat initial
 206diff-tree --pretty --patch-with-raw initial
 207diff-tree --pretty --root --patch-with-raw initial
 208
 209diff-tree --pretty=oneline initial
 210diff-tree --pretty=oneline --root initial
 211diff-tree --pretty=oneline -p initial
 212diff-tree --pretty=oneline --root -p initial
 213diff-tree --pretty=oneline --patch-with-stat initial
 214# improved by Timo's patch
 215diff-tree --pretty=oneline --root --patch-with-stat initial
 216diff-tree --pretty=oneline --patch-with-raw initial
 217diff-tree --pretty=oneline --root --patch-with-raw initial
 218
 219diff-tree --pretty side
 220diff-tree --pretty -p side
 221diff-tree --pretty --patch-with-stat side
 222
 223diff-tree initial mode
 224diff-tree --stat initial mode
 225diff-tree --summary initial mode
 226
 227diff-tree master
 228diff-tree -p master
 229diff-tree -p -m master
 230diff-tree -c master
 231diff-tree -c --abbrev master
 232:noellipses diff-tree -c --abbrev master
 233diff-tree --cc master
 234# stat only should show the diffstat with the first parent
 235diff-tree -c --stat master
 236diff-tree --cc --stat master
 237diff-tree -c --stat --summary master
 238diff-tree --cc --stat --summary master
 239# stat summary should show the diffstat and summary with the first parent
 240diff-tree -c --stat --summary side
 241diff-tree --cc --stat --summary side
 242diff-tree --cc --shortstat master
 243# improved by Timo's patch
 244diff-tree --cc --patch-with-stat master
 245# improved by Timo's patch
 246diff-tree --cc --patch-with-stat --summary master
 247# this is correct
 248diff-tree --cc --patch-with-stat --summary side
 249
 250log master
 251log -p master
 252log --root master
 253log --root -p master
 254log --patch-with-stat master
 255log --root --patch-with-stat master
 256log --root --patch-with-stat --summary master
 257# improved by Timo's patch
 258log --root -c --patch-with-stat --summary master
 259# improved by Timo's patch
 260log --root --cc --patch-with-stat --summary master
 261log -p --first-parent master
 262log -m -p --first-parent master
 263log -m -p master
 264log -SF master
 265log -S F master
 266log -SF -p master
 267log -SF master --max-count=0
 268log -SF master --max-count=1
 269log -SF master --max-count=2
 270log -GF master
 271log -GF -p master
 272log -GF -p --pickaxe-all master
 273log --decorate --all
 274log --decorate=full --all
 275
 276rev-list --parents HEAD
 277rev-list --children HEAD
 278
 279whatchanged master
 280:noellipses whatchanged master
 281whatchanged -p master
 282whatchanged --root master
 283:noellipses whatchanged --root master
 284whatchanged --root -p master
 285whatchanged --patch-with-stat master
 286whatchanged --root --patch-with-stat master
 287whatchanged --root --patch-with-stat --summary master
 288# improved by Timo's patch
 289whatchanged --root -c --patch-with-stat --summary master
 290# improved by Timo's patch
 291whatchanged --root --cc --patch-with-stat --summary master
 292whatchanged -SF master
 293:noellipses whatchanged -SF master
 294whatchanged -SF -p master
 295
 296log --patch-with-stat master -- dir/
 297whatchanged --patch-with-stat master -- dir/
 298log --patch-with-stat --summary master -- dir/
 299whatchanged --patch-with-stat --summary master -- dir/
 300
 301show initial
 302show --root initial
 303show side
 304show master
 305show -c master
 306show -m master
 307show --first-parent master
 308show --stat side
 309show --stat --summary side
 310show --patch-with-stat side
 311show --patch-with-raw side
 312:noellipses show --patch-with-raw side
 313show --patch-with-stat --summary side
 314
 315format-patch --stdout initial..side
 316format-patch --stdout initial..master^
 317format-patch --stdout initial..master
 318format-patch --stdout --no-numbered initial..master
 319format-patch --stdout --numbered initial..master
 320format-patch --attach --stdout initial..side
 321format-patch --attach --stdout --suffix=.diff initial..side
 322format-patch --attach --stdout initial..master^
 323format-patch --attach --stdout initial..master
 324format-patch --inline --stdout initial..side
 325format-patch --inline --stdout initial..master^
 326format-patch --inline --stdout --numbered-files initial..master
 327format-patch --inline --stdout initial..master
 328format-patch --inline --stdout --subject-prefix=TESTCASE initial..master
 329config format.subjectprefix DIFFERENT_PREFIX
 330format-patch --inline --stdout initial..master^^
 331format-patch --stdout --cover-letter -n initial..master^
 332
 333diff --abbrev initial..side
 334diff -r initial..side
 335diff --stat initial..side
 336diff -r --stat initial..side
 337diff initial..side
 338diff --patch-with-stat initial..side
 339diff --patch-with-raw initial..side
 340:noellipses diff --patch-with-raw initial..side
 341diff --patch-with-stat -r initial..side
 342diff --patch-with-raw -r initial..side
 343:noellipses diff --patch-with-raw -r initial..side
 344diff --name-status dir2 dir
 345diff --no-index --name-status dir2 dir
 346diff --no-index --name-status -- dir2 dir
 347diff --no-index dir dir3
 348diff master master^ side
 349# Can't use spaces...
 350diff --line-prefix=abc master master^ side
 351diff --dirstat master~1 master~2
 352diff --dirstat initial rearrange
 353diff --dirstat-by-file initial rearrange
 354# No-index --abbrev and --no-abbrev
 355diff --raw initial
 356:noellipses diff --raw initial
 357diff --raw --abbrev=4 initial
 358:noellipses diff --raw --abbrev=4 initial
 359diff --raw --no-abbrev initial
 360diff --no-index --raw dir2 dir
 361:noellipses diff --no-index --raw dir2 dir
 362diff --no-index --raw --abbrev=4 dir2 dir
 363:noellipses diff --no-index --raw --abbrev=4 dir2 dir
 364diff --no-index --raw --no-abbrev dir2 dir
 365
 366diff-tree --pretty --root --stat --compact-summary initial
 367diff-tree --pretty -R --root --stat --compact-summary initial
 368diff-tree --stat --compact-summary initial mode
 369diff-tree -R --stat --compact-summary initial mode
 370EOF
 371
 372test_expect_success 'log -S requires an argument' '
 373        test_must_fail git log -S
 374'
 375
 376test_expect_success 'diff --cached on unborn branch' '
 377        echo ref: refs/heads/unborn >.git/HEAD &&
 378        git diff --cached >result &&
 379        test_cmp "$TEST_DIRECTORY/t4013/diff.diff_--cached" result
 380'
 381
 382test_expect_success 'diff --cached -- file on unborn branch' '
 383        git diff --cached -- file0 >result &&
 384        test_cmp "$TEST_DIRECTORY/t4013/diff.diff_--cached_--_file0" result
 385'
 386test_expect_success 'diff --line-prefix with spaces' '
 387        git diff --line-prefix="| | | " --cached -- file0 >result &&
 388        test_cmp "$TEST_DIRECTORY/t4013/diff.diff_--line-prefix_--cached_--_file0" result
 389'
 390
 391test_expect_success 'diff-tree --stdin with log formatting' '
 392        cat >expect <<-\EOF &&
 393        Side
 394        Third
 395        Second
 396        EOF
 397        git rev-list master | git diff-tree --stdin --format=%s -s >actual &&
 398        test_cmp expect actual
 399'
 400
 401test_done