1 #!/bin/sh
3 test_description='external diff interface test'
5 . ./test-lib.sh
7 test_expect_success setup '
9 test_tick &&
10 echo initial >file &&
11 git add file &&
12 git commit -m initial &&
14 test_tick &&
15 echo second >file &&
16 git add file &&
17 git commit -m second &&
19 test_tick &&
20 echo third >file
21 '
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"
33 }
35 '
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"
42 '
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"
49 '
51 test_expect_success 'diff attribute' '
53 git config diff.parrot.command echo &&
55 echo >.gitattributes "file diff=parrot" &&
57 git diff | {
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"
65 }
67 '
69 test_expect_success 'diff attribute should apply only to diff' '
71 git log -p -1 HEAD |
72 grep "^diff --git a/file b/file"
74 '
76 test_expect_success 'diff attribute and --no-ext-diff' '
78 git diff --no-ext-diff |
79 grep "^diff --git a/file b/file"
81 '
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" &&
90 git diff | {
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"
98 }
100 '
102 test_expect_success 'diff attribute should apply only to diff' '
104 git log -p -1 HEAD |
105 grep "^diff --git a/file b/file"
107 '
109 test_expect_success 'diff attribute and --no-ext-diff' '
111 git diff --no-ext-diff |
112 grep "^diff --git a/file b/file"
114 '
116 test_expect_success 'no diff with -diff' '
117 echo >.gitattributes "file -diff" &&
118 git diff | grep Binary
119 '
121 echo NULZbetweenZwords | perl -pe 'y/Z/\000/' > file
123 test_expect_success 'force diff with "diff"' '
124 echo >.gitattributes "file diff" &&
125 git diff >actual &&
126 test_cmp "$TEST_DIRECTORY"/t4020/diff.NUL actual
127 '
129 test_expect_success 'GIT_EXTERNAL_DIFF with more than one changed files' '
130 echo anotherfile > file2 &&
131 git add file2 &&
132 git commit -m "added 2nd file" &&
133 echo modified >file2 &&
134 GIT_EXTERNAL_DIFF=echo git diff
135 '
137 test_expect_success 'GIT_EXTERNAL_DIFF generates pretty paths' '
138 touch file.ext &&
139 git add file.ext &&
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 &&
143 rm file.ext
144 '
146 echo "#!$SHELL_PATH" >fake-diff.sh
147 cat >> fake-diff.sh <<\EOF
148 cat $2 >> crlfed.txt
149 EOF
150 chmod a+x fake-diff.sh
152 keep_only_cr () {
153 tr -dc '\015'
154 }
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)
160 '
162 test_expect_success 'diff --cached' '
163 git add file &&
164 git update-index --assume-unchanged file &&
165 echo second >file &&
166 git diff --cached >actual &&
167 test_cmp "$TEST_DIRECTORY"/t4020/diff.NUL actual
168 '
170 test_done