summaryrefslogtreecommitdiff
path: root/t/t4020-diff-external.sh
blob: 0720001281db6aeb5a3b6bb46cd6914ad7d78d33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/sh
 
test_description='external diff interface test'
 
. ./test-lib.sh
 
_z40=0000000000000000000000000000000000000000
 
test_expect_success setup '
 
	test_tick &&
	echo initial >file &&
	git add file &&
	git commit -m initial &&
 
	test_tick &&
	echo second >file &&
	git add file &&
	git commit -m second &&
 
	test_tick &&
	echo third >file
'
 
test_expect_success 'GIT_EXTERNAL_DIFF environment' '
 
	GIT_EXTERNAL_DIFF=echo git diff | {
		read path oldfile oldhex oldmode newfile newhex newmode &&
		test "z$path" = zfile &&
		test "z$oldmode" = z100644 &&
		test "z$newhex" = "z$_z40" &&
		test "z$newmode" = z100644 &&
		oh=$(git rev-parse --verify HEAD:file) &&
		test "z$oh" = "z$oldhex"
	}
 
'
 
test_expect_success 'GIT_EXTERNAL_DIFF environment should apply only to diff' '
 
	GIT_EXTERNAL_DIFF=echo git log -p -1 HEAD |
	grep "^diff --git a/file b/file"
 
'
 
test_expect_success 'GIT_EXTERNAL_DIFF environment and --no-ext-diff' '
 
	GIT_EXTERNAL_DIFF=echo git diff --no-ext-diff |
	grep "^diff --git a/file b/file"
 
'
 
test_expect_success 'diff attribute' '
 
	git config diff.parrot.command echo &&
 
	echo >.gitattributes "file diff=parrot" &&
 
	git diff | {
		read path oldfile oldhex oldmode newfile newhex newmode &&
		test "z$path" = zfile &&
		test "z$oldmode" = z100644 &&
		test "z$newhex" = "z$_z40" &&
		test "z$newmode" = z100644 &&
		oh=$(git rev-parse --verify HEAD:file) &&
		test "z$oh" = "z$oldhex"
	}
 
'
 
test_expect_success 'diff attribute should apply only to diff' '
 
	git log -p -1 HEAD |
	grep "^diff --git a/file b/file"
 
'
 
test_expect_success 'diff attribute and --no-ext-diff' '
 
	git diff --no-ext-diff |
	grep "^diff --git a/file b/file"
 
'
 
test_expect_success 'diff attribute' '
 
	git config --unset diff.parrot.command &&
	git config diff.color.command echo &&
 
	echo >.gitattributes "file diff=color" &&
 
	git diff | {
		read path oldfile oldhex oldmode newfile newhex newmode &&
		test "z$path" = zfile &&
		test "z$oldmode" = z100644 &&
		test "z$newhex" = "z$_z40" &&
		test "z$newmode" = z100644 &&
		oh=$(git rev-parse --verify HEAD:file) &&
		test "z$oh" = "z$oldhex"
	}
 
'
 
test_expect_success 'diff attribute should apply only to diff' '
 
	git log -p -1 HEAD |
	grep "^diff --git a/file b/file"
 
'
 
test_expect_success 'diff attribute and --no-ext-diff' '
 
	git diff --no-ext-diff |
	grep "^diff --git a/file b/file"
 
'
 
test_expect_success 'no diff with -diff' '
	echo >.gitattributes "file -diff" &&
	git diff | grep Binary
'
 
echo NULZbetweenZwords | perl -pe 'y/Z/\000/' > file
 
test_expect_success 'force diff with "diff"' '
	echo >.gitattributes "file diff" &&
	git diff >actual &&
	test_cmp "$TEST_DIRECTORY"/t4020/diff.NUL actual
'
 
test_expect_success 'GIT_EXTERNAL_DIFF with more than one changed files' '
	echo anotherfile > file2 &&
	git add file2 &&
	git commit -m "added 2nd file" &&
	echo modified >file2 &&
	GIT_EXTERNAL_DIFF=echo git diff
'
 
echo "#!$SHELL_PATH" >fake-diff.sh
cat >> fake-diff.sh <<\EOF
cat $2 >> crlfed.txt
EOF
chmod a+x fake-diff.sh
 
keep_only_cr () {
	tr -dc '\015'
}
 
test_expect_success 'external diff with autocrlf = true' '
	git config core.autocrlf true &&
	GIT_EXTERNAL_DIFF=./fake-diff.sh git diff &&
	test $(wc -l < crlfed.txt) = $(cat crlfed.txt | keep_only_cr | wc -c)
'
 
test_expect_success 'diff --cached' '
	git add file &&
	git update-index --assume-unchanged file &&
	echo second >file &&
	git diff --cached >actual &&
	test_cmp ../t4020/diff.NUL actual
'
 
test_done