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