3 test_description
='diff --no-index'
5 TEST_PASSES_SANITIZE_LEAK
=true
8 test_expect_success
'setup' '
20 test_expect_success
'git diff --no-index --exit-code' '
21 git diff --no-index --exit-code a/1 non/git/a &&
22 test_expect_code 1 git diff --no-index --exit-code a/1 a/2
25 test_expect_success
'git diff --no-index directories' '
26 test_expect_code 1 git diff --no-index a b >cnt &&
27 test_line_count = 14 cnt
30 test_expect_success
'git diff --no-index relative path outside repo' '
33 test_expect_code 0 git diff --no-index a ../non/git/a &&
34 test_expect_code 0 git diff --no-index ../non/git/a ../non/git/b
38 test_expect_success
'git diff --no-index with broken index' '
41 echo broken >.git/index &&
42 git diff --no-index a ../non/git/a
46 test_expect_success
'git diff outside repo with broken index' '
49 git diff ../non/git/a ../non/git/b
53 test_expect_success
'git diff --no-index executed outside repo gives correct error message' '
55 GIT_CEILING_DIRECTORIES=$TRASH_DIRECTORY/non &&
56 export GIT_CEILING_DIRECTORIES &&
58 test_must_fail git diff --no-index a 2>actual.err &&
59 test_grep "usage: git diff --no-index" actual.err
63 test_expect_success
'diff D F and diff F D' '
67 echo non-repo >../non/git/a &&
69 echo sub-repo >sub/a &&
71 test_must_fail git diff --no-index sub/a ../non/git/a >expect &&
72 test_must_fail git diff --no-index sub/a ../non/git/ >actual &&
73 test_cmp expect actual &&
75 test_must_fail git diff --no-index a ../non/git/a >expect &&
76 test_must_fail git diff --no-index a ../non/git/ >actual &&
77 test_cmp expect actual &&
79 test_must_fail git diff --no-index ../non/git/a a >expect &&
80 test_must_fail git diff --no-index ../non/git a >actual &&
81 test_cmp expect actual
85 test_expect_success
'turning a file into a directory' '
91 printf "D\td/sub\nA\te/sub/file\n" >expect &&
92 test_must_fail git diff --no-index --name-status d e >actual &&
93 test_cmp expect actual
97 test_expect_success
'diff from repo subdir shows real paths (explicit)' '
98 echo "diff --git a/../../non/git/a b/../../non/git/b" >expect &&
101 diff --no-index ../../non/git/a ../../non/git/b >actual &&
102 head -n 1 <actual >actual.head &&
103 test_cmp expect actual.head
106 test_expect_success
'diff from repo subdir shows real paths (implicit)' '
107 echo "diff --git a/../../non/git/a b/../../non/git/b" >expect &&
110 diff ../../non/git/a ../../non/git/b >actual &&
111 head -n 1 <actual >actual.head &&
112 test_cmp expect actual.head
115 test_expect_success
'diff --no-index from repo subdir respects config (explicit)' '
116 echo "diff --git ../../non/git/a ../../non/git/b" >expect &&
117 test_config -C repo diff.noprefix true &&
120 diff --no-index ../../non/git/a ../../non/git/b >actual &&
121 head -n 1 <actual >actual.head &&
122 test_cmp expect actual.head
125 test_expect_success
'diff --no-index from repo subdir respects config (implicit)' '
126 echo "diff --git ../../non/git/a ../../non/git/b" >expect &&
127 test_config -C repo diff.noprefix true &&
130 diff ../../non/git/a ../../non/git/b >actual &&
131 head -n 1 <actual >actual.head &&
132 test_cmp expect actual.head
135 test_expect_success
'diff --no-index from repo subdir with absolute paths' '
136 cat <<-EOF >expect &&
137 1 1 $(pwd)/non/git/{a => b}
140 git -C repo/sub diff --numstat \
141 "$(pwd)/non/git/a" "$(pwd)/non/git/b" >actual &&
142 test_cmp expect actual
145 test_expect_success
'diff --no-index allows external diff' '
147 env GIT_EXTERNAL_DIFF="echo external ;:" \
148 git diff --no-index non/git/a non/git/b >actual &&
149 echo external >expect &&
150 test_cmp expect actual
153 test_expect_success
'diff --no-index normalizes mode: no changes' '
156 git diff --no-index x y >out &&
157 test_must_be_empty out
160 test_expect_success POSIXPERM
'diff --no-index normalizes mode: chmod +x' '
162 cat >expected <<-\EOF &&
167 test_expect_code 1 git diff --no-index x y >actual &&
168 test_cmp expected actual
171 test_expect_success POSIXPERM
'diff --no-index normalizes: mode not like git mode' '
174 cat >expected <<-\EOF &&
179 test_expect_code 1 git diff --no-index x y >actual &&
180 test_cmp expected actual
183 test_expect_success POSIXPERM
,SYMLINKS
'diff --no-index normalizes: mode not like git mode (symlink)' '
185 X_OID=$(git hash-object --stdin <x) &&
186 Z_OID=$(printf y | git hash-object --stdin) &&
187 cat >expected <<-EOF &&
189 deleted file mode 100644
190 index $X_OID..$ZERO_OID
197 index $ZERO_OID..$Z_OID
202 \ No newline at end of file
204 test_expect_code 1 git -c core.abbrev=no diff --no-index x z >actual &&
205 test_cmp expected actual
208 test_expect_success
"diff --no-index treats '-' as stdin" '
209 cat >expect <<-EOF &&
211 index $ZERO_OID..$(git hash-object --stdin <a/1) 100644
219 test_write_lines x | test_expect_code 1 \
220 git -c core.abbrev=no diff --no-index -- - a/1 >actual &&
221 test_cmp expect actual &&
223 test_write_lines 1 | git diff --no-index -- a/1 - >actual &&
224 test_must_be_empty actual
227 test_expect_success
"diff --no-index -R treats '-' as stdin" '
228 cat >expect <<-EOF &&
230 index $(git hash-object --stdin <a/1)..$ZERO_OID 100644
238 test_write_lines x | test_expect_code 1 \
239 git -c core.abbrev=no diff --no-index -R -- - a/1 >actual &&
240 test_cmp expect actual &&
242 test_write_lines 1 | git diff --no-index -R -- a/1 - >actual &&
243 test_must_be_empty actual
246 test_expect_success
'diff --no-index refuses to diff stdin and a directory' '
247 test_must_fail git diff --no-index -- - a </dev/null 2>err &&
248 grep "fatal: cannot compare stdin to a directory" err
251 test_expect_success PIPE
'diff --no-index refuses to diff a named pipe and a directory' '
252 test_when_finished "rm -f pipe" &&
254 test_must_fail git diff --no-index -- pipe a 2>err &&
255 grep "fatal: cannot compare a named pipe to a directory" err
258 test_expect_success PIPE
,SYMLINKS
'diff --no-index reads from pipes' '
259 test_when_finished "rm -f old new new-link" &&
262 ln -s new new-link &&
264 (test_write_lines a b c >old) &
266 test_when_finished "kill $! || :" &&
268 (test_write_lines a x c >new) &
270 test_when_finished "kill $! || :" &&
272 cat >expect <<-EOF &&
273 diff --git a/old b/new-link
283 test_expect_code 1 git diff --no-index old new-link >actual &&
284 test_cmp expect actual