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