t / t4035-diff-quiet.shon commit Merge branch 'ah/fix-http-push' into maint (cd989a9)
   1#!/bin/sh
   2
   3test_description='Return value of diffs'
   4
   5. ./test-lib.sh
   6
   7test_expect_success 'setup' '
   8        echo 1 >a &&
   9        git add . &&
  10        git commit -m first &&
  11        echo 2 >b &&
  12        git add . &&
  13        git commit -a -m second &&
  14        mkdir -p test-outside/repo && (
  15                cd test-outside/repo &&
  16                git init &&
  17                echo "1 1" >a &&
  18                git add . &&
  19                git commit -m 1
  20        ) &&
  21        mkdir -p test-outside/non/git && (
  22                cd test-outside/non/git &&
  23                echo "1 1" >a &&
  24                echo "1 1" >matching-file &&
  25                echo "1 1 " >trailing-space &&
  26                echo "1   1" >extra-space &&
  27                echo "2" >never-match
  28        )
  29'
  30
  31test_expect_success 'git diff-tree HEAD^ HEAD' '
  32        git diff-tree --quiet HEAD^ HEAD >cnt
  33        test $? = 1 && test_line_count = 0 cnt
  34'
  35test_expect_success 'git diff-tree HEAD^ HEAD -- a' '
  36        git diff-tree --quiet HEAD^ HEAD -- a >cnt
  37        test $? = 0 && test_line_count = 0 cnt
  38'
  39test_expect_success 'git diff-tree HEAD^ HEAD -- b' '
  40        git diff-tree --quiet HEAD^ HEAD -- b >cnt
  41        test $? = 1 && test_line_count = 0 cnt
  42'
  43# this diff outputs one line: sha1 of the given head
  44test_expect_success 'echo HEAD | git diff-tree --stdin' '
  45        echo $(git rev-parse HEAD) | git diff-tree --quiet --stdin >cnt
  46        test $? = 1 && test_line_count = 1 cnt
  47'
  48test_expect_success 'git diff-tree HEAD HEAD' '
  49        git diff-tree --quiet HEAD HEAD >cnt
  50        test $? = 0 && test_line_count = 0 cnt
  51'
  52test_expect_success 'git diff-files' '
  53        git diff-files --quiet >cnt
  54        test $? = 0 && test_line_count = 0 cnt
  55'
  56test_expect_success 'git diff-index --cached HEAD' '
  57        git diff-index --quiet --cached HEAD >cnt
  58        test $? = 0 && test_line_count = 0 cnt
  59'
  60test_expect_success 'git diff-index --cached HEAD^' '
  61        git diff-index --quiet --cached HEAD^ >cnt
  62        test $? = 1 && test_line_count = 0 cnt
  63'
  64test_expect_success 'git diff-index --cached HEAD^' '
  65        echo text >>b &&
  66        echo 3 >c &&
  67        git add . && {
  68                git diff-index --quiet --cached HEAD^ >cnt
  69                test $? = 1 && test_line_count = 0 cnt
  70        }
  71'
  72test_expect_success 'git diff-tree -Stext HEAD^ HEAD -- b' '
  73        git commit -m "text in b" && {
  74                git diff-tree --quiet -Stext HEAD^ HEAD -- b >cnt
  75                test $? = 1 && test_line_count = 0 cnt
  76        }
  77'
  78test_expect_success 'git diff-tree -Snot-found HEAD^ HEAD -- b' '
  79        git diff-tree --quiet -Snot-found HEAD^ HEAD -- b >cnt
  80        test $? = 0 && test_line_count = 0 cnt
  81'
  82test_expect_success 'git diff-files' '
  83        echo 3 >>c && {
  84                git diff-files --quiet >cnt
  85                test $? = 1 && test_line_count = 0 cnt
  86        }
  87'
  88test_expect_success 'git diff-index --cached HEAD' '
  89        git update-index c && {
  90                git diff-index --quiet --cached HEAD >cnt
  91                test $? = 1 && test_line_count = 0 cnt
  92        }
  93'
  94
  95test_expect_success 'git diff, one file outside repo' '
  96        (
  97                cd test-outside/repo &&
  98                test_expect_code 0 git diff --quiet a ../non/git/matching-file &&
  99                test_expect_code 1 git diff --quiet a ../non/git/extra-space
 100        )
 101'
 102
 103test_expect_success 'git diff, both files outside repo' '
 104        (
 105                GIT_CEILING_DIRECTORIES="$TRASH_DIRECTORY/test-outside" &&
 106                export GIT_CEILING_DIRECTORIES &&
 107                cd test-outside/non/git &&
 108                test_expect_code 0 git diff --quiet a matching-file &&
 109                test_expect_code 1 git diff --quiet a extra-space
 110        )
 111'
 112
 113test_expect_success 'git diff --ignore-space-at-eol, one file outside repo' '
 114        (
 115                cd test-outside/repo &&
 116                test_expect_code 0 git diff --quiet --ignore-space-at-eol a ../non/git/trailing-space &&
 117                test_expect_code 1 git diff --quiet --ignore-space-at-eol a ../non/git/extra-space
 118        )
 119'
 120
 121test_expect_success 'git diff --ignore-space-at-eol, both files outside repo' '
 122        (
 123                GIT_CEILING_DIRECTORIES="$TRASH_DIRECTORY/test-outside" &&
 124                export GIT_CEILING_DIRECTORIES &&
 125                cd test-outside/non/git &&
 126                test_expect_code 0 git diff --quiet --ignore-space-at-eol a trailing-space &&
 127                test_expect_code 1 git diff --quiet --ignore-space-at-eol a extra-space
 128        )
 129'
 130
 131test_expect_success 'git diff --ignore-all-space, one file outside repo' '
 132        (
 133                cd test-outside/repo &&
 134                test_expect_code 0 git diff --quiet --ignore-all-space a ../non/git/trailing-space &&
 135                test_expect_code 0 git diff --quiet --ignore-all-space a ../non/git/extra-space &&
 136                test_expect_code 1 git diff --quiet --ignore-all-space a ../non/git/never-match
 137        )
 138'
 139
 140test_expect_success 'git diff --ignore-all-space, both files outside repo' '
 141        (
 142                GIT_CEILING_DIRECTORIES="$TRASH_DIRECTORY/test-outside" &&
 143                export GIT_CEILING_DIRECTORIES &&
 144                cd test-outside/non/git &&
 145                test_expect_code 0 git diff --quiet --ignore-all-space a trailing-space &&
 146                test_expect_code 0 git diff --quiet --ignore-all-space a extra-space &&
 147                test_expect_code 1 git diff --quiet --ignore-all-space a never-match
 148        )
 149'
 150
 151test_expect_success 'git diff --quiet ignores stat-change only entries' '
 152        test-chmtime +10 a &&
 153        echo modified >>b &&
 154        test_expect_code 1 git diff --quiet
 155'
 156
 157test_done