t / t4020-diff-external.shon commit diff: correctly disable external_diff with --no-ext-diff (bd8c1a9)
   1#!/bin/sh
   2
   3test_description='external diff interface test'
   4
   5. ./test-lib.sh
   6
   7test_expect_success setup '
   8
   9        test_tick &&
  10        echo initial >file &&
  11        git add file &&
  12        git commit -m initial &&
  13
  14        test_tick &&
  15        echo second >file &&
  16        git add file &&
  17        git commit -m second &&
  18
  19        test_tick &&
  20        echo third >file
  21'
  22
  23test_expect_success 'GIT_EXTERNAL_DIFF environment' '
  24
  25        GIT_EXTERNAL_DIFF=echo git diff | {
  26                read path oldfile oldhex oldmode newfile newhex newmode &&
  27                test "z$path" = zfile &&
  28                test "z$oldmode" = z100644 &&
  29                test "z$newhex" = "z$_z40" &&
  30                test "z$newmode" = z100644 &&
  31                oh=$(git rev-parse --verify HEAD:file) &&
  32                test "z$oh" = "z$oldhex"
  33        }
  34
  35'
  36
  37test_expect_success 'GIT_EXTERNAL_DIFF environment should apply only to diff' '
  38
  39        GIT_EXTERNAL_DIFF=echo git log -p -1 HEAD |
  40        grep "^diff --git a/file b/file"
  41
  42'
  43
  44test_expect_success 'GIT_EXTERNAL_DIFF environment and --no-ext-diff' '
  45
  46        GIT_EXTERNAL_DIFF=echo git diff --no-ext-diff |
  47        grep "^diff --git a/file b/file"
  48
  49'
  50
  51test_expect_success SYMLINKS 'typechange diff' '
  52        rm -f file &&
  53        ln -s elif file &&
  54        GIT_EXTERNAL_DIFF=echo git diff  | {
  55                read path oldfile oldhex oldmode newfile newhex newmode &&
  56                test "z$path" = zfile &&
  57                test "z$oldmode" = z100644 &&
  58                test "z$newhex" = "z$_z40" &&
  59                test "z$newmode" = z120000 &&
  60                oh=$(git rev-parse --verify HEAD:file) &&
  61                test "z$oh" = "z$oldhex"
  62        } &&
  63        GIT_EXTERNAL_DIFF=echo git diff --no-ext-diff >actual &&
  64        git diff >expect &&
  65        test_cmp expect actual
  66'
  67
  68test_expect_success 'diff attribute' '
  69        git reset --hard &&
  70        echo third >file &&
  71
  72        git config diff.parrot.command echo &&
  73
  74        echo >.gitattributes "file diff=parrot" &&
  75
  76        git diff | {
  77                read path oldfile oldhex oldmode newfile newhex newmode &&
  78                test "z$path" = zfile &&
  79                test "z$oldmode" = z100644 &&
  80                test "z$newhex" = "z$_z40" &&
  81                test "z$newmode" = z100644 &&
  82                oh=$(git rev-parse --verify HEAD:file) &&
  83                test "z$oh" = "z$oldhex"
  84        }
  85
  86'
  87
  88test_expect_success 'diff attribute should apply only to diff' '
  89
  90        git log -p -1 HEAD |
  91        grep "^diff --git a/file b/file"
  92
  93'
  94
  95test_expect_success 'diff attribute and --no-ext-diff' '
  96
  97        git diff --no-ext-diff |
  98        grep "^diff --git a/file b/file"
  99
 100'
 101
 102test_expect_success 'diff attribute' '
 103
 104        git config --unset diff.parrot.command &&
 105        git config diff.color.command echo &&
 106
 107        echo >.gitattributes "file diff=color" &&
 108
 109        git diff | {
 110                read path oldfile oldhex oldmode newfile newhex newmode &&
 111                test "z$path" = zfile &&
 112                test "z$oldmode" = z100644 &&
 113                test "z$newhex" = "z$_z40" &&
 114                test "z$newmode" = z100644 &&
 115                oh=$(git rev-parse --verify HEAD:file) &&
 116                test "z$oh" = "z$oldhex"
 117        }
 118
 119'
 120
 121test_expect_success 'diff attribute should apply only to diff' '
 122
 123        git log -p -1 HEAD |
 124        grep "^diff --git a/file b/file"
 125
 126'
 127
 128test_expect_success 'diff attribute and --no-ext-diff' '
 129
 130        git diff --no-ext-diff |
 131        grep "^diff --git a/file b/file"
 132
 133'
 134
 135test_expect_success 'no diff with -diff' '
 136        echo >.gitattributes "file -diff" &&
 137        git diff | grep Binary
 138'
 139
 140echo NULZbetweenZwords | perl -pe 'y/Z/\000/' > file
 141
 142test_expect_success 'force diff with "diff"' '
 143        echo >.gitattributes "file diff" &&
 144        git diff >actual &&
 145        test_cmp "$TEST_DIRECTORY"/t4020/diff.NUL actual
 146'
 147
 148test_expect_success 'GIT_EXTERNAL_DIFF with more than one changed files' '
 149        echo anotherfile > file2 &&
 150        git add file2 &&
 151        git commit -m "added 2nd file" &&
 152        echo modified >file2 &&
 153        GIT_EXTERNAL_DIFF=echo git diff
 154'
 155
 156test_expect_success 'GIT_EXTERNAL_DIFF generates pretty paths' '
 157        touch file.ext &&
 158        git add file.ext &&
 159        echo with extension > file.ext &&
 160        GIT_EXTERNAL_DIFF=echo git diff file.ext | grep ......_file\.ext &&
 161        git update-index --force-remove file.ext &&
 162        rm file.ext
 163'
 164
 165echo "#!$SHELL_PATH" >fake-diff.sh
 166cat >> fake-diff.sh <<\EOF
 167cat $2 >> crlfed.txt
 168EOF
 169chmod a+x fake-diff.sh
 170
 171keep_only_cr () {
 172        tr -dc '\015'
 173}
 174
 175test_expect_success 'external diff with autocrlf = true' '
 176        git config core.autocrlf true &&
 177        GIT_EXTERNAL_DIFF=./fake-diff.sh git diff &&
 178        test $(wc -l < crlfed.txt) = $(cat crlfed.txt | keep_only_cr | wc -c)
 179'
 180
 181test_expect_success 'diff --cached' '
 182        git add file &&
 183        git update-index --assume-unchanged file &&
 184        echo second >file &&
 185        git diff --cached >actual &&
 186        test_cmp "$TEST_DIRECTORY"/t4020/diff.NUL actual
 187'
 188
 189test_done