]> git.ipfire.org Git - thirdparty/git.git/blob - t/t4035-diff-quiet.sh
The third batch
[thirdparty/git.git] / t / t4035-diff-quiet.sh
1 #!/bin/sh
2
3 test_description='Return value of diffs'
4
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 test_expect_success 'setup' '
9 echo 1 >a &&
10 git add . &&
11 git commit -m first &&
12 echo 2 >b &&
13 git add . &&
14 git commit -a -m second &&
15 mkdir -p test-outside/repo && (
16 cd test-outside/repo &&
17 git init &&
18 echo "1 1" >a &&
19 git add . &&
20 git commit -m 1
21 ) &&
22 mkdir -p test-outside/non/git && (
23 cd test-outside/non/git &&
24 echo "1 1" >a &&
25 echo "1 1" >matching-file &&
26 echo "1 1 " >trailing-space &&
27 echo "1 1" >extra-space &&
28 echo "2" >never-match
29 )
30 '
31
32 test_expect_success 'git diff-tree HEAD^ HEAD' '
33 test_expect_code 1 git diff-tree --quiet HEAD^ HEAD >cnt &&
34 test_line_count = 0 cnt
35 '
36 test_expect_success 'git diff-tree HEAD^ HEAD -- a' '
37 test_expect_code 0 git diff-tree --quiet HEAD^ HEAD -- a >cnt &&
38 test_line_count = 0 cnt
39 '
40 test_expect_success 'git diff-tree HEAD^ HEAD -- b' '
41 test_expect_code 1 git diff-tree --quiet HEAD^ HEAD -- b >cnt &&
42 test_line_count = 0 cnt
43 '
44 # this diff outputs one line: sha1 of the given head
45 test_expect_success 'echo HEAD | git diff-tree --stdin' '
46 echo $(git rev-parse HEAD) |
47 test_expect_code 1 git diff-tree --quiet --stdin >cnt &&
48 test_line_count = 1 cnt
49 '
50 test_expect_success 'git diff-tree HEAD HEAD' '
51 test_expect_code 0 git diff-tree --quiet HEAD HEAD >cnt &&
52 test_line_count = 0 cnt
53 '
54 test_expect_success 'git diff-files' '
55 test_expect_code 0 git diff-files --quiet >cnt &&
56 test_line_count = 0 cnt
57 '
58 test_expect_success 'git diff-index --cached HEAD' '
59 test_expect_code 0 git diff-index --quiet --cached HEAD >cnt &&
60 test_line_count = 0 cnt
61 '
62 test_expect_success 'git diff-index --cached HEAD^' '
63 test_expect_code 1 git diff-index --quiet --cached HEAD^ >cnt &&
64 test_line_count = 0 cnt
65 '
66 test_expect_success 'git diff-index --cached HEAD^' '
67 echo text >>b &&
68 echo 3 >c &&
69 git add . &&
70 test_expect_code 1 git diff-index --quiet --cached HEAD^ >cnt &&
71 test_line_count = 0 cnt
72 '
73 test_expect_success 'git diff-tree -Stext HEAD^ HEAD -- b' '
74 git commit -m "text in b" &&
75 test_expect_code 1 git diff-tree --quiet -Stext HEAD^ HEAD -- b >cnt &&
76 test_line_count = 0 cnt
77 '
78 test_expect_success 'git diff-tree -Snot-found HEAD^ HEAD -- b' '
79 test_expect_code 0 git diff-tree --quiet -Snot-found HEAD^ HEAD -- b >cnt &&
80 test_line_count = 0 cnt
81 '
82 test_expect_success 'git diff-files' '
83 echo 3 >>c &&
84 test_expect_code 1 git diff-files --quiet >cnt &&
85 test_line_count = 0 cnt
86 '
87
88 test_expect_success 'git diff-index --cached HEAD' '
89 git update-index c &&
90 test_expect_code 1 git diff-index --quiet --cached HEAD >cnt &&
91 test_line_count = 0 cnt
92 '
93
94 test_expect_success 'git diff, one file outside repo' '
95 (
96 cd test-outside/repo &&
97 test_expect_code 0 git diff --quiet a ../non/git/matching-file &&
98 test_expect_code 1 git diff --quiet a ../non/git/extra-space
99 )
100 '
101
102 test_expect_success 'git diff, both files outside repo' '
103 (
104 GIT_CEILING_DIRECTORIES="$TRASH_DIRECTORY/test-outside" &&
105 export GIT_CEILING_DIRECTORIES &&
106 cd test-outside/non/git &&
107 test_expect_code 0 git diff --quiet a matching-file &&
108 test_expect_code 1 git diff --quiet a extra-space
109 )
110 '
111
112 test_expect_success 'git diff --ignore-space-at-eol, one file outside repo' '
113 (
114 cd test-outside/repo &&
115 test_expect_code 0 git diff --quiet --ignore-space-at-eol a ../non/git/trailing-space &&
116 test_expect_code 1 git diff --quiet --ignore-space-at-eol a ../non/git/extra-space
117 )
118 '
119
120 test_expect_success 'git diff --ignore-space-at-eol, both files outside repo' '
121 (
122 GIT_CEILING_DIRECTORIES="$TRASH_DIRECTORY/test-outside" &&
123 export GIT_CEILING_DIRECTORIES &&
124 cd test-outside/non/git &&
125 test_expect_code 0 git diff --quiet --ignore-space-at-eol a trailing-space &&
126 test_expect_code 1 git diff --quiet --ignore-space-at-eol a extra-space
127 )
128 '
129
130 test_expect_success 'git diff --ignore-all-space, one file outside repo' '
131 (
132 cd test-outside/repo &&
133 test_expect_code 0 git diff --quiet --ignore-all-space a ../non/git/trailing-space &&
134 test_expect_code 0 git diff --quiet --ignore-all-space a ../non/git/extra-space &&
135 test_expect_code 1 git diff --quiet --ignore-all-space a ../non/git/never-match
136 )
137 '
138
139 test_expect_success 'git diff --ignore-all-space, both files outside repo' '
140 (
141 GIT_CEILING_DIRECTORIES="$TRASH_DIRECTORY/test-outside" &&
142 export GIT_CEILING_DIRECTORIES &&
143 cd test-outside/non/git &&
144 test_expect_code 0 git diff --quiet --ignore-all-space a trailing-space &&
145 test_expect_code 0 git diff --quiet --ignore-all-space a extra-space &&
146 test_expect_code 1 git diff --quiet --ignore-all-space a never-match
147 )
148 '
149
150 test_expect_success 'git diff --quiet ignores stat-change only entries' '
151 test-tool chmtime +10 a &&
152 echo modified >>b &&
153 test_expect_code 1 git diff --quiet
154 '
155
156 test_expect_success 'git diff --quiet on a path that need conversion' '
157 echo "crlf.txt text=auto" >.gitattributes &&
158 printf "Hello\r\nWorld\r\n" >crlf.txt &&
159 git add .gitattributes crlf.txt &&
160
161 printf "Hello\r\nWorld\n" >crlf.txt &&
162 git diff --quiet crlf.txt
163 '
164
165 test_done