t / t4017-diff-retval.shon commit Merge branch 'jc/for-each-ref' (e4b8931)
   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 zeroth &&
  11        echo 1 >a &&
  12        git add . &&
  13        git commit -m first &&
  14        echo 2 >b &&
  15        git add . &&
  16        git commit -a -m second
  17'
  18
  19test_expect_success 'git diff --quiet -w  HEAD^^ HEAD^' '
  20        git diff --quiet -w HEAD^^ HEAD^
  21'
  22
  23test_expect_success 'git diff --quiet HEAD^^ HEAD^' '
  24        test_must_fail git diff --quiet HEAD^^ HEAD^
  25'
  26
  27test_expect_success 'git diff --quiet -w  HEAD^ HEAD' '
  28        test_must_fail git diff --quiet -w HEAD^ HEAD
  29'
  30
  31test_expect_success 'git diff-tree HEAD^ HEAD' '
  32        git diff-tree --exit-code HEAD^ HEAD
  33        test $? = 1
  34'
  35test_expect_success 'git diff-tree HEAD^ HEAD -- a' '
  36        git diff-tree --exit-code HEAD^ HEAD -- a
  37        test $? = 0
  38'
  39test_expect_success 'git diff-tree HEAD^ HEAD -- b' '
  40        git diff-tree --exit-code HEAD^ HEAD -- b
  41        test $? = 1
  42'
  43test_expect_success 'echo HEAD | git diff-tree --stdin' '
  44        echo $(git rev-parse HEAD) | git diff-tree --exit-code --stdin
  45        test $? = 1
  46'
  47test_expect_success 'git diff-tree HEAD HEAD' '
  48        git diff-tree --exit-code HEAD HEAD
  49        test $? = 0
  50'
  51test_expect_success 'git diff-files' '
  52        git diff-files --exit-code
  53        test $? = 0
  54'
  55test_expect_success 'git diff-index --cached HEAD' '
  56        git diff-index --exit-code --cached HEAD
  57        test $? = 0
  58'
  59test_expect_success 'git diff-index --cached HEAD^' '
  60        git diff-index --exit-code --cached HEAD^
  61        test $? = 1
  62'
  63test_expect_success 'git diff-index --cached HEAD^' '
  64        echo text >>b &&
  65        echo 3 >c &&
  66        git add . && {
  67                git diff-index --exit-code --cached HEAD^
  68                test $? = 1
  69        }
  70'
  71test_expect_success 'git diff-tree -Stext HEAD^ HEAD -- b' '
  72        git commit -m "text in b" && {
  73                git diff-tree -p --exit-code -Stext HEAD^ HEAD -- b
  74                test $? = 1
  75        }
  76'
  77test_expect_success 'git diff-tree -Snot-found HEAD^ HEAD -- b' '
  78        git diff-tree -p --exit-code -Snot-found HEAD^ HEAD -- b
  79        test $? = 0
  80'
  81test_expect_success 'git diff-files' '
  82        echo 3 >>c && {
  83                git diff-files --exit-code
  84                test $? = 1
  85        }
  86'
  87test_expect_success 'git diff-index --cached HEAD' '
  88        git update-index c && {
  89                git diff-index --exit-code --cached HEAD
  90                test $? = 1
  91        }
  92'
  93
  94test_expect_success '--check --exit-code returns 0 for no difference' '
  95
  96        git diff --check --exit-code
  97
  98'
  99
 100test_expect_success '--check --exit-code returns 1 for a clean difference' '
 101
 102        echo "good" > a &&
 103        git diff --check --exit-code
 104        test $? = 1
 105
 106'
 107
 108test_expect_success '--check --exit-code returns 3 for a dirty difference' '
 109
 110        echo "bad   " >> a &&
 111        git diff --check --exit-code
 112        test $? = 3
 113
 114'
 115
 116test_expect_success '--check with --no-pager returns 2 for dirty difference' '
 117
 118        git --no-pager diff --check
 119        test $? = 2
 120
 121'
 122
 123
 124test_expect_success 'check should test not just the last line' '
 125        echo "" >>a &&
 126        git --no-pager diff --check
 127        test $? = 2
 128
 129'
 130
 131test_expect_success 'check detects leftover conflict markers' '
 132        git reset --hard &&
 133        git checkout HEAD^ &&
 134        echo binary >>b &&
 135        git commit -m "side" b &&
 136        test_must_fail git merge master &&
 137        git add b && (
 138                git --no-pager diff --cached --check >test.out
 139                test $? = 2
 140        ) &&
 141        test 3 = $(grep "conflict marker" test.out | wc -l) &&
 142        git reset --hard
 143'
 144
 145test_done