1#!/bin/sh
2
3test_description='external diff interface test'
4
5. ./test-lib.sh
6
7_z40=0000000000000000000000000000000000000000
8
9test_expect_success setup '
10
11 test_tick &&
12 echo initial >file &&
13 git add file &&
14 git commit -m initial &&
15
16 test_tick &&
17 echo second >file &&
18 git add file &&
19 git commit -m second &&
20
21 test_tick &&
22 echo third >file
23'
24
25test_expect_success 'GIT_EXTERNAL_DIFF environment' '
26
27 GIT_EXTERNAL_DIFF=echo git diff | {
28 read path oldfile oldhex oldmode newfile newhex newmode &&
29 test "z$path" = zfile &&
30 test "z$oldmode" = z100644 &&
31 test "z$newhex" = "z$_z40" &&
32 test "z$newmode" = z100644 &&
33 oh=$(git rev-parse --verify HEAD:file) &&
34 test "z$oh" = "z$oldhex"
35 }
36
37'
38
39test_expect_success 'GIT_EXTERNAL_DIFF environment should apply only to diff' '
40
41 GIT_EXTERNAL_DIFF=echo git log -p -1 HEAD |
42 grep "^diff --git a/file b/file"
43
44'
45
46test_expect_success 'GIT_EXTERNAL_DIFF environment and --no-ext-diff' '
47
48 GIT_EXTERNAL_DIFF=echo git diff --no-ext-diff |
49 grep "^diff --git a/file b/file"
50
51'
52
53test_expect_success 'diff attribute' '
54
55 git config diff.parrot.command echo &&
56
57 echo >.gitattributes "file diff=parrot" &&
58
59 git diff | {
60 read path oldfile oldhex oldmode newfile newhex newmode &&
61 test "z$path" = zfile &&
62 test "z$oldmode" = z100644 &&
63 test "z$newhex" = "z$_z40" &&
64 test "z$newmode" = z100644 &&
65 oh=$(git rev-parse --verify HEAD:file) &&
66 test "z$oh" = "z$oldhex"
67 }
68
69'
70
71test_expect_success 'diff attribute should apply only to diff' '
72
73 git log -p -1 HEAD |
74 grep "^diff --git a/file b/file"
75
76'
77
78test_expect_success 'diff attribute and --no-ext-diff' '
79
80 git diff --no-ext-diff |
81 grep "^diff --git a/file b/file"
82
83'
84
85test_expect_success 'diff attribute' '
86
87 git config --unset diff.parrot.command &&
88 git config diff.color.command echo &&
89
90 echo >.gitattributes "file diff=color" &&
91
92 git diff | {
93 read path oldfile oldhex oldmode newfile newhex newmode &&
94 test "z$path" = zfile &&
95 test "z$oldmode" = z100644 &&
96 test "z$newhex" = "z$_z40" &&
97 test "z$newmode" = z100644 &&
98 oh=$(git rev-parse --verify HEAD:file) &&
99 test "z$oh" = "z$oldhex"
100 }
101
102'
103
104test_expect_success 'diff attribute should apply only to diff' '
105
106 git log -p -1 HEAD |
107 grep "^diff --git a/file b/file"
108
109'
110
111test_expect_success 'diff attribute and --no-ext-diff' '
112
113 git diff --no-ext-diff |
114 grep "^diff --git a/file b/file"
115
116'
117
118test_expect_success 'no diff with -diff' '
119 echo >.gitattributes "file -diff" &&
120 git diff | grep Binary
121'
122
123echo NULZbetweenZwords | perl -pe 'y/Z/\000/' > file
124
125test_expect_success 'force diff with "diff"' '
126 echo >.gitattributes "file diff" &&
127 git diff >actual &&
128 test_cmp ../t4020/diff.NUL actual
129'
130
131test_done