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 SYMLINKS
'typechange diff' '
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"
63 GIT_EXTERNAL_DIFF=echo git diff --no-ext-diff >actual &&
65 test_cmp expect actual
68 test_expect_success
'diff attribute' '
72 git config diff.parrot.command echo &&
74 echo >.gitattributes "file diff=parrot" &&
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"
88 test_expect_success
'diff attribute should apply only to diff' '
91 grep "^diff --git a/file b/file"
95 test_expect_success
'diff attribute and --no-ext-diff' '
97 git diff --no-ext-diff |
98 grep "^diff --git a/file b/file"
102 test_expect_success
'diff attribute' '
104 git config --unset diff.parrot.command &&
105 git config diff.color.command echo &&
107 echo >.gitattributes "file diff=color" &&
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"
121 test_expect_success
'diff attribute should apply only to diff' '
124 grep "^diff --git a/file b/file"
128 test_expect_success
'diff attribute and --no-ext-diff' '
130 git diff --no-ext-diff |
131 grep "^diff --git a/file b/file"
135 test_expect_success
'no diff with -diff' '
136 echo >.gitattributes "file -diff" &&
137 git diff | grep Binary
140 echo NULZbetweenZwords | perl
-pe 'y/Z/\000/' > file
142 test_expect_success
'force diff with "diff"' '
143 echo >.gitattributes "file diff" &&
145 test_cmp "$TEST_DIRECTORY"/t4020/diff.NUL actual
148 test_expect_success
'GIT_EXTERNAL_DIFF with more than one changed files' '
149 echo anotherfile > file2 &&
151 git commit -m "added 2nd file" &&
152 echo modified >file2 &&
153 GIT_EXTERNAL_DIFF=echo git diff
156 test_expect_success
'GIT_EXTERNAL_DIFF generates pretty paths' '
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 &&
165 echo "#!$SHELL_PATH" >fake-diff.sh
166 cat >> fake-diff.sh
<<\EOF
169 chmod a
+x fake-diff.sh
175 test_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)
181 test_expect_success
'diff --cached' '
183 git update-index --assume-unchanged file &&
185 git diff --cached >actual &&
186 test_cmp "$TEST_DIRECTORY"/t4020/diff.NUL actual