t / t4013-diff-various.shon commit Merge branch 'js/mingw-redirect-std-handles' (421f21c)
   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-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 cmd
 122do
 123        case "$cmd" in
 124        '' | '#'*) continue ;;
 125        esac
 126        test=$(echo "$cmd" | sed -e 's|[/ ][/ ]*|_|g')
 127        pfx=$(printf "%04d" $test_count)
 128        expect="$TEST_DIRECTORY/t4013/diff.$test"
 129        actual="$pfx-diff.$test"
 130
 131        test_expect_success "git $cmd" '
 132                {
 133                        echo "\$ git $cmd"
 134                        git $cmd |
 135                        sed -e "s/^\\(-*\\)$V\\(-*\\)\$/\\1g-i-t--v-e-r-s-i-o-n\2/" \
 136                            -e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/"
 137                        echo "\$"
 138                } >"$actual" &&
 139                if test -f "$expect"
 140                then
 141                        case $cmd in
 142                        *format-patch* | *-stat*)
 143                                test_i18ncmp "$expect" "$actual";;
 144                        *)
 145                                test_cmp "$expect" "$actual";;
 146                        esac &&
 147                        rm -f "$actual"
 148                else
 149                        # this is to help developing new tests.
 150                        cp "$actual" "$expect"
 151                        false
 152                fi
 153        '
 154done <<\EOF
 155diff-tree initial
 156diff-tree -r initial
 157diff-tree -r --abbrev initial
 158diff-tree -r --abbrev=4 initial
 159diff-tree --root initial
 160diff-tree --root --abbrev initial
 161diff-tree --root -r initial
 162diff-tree --root -r --abbrev initial
 163diff-tree --root -r --abbrev=4 initial
 164diff-tree -p initial
 165diff-tree --root -p initial
 166diff-tree --patch-with-stat initial
 167diff-tree --root --patch-with-stat initial
 168diff-tree --patch-with-raw initial
 169diff-tree --root --patch-with-raw initial
 170
 171diff-tree --pretty initial
 172diff-tree --pretty --root initial
 173diff-tree --pretty -p initial
 174diff-tree --pretty --stat initial
 175diff-tree --pretty --summary initial
 176diff-tree --pretty --stat --summary initial
 177diff-tree --pretty --root -p initial
 178diff-tree --pretty --root --stat initial
 179# improved by Timo's patch
 180diff-tree --pretty --root --summary initial
 181# improved by Timo's patch
 182diff-tree --pretty --root --summary -r initial
 183diff-tree --pretty --root --stat --summary initial
 184diff-tree --pretty --patch-with-stat initial
 185diff-tree --pretty --root --patch-with-stat initial
 186diff-tree --pretty --patch-with-raw initial
 187diff-tree --pretty --root --patch-with-raw initial
 188
 189diff-tree --pretty=oneline initial
 190diff-tree --pretty=oneline --root initial
 191diff-tree --pretty=oneline -p initial
 192diff-tree --pretty=oneline --root -p initial
 193diff-tree --pretty=oneline --patch-with-stat initial
 194# improved by Timo's patch
 195diff-tree --pretty=oneline --root --patch-with-stat initial
 196diff-tree --pretty=oneline --patch-with-raw initial
 197diff-tree --pretty=oneline --root --patch-with-raw initial
 198
 199diff-tree --pretty side
 200diff-tree --pretty -p side
 201diff-tree --pretty --patch-with-stat side
 202
 203diff-tree initial mode
 204diff-tree --stat initial mode
 205diff-tree --summary initial mode
 206
 207diff-tree master
 208diff-tree -p master
 209diff-tree -p -m master
 210diff-tree -c master
 211diff-tree -c --abbrev master
 212diff-tree --cc master
 213# stat only should show the diffstat with the first parent
 214diff-tree -c --stat master
 215diff-tree --cc --stat master
 216diff-tree -c --stat --summary master
 217diff-tree --cc --stat --summary master
 218# stat summary should show the diffstat and summary with the first parent
 219diff-tree -c --stat --summary side
 220diff-tree --cc --stat --summary side
 221# improved by Timo's patch
 222diff-tree --cc --patch-with-stat master
 223# improved by Timo's patch
 224diff-tree --cc --patch-with-stat --summary master
 225# this is correct
 226diff-tree --cc --patch-with-stat --summary side
 227
 228log master
 229log -p master
 230log --root master
 231log --root -p master
 232log --patch-with-stat master
 233log --root --patch-with-stat master
 234log --root --patch-with-stat --summary master
 235# improved by Timo's patch
 236log --root -c --patch-with-stat --summary master
 237# improved by Timo's patch
 238log --root --cc --patch-with-stat --summary master
 239log -p --first-parent master
 240log -m -p --first-parent master
 241log -m -p master
 242log -SF master
 243log -S F master
 244log -SF -p master
 245log -SF master --max-count=0
 246log -SF master --max-count=1
 247log -SF master --max-count=2
 248log -GF master
 249log -GF -p master
 250log -GF -p --pickaxe-all master
 251log --decorate --all
 252log --decorate=full --all
 253
 254rev-list --parents HEAD
 255rev-list --children HEAD
 256
 257whatchanged master
 258whatchanged -p master
 259whatchanged --root master
 260whatchanged --root -p master
 261whatchanged --patch-with-stat master
 262whatchanged --root --patch-with-stat master
 263whatchanged --root --patch-with-stat --summary master
 264# improved by Timo's patch
 265whatchanged --root -c --patch-with-stat --summary master
 266# improved by Timo's patch
 267whatchanged --root --cc --patch-with-stat --summary master
 268whatchanged -SF master
 269whatchanged -SF -p master
 270
 271log --patch-with-stat master -- dir/
 272whatchanged --patch-with-stat master -- dir/
 273log --patch-with-stat --summary master -- dir/
 274whatchanged --patch-with-stat --summary master -- dir/
 275
 276show initial
 277show --root initial
 278show side
 279show master
 280show -c master
 281show -m master
 282show --first-parent master
 283show --stat side
 284show --stat --summary side
 285show --patch-with-stat side
 286show --patch-with-raw side
 287show --patch-with-stat --summary side
 288
 289format-patch --stdout initial..side
 290format-patch --stdout initial..master^
 291format-patch --stdout initial..master
 292format-patch --stdout --no-numbered initial..master
 293format-patch --stdout --numbered initial..master
 294format-patch --attach --stdout initial..side
 295format-patch --attach --stdout --suffix=.diff initial..side
 296format-patch --attach --stdout initial..master^
 297format-patch --attach --stdout initial..master
 298format-patch --inline --stdout initial..side
 299format-patch --inline --stdout initial..master^
 300format-patch --inline --stdout --numbered-files initial..master
 301format-patch --inline --stdout initial..master
 302format-patch --inline --stdout --subject-prefix=TESTCASE initial..master
 303config format.subjectprefix DIFFERENT_PREFIX
 304format-patch --inline --stdout initial..master^^
 305format-patch --stdout --cover-letter -n initial..master^
 306
 307diff --abbrev initial..side
 308diff -r initial..side
 309diff --stat initial..side
 310diff -r --stat initial..side
 311diff initial..side
 312diff --patch-with-stat initial..side
 313diff --patch-with-raw initial..side
 314diff --patch-with-stat -r initial..side
 315diff --patch-with-raw -r initial..side
 316diff --name-status dir2 dir
 317diff --no-index --name-status dir2 dir
 318diff --no-index --name-status -- dir2 dir
 319diff --no-index dir dir3
 320diff master master^ side
 321# Can't use spaces...
 322diff --line-prefix=abc master master^ side
 323diff --dirstat master~1 master~2
 324diff --dirstat initial rearrange
 325diff --dirstat-by-file initial rearrange
 326# No-index --abbrev and --no-abbrev
 327diff --raw initial
 328diff --raw --abbrev=4 initial
 329diff --raw --no-abbrev initial
 330diff --no-index --raw dir2 dir
 331diff --no-index --raw --abbrev=4 dir2 dir
 332diff --no-index --raw --no-abbrev dir2 dir
 333EOF
 334
 335test_expect_success 'log -S requires an argument' '
 336        test_must_fail git log -S
 337'
 338
 339test_expect_success 'diff --cached on unborn branch' '
 340        echo ref: refs/heads/unborn >.git/HEAD &&
 341        git diff --cached >result &&
 342        test_cmp "$TEST_DIRECTORY/t4013/diff.diff_--cached" result
 343'
 344
 345test_expect_success 'diff --cached -- file on unborn branch' '
 346        git diff --cached -- file0 >result &&
 347        test_cmp "$TEST_DIRECTORY/t4013/diff.diff_--cached_--_file0" result
 348'
 349test_expect_success 'diff --line-prefix with spaces' '
 350        git diff --line-prefix="| | | " --cached -- file0 >result &&
 351        test_cmp "$TEST_DIRECTORY/t4013/diff.diff_--line-prefix_--cached_--_file0" result
 352'
 353
 354test_expect_success 'diff-tree --stdin with log formatting' '
 355        cat >expect <<-\EOF &&
 356        Side
 357        Third
 358        Second
 359        EOF
 360        git rev-list master | git diff-tree --stdin --format=%s -s >actual &&
 361        test_cmp expect actual
 362'
 363
 364test_done