]> git.ipfire.org Git - thirdparty/git.git/blob - t/t4020-diff-external.sh
The seventh batch of topics graduated to 'master'
[thirdparty/git.git] / t / t4020-diff-external.sh
1 #!/bin/sh
2
3 test_description='external diff interface test'
4
5 . ./test-lib.sh
6
7 test_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
23 test_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
37 test_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
44 test_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
51 test_expect_success 'diff attribute' '
52
53 git config diff.parrot.command echo &&
54
55 echo >.gitattributes "file diff=parrot" &&
56
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 }
66
67 '
68
69 test_expect_success 'diff attribute should apply only to diff' '
70
71 git log -p -1 HEAD |
72 grep "^diff --git a/file b/file"
73
74 '
75
76 test_expect_success 'diff attribute and --no-ext-diff' '
77
78 git diff --no-ext-diff |
79 grep "^diff --git a/file b/file"
80
81 '
82
83 test_expect_success 'diff attribute' '
84
85 git config --unset diff.parrot.command &&
86 git config diff.color.command echo &&
87
88 echo >.gitattributes "file diff=color" &&
89
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 }
99
100 '
101
102 test_expect_success 'diff attribute should apply only to diff' '
103
104 git log -p -1 HEAD |
105 grep "^diff --git a/file b/file"
106
107 '
108
109 test_expect_success 'diff attribute and --no-ext-diff' '
110
111 git diff --no-ext-diff |
112 grep "^diff --git a/file b/file"
113
114 '
115
116 test_expect_success 'no diff with -diff' '
117 echo >.gitattributes "file -diff" &&
118 git diff | grep Binary
119 '
120
121 echo NULZbetweenZwords | perl -pe 'y/Z/\000/' > file
122
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 '
128
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 '
136
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 '
145
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
151
152 keep_only_cr () {
153 tr -dc '\015'
154 }
155
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 '
161
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 '
169
170 test_done