]> git.ipfire.org Git - thirdparty/git.git/blob - t/t4020-diff-external.sh
diff --cached: do not borrow from a work tree when a path is marked as assume-unchanged
[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 _z40=0000000000000000000000000000000000000000
8
9 test_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
25 test_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
39 test_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
46 test_expect_success 'diff attribute' '
47
48 git config diff.parrot.command echo &&
49
50 echo >.gitattributes "file diff=parrot" &&
51
52 git diff | {
53 read path oldfile oldhex oldmode newfile newhex newmode &&
54 test "z$path" = zfile &&
55 test "z$oldmode" = z100644 &&
56 test "z$newhex" = "z$_z40" &&
57 test "z$newmode" = z100644 &&
58 oh=$(git rev-parse --verify HEAD:file) &&
59 test "z$oh" = "z$oldhex"
60 }
61
62 '
63
64 test_expect_success 'diff attribute should apply only to diff' '
65
66 git log -p -1 HEAD |
67 grep "^diff --git a/file b/file"
68
69 '
70
71 test_expect_success 'diff attribute' '
72
73 git config --unset diff.parrot.command &&
74 git config diff.color.command echo &&
75
76 echo >.gitattributes "file diff=color" &&
77
78 git diff | {
79 read path oldfile oldhex oldmode newfile newhex newmode &&
80 test "z$path" = zfile &&
81 test "z$oldmode" = z100644 &&
82 test "z$newhex" = "z$_z40" &&
83 test "z$newmode" = z100644 &&
84 oh=$(git rev-parse --verify HEAD:file) &&
85 test "z$oh" = "z$oldhex"
86 }
87
88 '
89
90 test_expect_success 'diff attribute should apply only to diff' '
91
92 git log -p -1 HEAD |
93 grep "^diff --git a/file b/file"
94
95 '
96
97 test_expect_success 'no diff with -diff' '
98 echo >.gitattributes "file -diff" &&
99 git diff | grep Binary
100 '
101
102 echo NULZbetweenZwords | perl -pe 'y/Z/\000/' > file
103
104 test_expect_success 'force diff with "diff"' '
105 echo >.gitattributes "file diff" &&
106 git diff >actual &&
107 test_cmp ../t4020/diff.NUL actual
108 '
109
110 test_expect_success 'diff --cached' '
111 git add file &&
112 git update-index --assume-unchanged file &&
113 echo second >file &&
114 git diff --cached >actual &&
115 test_cmp ../t4020/diff.NUL actual
116 '
117
118 test_done