diff: correctly disable external_diff with --no-ext-diff
[alt-git.git] / t / t4020-diff-external.sh
blob025df533ca8969e67c38f8dcb913c9021b816c57
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
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' '
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
68 test_expect_success 'diff attribute' '
69 git reset --hard &&
70 echo third >file &&
72 git config diff.parrot.command echo &&
74 echo >.gitattributes "file diff=parrot" &&
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"
88 test_expect_success 'diff attribute should apply only to diff' '
90 git log -p -1 HEAD |
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" &&
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"
121 test_expect_success 'diff attribute should apply only to diff' '
123 git log -p -1 HEAD |
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" &&
144 git diff >actual &&
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 &&
150 git add 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' '
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
165 echo "#!$SHELL_PATH" >fake-diff.sh
166 cat >> fake-diff.sh <<\EOF
167 cat $2 >> crlfed.txt
169 chmod a+x fake-diff.sh
171 keep_only_cr () {
172 tr -dc '\015'
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' '
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
189 test_done