3 test_description='external diff interface test'
 
   7 _z40=0000000000000000000000000000000000000000
 
   9 test_expect_success setup '
 
  14         git commit -m initial &&
 
  19         git commit -m second &&
 
  25 test_expect_success 'GIT_EXTERNAL_DIFF environment' '
 
  27         GIT_EXTERNAL_DIFF=echo git diff | {
 
  28                 read path oldfile oldhex oldmode newfile newhex newmode &&
 
  29                 test "z$path" = zfile &&
 
  30                 test "z$oldmode" = z100644 &&
 
  31                 test "z$newhex" = "z$_z40" &&
 
  32                 test "z$newmode" = z100644 &&
 
  33                 oh=$(git rev-parse --verify HEAD:file) &&
 
  34                 test "z$oh" = "z$oldhex"
 
  39 test_expect_success 'GIT_EXTERNAL_DIFF environment should apply only to diff' '
 
  41         GIT_EXTERNAL_DIFF=echo git log -p -1 HEAD |
 
  42         grep "^diff --git a/file b/file"
 
  46 test_expect_success 'GIT_EXTERNAL_DIFF environment and --no-ext-diff' '
 
  48         GIT_EXTERNAL_DIFF=echo git diff --no-ext-diff |
 
  49         grep "^diff --git a/file b/file"
 
  53 test_expect_success 'diff attribute' '
 
  55         git config diff.parrot.command echo &&
 
  57         echo >.gitattributes "file diff=parrot" &&
 
  60                 read path oldfile oldhex oldmode newfile newhex newmode &&
 
  61                 test "z$path" = zfile &&
 
  62                 test "z$oldmode" = z100644 &&
 
  63                 test "z$newhex" = "z$_z40" &&
 
  64                 test "z$newmode" = z100644 &&
 
  65                 oh=$(git rev-parse --verify HEAD:file) &&
 
  66                 test "z$oh" = "z$oldhex"
 
  71 test_expect_success 'diff attribute should apply only to diff' '
 
  74         grep "^diff --git a/file b/file"
 
  78 test_expect_success 'diff attribute and --no-ext-diff' '
 
  80         git diff --no-ext-diff |
 
  81         grep "^diff --git a/file b/file"
 
  85 test_expect_success 'diff attribute' '
 
  87         git config --unset diff.parrot.command &&
 
  88         git config diff.color.command echo &&
 
  90         echo >.gitattributes "file diff=color" &&
 
  93                 read path oldfile oldhex oldmode newfile newhex newmode &&
 
  94                 test "z$path" = zfile &&
 
  95                 test "z$oldmode" = z100644 &&
 
  96                 test "z$newhex" = "z$_z40" &&
 
  97                 test "z$newmode" = z100644 &&
 
  98                 oh=$(git rev-parse --verify HEAD:file) &&
 
  99                 test "z$oh" = "z$oldhex"
 
 104 test_expect_success 'diff attribute should apply only to diff' '
 
 107         grep "^diff --git a/file b/file"
 
 111 test_expect_success 'diff attribute and --no-ext-diff' '
 
 113         git diff --no-ext-diff |
 
 114         grep "^diff --git a/file b/file"
 
 118 test_expect_success 'no diff with -diff' '
 
 119         echo >.gitattributes "file -diff" &&
 
 120         git diff | grep Binary
 
 123 echo NULZbetweenZwords | perl -pe 'y/Z/\000/' > file
 
 125 test_expect_success 'force diff with "diff"' '
 
 126         echo >.gitattributes "file diff" &&
 
 128         test_cmp "$TEST_DIRECTORY"/t4020/diff.NUL actual
 
 131 test_expect_success 'GIT_EXTERNAL_DIFF with more than one changed files' '
 
 132         echo anotherfile > file2 &&
 
 134         git commit -m "added 2nd file" &&
 
 135         echo modified >file2 &&
 
 136         GIT_EXTERNAL_DIFF=echo git diff
 
 139 test_expect_success 'GIT_EXTERNAL_DIFF generates pretty paths' '
 
 142         echo with extension > file.ext &&
 
 143         GIT_EXTERNAL_DIFF=echo git diff file.ext | grep ......_file\.ext &&
 
 144         git update-index --force-remove file.ext &&
 
 148 echo "#!$SHELL_PATH" >fake-diff.sh
 
 149 cat >> fake-diff.sh <<\EOF
 
 152 chmod a+x fake-diff.sh
 
 158 test_expect_success 'external diff with autocrlf = true' '
 
 159         git config core.autocrlf true &&
 
 160         GIT_EXTERNAL_DIFF=./fake-diff.sh git diff &&
 
 161         test $(wc -l < crlfed.txt) = $(cat crlfed.txt | keep_only_cr | wc -c)
 
 164 test_expect_success 'diff --cached' '
 
 166         git update-index --assume-unchanged file &&
 
 168         git diff --cached >actual &&
 
 169         test_cmp "$TEST_DIRECTORY"/t4020/diff.NUL actual