t / t4017-diff-retval.shon commit Merge branch 'master' of git://repo.or.cz/git-gui (06cfa8a)
   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
 123test_expect_success 'check should test not just the last line' '
 124        echo "" >>a &&
 125        git --no-pager diff --check
 126        test $? = 2
 127
 128'
 129
 130test_expect_success 'check detects leftover conflict markers' '
 131        git reset --hard &&
 132        git checkout HEAD^ &&
 133        echo binary >>b &&
 134        git commit -m "side" b &&
 135        test_must_fail git merge master &&
 136        git add b && (
 137                git --no-pager diff --cached --check >test.out
 138                test $? = 2
 139        ) &&
 140        test 3 = $(grep "conflict marker" test.out | wc -l) &&
 141        git reset --hard
 142'
 143
 144test_expect_success 'check honors conflict marker length' '
 145        git reset --hard &&
 146        echo ">>>>>>> boo" >>b &&
 147        echo "======" >>a &&
 148        git diff --check a &&
 149        (
 150                git diff --check b
 151                test $? = 2
 152        ) &&
 153        git reset --hard &&
 154        echo ">>>>>>>> boo" >>b &&
 155        echo "========" >>a &&
 156        git diff --check &&
 157        echo "b conflict-marker-size=8" >.gitattributes &&
 158        (
 159                git diff --check b
 160                test $? = 2
 161        ) &&
 162        git diff --check a &&
 163        git reset --hard
 164'
 165
 166test_done