3 test_description='external diff interface test'
7 test_expect_success setup '
12 git commit -m initial &&
17 git commit -m second &&
23 test_expect_success 'GIT_EXTERNAL_DIFF environment' '
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"
37 test_expect_success 'GIT_EXTERNAL_DIFF environment should apply only to diff' '
39 GIT_EXTERNAL_DIFF=echo git log -p -1 HEAD |
40 grep "^diff --git a/file b/file"
44 test_expect_success 'GIT_EXTERNAL_DIFF environment and --no-ext-diff' '
46 GIT_EXTERNAL_DIFF=echo git diff --no-ext-diff |
47 grep "^diff --git a/file b/file"
51 test_expect_success 'diff attribute' '
53 git config diff.parrot.command echo &&
55 echo >.gitattributes "file diff=parrot" &&
58 read path oldfile oldhex oldmode newfile newhex newmode &&
59 test "z$path" = zfile &&
60 test "z$oldmode" = z100644 &&
61 test "z$newhex" = "z$_z40" &&
62 test "z$newmode" = z100644 &&
63 oh=$(git rev-parse --verify HEAD:file) &&
64 test "z$oh" = "z$oldhex"
69 test_expect_success 'diff attribute should apply only to diff' '
72 grep "^diff --git a/file b/file"
76 test_expect_success 'diff attribute and --no-ext-diff' '
78 git diff --no-ext-diff |
79 grep "^diff --git a/file b/file"
83 test_expect_success 'diff attribute' '
85 git config --unset diff.parrot.command &&
86 git config diff.color.command echo &&
88 echo >.gitattributes "file diff=color" &&
91 read path oldfile oldhex oldmode newfile newhex newmode &&
92 test "z$path" = zfile &&
93 test "z$oldmode" = z100644 &&
94 test "z$newhex" = "z$_z40" &&
95 test "z$newmode" = z100644 &&
96 oh=$(git rev-parse --verify HEAD:file) &&
97 test "z$oh" = "z$oldhex"
102 test_expect_success 'diff attribute should apply only to diff' '
105 grep "^diff --git a/file b/file"
109 test_expect_success 'diff attribute and --no-ext-diff' '
111 git diff --no-ext-diff |
112 grep "^diff --git a/file b/file"
116 test_expect_success 'no diff with -diff' '
117 echo >.gitattributes "file -diff" &&
118 git diff | grep Binary
121 echo NULZbetweenZwords | perl -pe 'y/Z/\000/' > file
123 test_expect_success 'force diff with "diff"' '
124 echo >.gitattributes "file diff" &&
126 test_cmp "$TEST_DIRECTORY"/t4020/diff.NUL actual
129 test_expect_success 'GIT_EXTERNAL_DIFF with more than one changed files' '
130 echo anotherfile > file2 &&
132 git commit -m "added 2nd file" &&
133 echo modified >file2 &&
134 GIT_EXTERNAL_DIFF=echo git diff
137 test_expect_success 'GIT_EXTERNAL_DIFF generates pretty paths' '
140 echo with extension > file.ext &&
141 GIT_EXTERNAL_DIFF=echo git diff file.ext | grep ......_file\.ext &&
142 git update-index --force-remove file.ext &&
146 echo "#!$SHELL_PATH" >fake-diff.sh
147 cat >> fake-diff.sh <<\EOF
150 chmod a+x fake-diff.sh
156 test_expect_success 'external diff with autocrlf = true' '
157 git config core.autocrlf true &&
158 GIT_EXTERNAL_DIFF=./fake-diff.sh git diff &&
159 test $(wc -l < crlfed.txt) = $(cat crlfed.txt | keep_only_cr | wc -c)
162 test_expect_success 'diff --cached' '
164 git update-index --assume-unchanged file &&
166 git diff --cached >actual &&
167 test_cmp "$TEST_DIRECTORY"/t4020/diff.NUL actual