blob: 0352bf81a90a38adf14fb7a980c98600e1f650b2 [file] [log] [blame]
Alex Riesen0c66d6b2007-03-14 23:57:23 +01001#!/bin/sh
2
3test_description='Return value of diffs'
4
5. ./test-lib.sh
6
7test_expect_success 'setup' '
8 echo 1 >a &&
9 git add . &&
10 git commit -m first &&
11 echo 2 >b &&
12 git add . &&
Tim Henigan304970d2012-06-21 14:09:51 -040013 git commit -a -m second &&
14 mkdir -p test-outside/repo && (
15 cd test-outside/repo &&
16 git init &&
17 echo "1 1" >a &&
18 git add . &&
19 git commit -m 1
20 ) &&
21 mkdir -p test-outside/non/git && (
22 cd test-outside/non/git &&
23 echo "1 1" >a &&
24 echo "1 1" >matching-file &&
25 echo "1 1 " >trailing-space &&
26 echo "1 1" >extra-space &&
27 echo "2" >never-match
28 )
Alex Riesen0c66d6b2007-03-14 23:57:23 +010029'
30
31test_expect_success 'git diff-tree HEAD^ HEAD' '
Jeff Kingc21fc9d2015-03-20 06:11:46 -040032 test_expect_code 1 git diff-tree --quiet HEAD^ HEAD >cnt &&
33 test_line_count = 0 cnt
Alex Riesen0c66d6b2007-03-14 23:57:23 +010034'
35test_expect_success 'git diff-tree HEAD^ HEAD -- a' '
Jeff Kingc21fc9d2015-03-20 06:11:46 -040036 test_expect_code 0 git diff-tree --quiet HEAD^ HEAD -- a >cnt &&
37 test_line_count = 0 cnt
Alex Riesen0c66d6b2007-03-14 23:57:23 +010038'
39test_expect_success 'git diff-tree HEAD^ HEAD -- b' '
Jeff Kingc21fc9d2015-03-20 06:11:46 -040040 test_expect_code 1 git diff-tree --quiet HEAD^ HEAD -- b >cnt &&
41 test_line_count = 0 cnt
Alex Riesen0c66d6b2007-03-14 23:57:23 +010042'
43# this diff outputs one line: sha1 of the given head
44test_expect_success 'echo HEAD | git diff-tree --stdin' '
Jeff Kingc21fc9d2015-03-20 06:11:46 -040045 echo $(git rev-parse HEAD) |
46 test_expect_code 1 git diff-tree --quiet --stdin >cnt &&
47 test_line_count = 1 cnt
Alex Riesen0c66d6b2007-03-14 23:57:23 +010048'
49test_expect_success 'git diff-tree HEAD HEAD' '
Jeff Kingc21fc9d2015-03-20 06:11:46 -040050 test_expect_code 0 git diff-tree --quiet HEAD HEAD >cnt &&
51 test_line_count = 0 cnt
Alex Riesen0c66d6b2007-03-14 23:57:23 +010052'
53test_expect_success 'git diff-files' '
Jeff Kingc21fc9d2015-03-20 06:11:46 -040054 test_expect_code 0 git diff-files --quiet >cnt &&
55 test_line_count = 0 cnt
Alex Riesen0c66d6b2007-03-14 23:57:23 +010056'
57test_expect_success 'git diff-index --cached HEAD' '
Jeff Kingc21fc9d2015-03-20 06:11:46 -040058 test_expect_code 0 git diff-index --quiet --cached HEAD >cnt &&
59 test_line_count = 0 cnt
Alex Riesen0c66d6b2007-03-14 23:57:23 +010060'
61test_expect_success 'git diff-index --cached HEAD^' '
Jeff Kingc21fc9d2015-03-20 06:11:46 -040062 test_expect_code 1 git diff-index --quiet --cached HEAD^ >cnt &&
63 test_line_count = 0 cnt
Alex Riesen0c66d6b2007-03-14 23:57:23 +010064'
65test_expect_success 'git diff-index --cached HEAD^' '
66 echo text >>b &&
67 echo 3 >c &&
Jeff Kingc21fc9d2015-03-20 06:11:46 -040068 git add . &&
69 test_expect_code 1 git diff-index --quiet --cached HEAD^ >cnt &&
70 test_line_count = 0 cnt
Alex Riesen0c66d6b2007-03-14 23:57:23 +010071'
72test_expect_success 'git diff-tree -Stext HEAD^ HEAD -- b' '
Jeff Kingc21fc9d2015-03-20 06:11:46 -040073 git commit -m "text in b" &&
74 test_expect_code 1 git diff-tree --quiet -Stext HEAD^ HEAD -- b >cnt &&
75 test_line_count = 0 cnt
Alex Riesen0c66d6b2007-03-14 23:57:23 +010076'
77test_expect_success 'git diff-tree -Snot-found HEAD^ HEAD -- b' '
Jeff Kingc21fc9d2015-03-20 06:11:46 -040078 test_expect_code 0 git diff-tree --quiet -Snot-found HEAD^ HEAD -- b >cnt &&
79 test_line_count = 0 cnt
Alex Riesen0c66d6b2007-03-14 23:57:23 +010080'
81test_expect_success 'git diff-files' '
Jeff Kingc21fc9d2015-03-20 06:11:46 -040082 echo 3 >>c &&
83 test_expect_code 1 git diff-files --quiet >cnt &&
84 test_line_count = 0 cnt
Alex Riesen0c66d6b2007-03-14 23:57:23 +010085'
Jeff Kingc21fc9d2015-03-20 06:11:46 -040086
Alex Riesen0c66d6b2007-03-14 23:57:23 +010087test_expect_success 'git diff-index --cached HEAD' '
Jeff Kingc21fc9d2015-03-20 06:11:46 -040088 git update-index c &&
89 test_expect_code 1 git diff-index --quiet --cached HEAD >cnt &&
90 test_line_count = 0 cnt
Alex Riesen0c66d6b2007-03-14 23:57:23 +010091'
92
Tim Henigan304970d2012-06-21 14:09:51 -040093test_expect_success 'git diff, one file outside repo' '
94 (
95 cd test-outside/repo &&
96 test_expect_code 0 git diff --quiet a ../non/git/matching-file &&
97 test_expect_code 1 git diff --quiet a ../non/git/extra-space
98 )
99'
100
101test_expect_success 'git diff, both files outside repo' '
102 (
103 GIT_CEILING_DIRECTORIES="$TRASH_DIRECTORY/test-outside" &&
104 export GIT_CEILING_DIRECTORIES &&
105 cd test-outside/non/git &&
106 test_expect_code 0 git diff --quiet a matching-file &&
107 test_expect_code 1 git diff --quiet a extra-space
108 )
109'
110
111test_expect_success 'git diff --ignore-space-at-eol, one file outside repo' '
112 (
113 cd test-outside/repo &&
114 test_expect_code 0 git diff --quiet --ignore-space-at-eol a ../non/git/trailing-space &&
115 test_expect_code 1 git diff --quiet --ignore-space-at-eol a ../non/git/extra-space
116 )
117'
118
119test_expect_success 'git diff --ignore-space-at-eol, both files outside repo' '
120 (
121 GIT_CEILING_DIRECTORIES="$TRASH_DIRECTORY/test-outside" &&
122 export GIT_CEILING_DIRECTORIES &&
123 cd test-outside/non/git &&
124 test_expect_code 0 git diff --quiet --ignore-space-at-eol a trailing-space &&
125 test_expect_code 1 git diff --quiet --ignore-space-at-eol a extra-space
126 )
127'
128
129test_expect_success 'git diff --ignore-all-space, one file outside repo' '
130 (
131 cd test-outside/repo &&
132 test_expect_code 0 git diff --quiet --ignore-all-space a ../non/git/trailing-space &&
133 test_expect_code 0 git diff --quiet --ignore-all-space a ../non/git/extra-space &&
134 test_expect_code 1 git diff --quiet --ignore-all-space a ../non/git/never-match
135 )
136'
137
138test_expect_success 'git diff --ignore-all-space, both files outside repo' '
139 (
140 GIT_CEILING_DIRECTORIES="$TRASH_DIRECTORY/test-outside" &&
141 export GIT_CEILING_DIRECTORIES &&
142 cd test-outside/non/git &&
143 test_expect_code 0 git diff --quiet --ignore-all-space a trailing-space &&
144 test_expect_code 0 git diff --quiet --ignore-all-space a extra-space &&
145 test_expect_code 1 git diff --quiet --ignore-all-space a never-match
146 )
147'
148
Nguyễn Thái Ngọc Duyf34b2052014-01-25 13:46:50 +0700149test_expect_success 'git diff --quiet ignores stat-change only entries' '
Nguyễn Thái Ngọc Duy0e496492018-03-24 08:44:31 +0100150 test-tool chmtime +10 a &&
Nguyễn Thái Ngọc Duyf34b2052014-01-25 13:46:50 +0700151 echo modified >>b &&
152 test_expect_code 1 git diff --quiet
153'
154
Junio C Hamano12426e12017-03-01 18:04:44 +0100155test_expect_success 'git diff --quiet on a path that need conversion' '
156 echo "crlf.txt text=auto" >.gitattributes &&
157 printf "Hello\r\nWorld\r\n" >crlf.txt &&
158 git add .gitattributes crlf.txt &&
159
160 printf "Hello\r\nWorld\n" >crlf.txt &&
161 git diff --quiet crlf.txt
162'
163
Alex Riesen0c66d6b2007-03-14 23:57:23 +0100164test_done