t / t4017-diff-retval.shon commit Merge branch 'db/delta-applier' into svn-fe (a8d3d26)
   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        test_expect_code 1 git diff-tree --exit-code HEAD^ HEAD
  33'
  34test_expect_success 'git diff-tree HEAD^ HEAD -- a' '
  35        git diff-tree --exit-code HEAD^ HEAD -- a
  36'
  37test_expect_success 'git diff-tree HEAD^ HEAD -- b' '
  38        test_expect_code 1 git diff-tree --exit-code HEAD^ HEAD -- b
  39'
  40test_expect_success 'echo HEAD | git diff-tree --stdin' '
  41        echo $(git rev-parse HEAD) | test_expect_code 1 git diff-tree --exit-code --stdin
  42'
  43test_expect_success 'git diff-tree HEAD HEAD' '
  44        git diff-tree --exit-code HEAD HEAD
  45'
  46test_expect_success 'git diff-files' '
  47        git diff-files --exit-code
  48'
  49test_expect_success 'git diff-index --cached HEAD' '
  50        git diff-index --exit-code --cached HEAD
  51'
  52test_expect_success 'git diff-index --cached HEAD^' '
  53        test_expect_code 1 git diff-index --exit-code --cached HEAD^
  54'
  55test_expect_success 'git diff-index --cached HEAD^' '
  56        echo text >>b &&
  57        echo 3 >c &&
  58        git add . &&
  59        test_expect_code 1 git diff-index --exit-code --cached HEAD^
  60'
  61test_expect_success 'git diff-tree -Stext HEAD^ HEAD -- b' '
  62        git commit -m "text in b" &&
  63        test_expect_code 1 git diff-tree -p --exit-code -Stext HEAD^ HEAD -- b
  64'
  65test_expect_success 'git diff-tree -Snot-found HEAD^ HEAD -- b' '
  66        git diff-tree -p --exit-code -Snot-found HEAD^ HEAD -- b
  67'
  68test_expect_success 'git diff-files' '
  69        echo 3 >>c &&
  70        test_expect_code 1 git diff-files --exit-code
  71'
  72test_expect_success 'git diff-index --cached HEAD' '
  73        git update-index c &&
  74        test_expect_code 1 git diff-index --exit-code --cached HEAD
  75'
  76
  77test_expect_success '--check --exit-code returns 0 for no difference' '
  78
  79        git diff --check --exit-code
  80
  81'
  82
  83test_expect_success '--check --exit-code returns 1 for a clean difference' '
  84
  85        echo "good" > a &&
  86        test_expect_code 1 git diff --check --exit-code
  87
  88'
  89
  90test_expect_success '--check --exit-code returns 3 for a dirty difference' '
  91
  92        echo "bad   " >> a &&
  93        test_expect_code 3 git diff --check --exit-code
  94
  95'
  96
  97test_expect_success '--check with --no-pager returns 2 for dirty difference' '
  98
  99        test_expect_code 2 git --no-pager diff --check
 100
 101'
 102
 103test_expect_success 'check should test not just the last line' '
 104        echo "" >>a &&
 105        test_expect_code 2 git --no-pager diff --check
 106
 107'
 108
 109test_expect_success 'check detects leftover conflict markers' '
 110        git reset --hard &&
 111        git checkout HEAD^ &&
 112        echo binary >>b &&
 113        git commit -m "side" b &&
 114        test_must_fail git merge master &&
 115        git add b &&
 116        test_expect_code 2 git --no-pager diff --cached --check >test.out &&
 117        test 3 = $(grep "conflict marker" test.out | wc -l) &&
 118        git reset --hard
 119'
 120
 121test_expect_success 'check honors conflict marker length' '
 122        git reset --hard &&
 123        echo ">>>>>>> boo" >>b &&
 124        echo "======" >>a &&
 125        git diff --check a &&
 126        test_expect_code 2 git diff --check b &&
 127        git reset --hard &&
 128        echo ">>>>>>>> boo" >>b &&
 129        echo "========" >>a &&
 130        git diff --check &&
 131        echo "b conflict-marker-size=8" >.gitattributes &&
 132        test_expect_code 2 git diff --check b &&
 133        git diff --check a &&
 134        git reset --hard
 135'
 136
 137test_done