git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
e49f773515455266822a7ff1bfbe24af79525663 blob 8859 bytes (raw)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
 
#!/bin/sh

test_description='diff --no-index'

. ./test-lib.sh

test_expect_success 'setup' '
	mkdir a &&
	mkdir b &&
	echo 1 >a/1 &&
	echo 2 >a/2 &&
	git init repo &&
	echo 1 >repo/a &&
	mkdir -p non/git &&
	echo 1 >non/git/a &&
	echo 1 >non/git/b
'

test_expect_success 'git diff --no-index directories' '
	test_expect_code 1 git diff --no-index a b >cnt &&
	test_line_count = 14 cnt
'

test_expect_success 'git diff --no-index relative path outside repo' '
	(
		cd repo &&
		test_expect_code 0 git diff --no-index a ../non/git/a &&
		test_expect_code 0 git diff --no-index ../non/git/a ../non/git/b
	)
'

test_expect_success 'git diff --no-index with broken index' '
	(
		cd repo &&
		echo broken >.git/index &&
		git diff --no-index a ../non/git/a
	)
'

test_expect_success 'git diff outside repo with broken index' '
	(
		cd repo &&
		git diff ../non/git/a ../non/git/b
	)
'

test_expect_success 'git diff --no-index executed outside repo gives correct error message' '
	(
		GIT_CEILING_DIRECTORIES=$TRASH_DIRECTORY/non &&
		export GIT_CEILING_DIRECTORIES &&
		cd non/git &&
		test_must_fail git diff --no-index a 2>actual.err &&
		test_i18ngrep "usage: git diff --no-index" actual.err
	)
'

test_expect_success 'diff D F and diff F D' '
	(
		cd repo &&
		echo in-repo >a &&
		echo non-repo >../non/git/a &&
		mkdir sub &&
		echo sub-repo >sub/a &&

		test_must_fail git diff --no-index sub/a ../non/git/a >expect &&
		test_must_fail git diff --no-index sub/a ../non/git/ >actual &&
		test_cmp expect actual &&

		test_must_fail git diff --no-index a ../non/git/a >expect &&
		test_must_fail git diff --no-index a ../non/git/ >actual &&
		test_cmp expect actual &&

		test_must_fail git diff --no-index ../non/git/a a >expect &&
		test_must_fail git diff --no-index ../non/git a >actual &&
		test_cmp expect actual
	)
'

test_expect_success 'turning a file into a directory' '
	(
		cd non/git &&
		mkdir d e e/sub &&
		echo 1 >d/sub &&
		echo 2 >e/sub/file &&
		printf "D\td/sub\nA\te/sub/file\n" >expect &&
		test_must_fail git diff --no-index --name-status d e >actual &&
		test_cmp expect actual
	)
'

test_expect_success 'diff from repo subdir shows real paths (explicit)' '
	echo "diff --git a/../../non/git/a b/../../non/git/b" >expect &&
	test_expect_code 1 \
		git -C repo/sub \
		diff --no-index ../../non/git/a ../../non/git/b >actual &&
	head -n 1 <actual >actual.head &&
	test_cmp expect actual.head
'

test_expect_success 'diff from repo subdir shows real paths (implicit)' '
	echo "diff --git a/../../non/git/a b/../../non/git/b" >expect &&
	test_expect_code 1 \
		git -C repo/sub \
		diff ../../non/git/a ../../non/git/b >actual &&
	head -n 1 <actual >actual.head &&
	test_cmp expect actual.head
'

test_expect_success 'diff --no-index from repo subdir respects config (explicit)' '
	echo "diff --git ../../non/git/a ../../non/git/b" >expect &&
	test_config -C repo diff.noprefix true &&
	test_expect_code 1 \
		git -C repo/sub \
		diff --no-index ../../non/git/a ../../non/git/b >actual &&
	head -n 1 <actual >actual.head &&
	test_cmp expect actual.head
'

test_expect_success 'diff --no-index from repo subdir respects config (implicit)' '
	echo "diff --git ../../non/git/a ../../non/git/b" >expect &&
	test_config -C repo diff.noprefix true &&
	test_expect_code 1 \
		git -C repo/sub \
		diff ../../non/git/a ../../non/git/b >actual &&
	head -n 1 <actual >actual.head &&
	test_cmp expect actual.head
'

test_expect_success 'diff --no-index from repo subdir with absolute paths' '
	cat <<-EOF >expect &&
	1	1	$(pwd)/non/git/{a => b}
	EOF
	test_expect_code 1 \
		git -C repo/sub diff --numstat \
		"$(pwd)/non/git/a" "$(pwd)/non/git/b" >actual &&
	test_cmp expect actual
'

test_expect_success 'diff --no-index allows external diff' '
	test_expect_code 1 \
		env GIT_EXTERNAL_DIFF="echo external ;:" \
		git diff --no-index non/git/a non/git/b >actual &&
	echo external >expect &&
	test_cmp expect actual
'

test_expect_success 'diff --no-index can diff piped subshells' '
	echo 1 >non/git/c &&
	test_expect_code 0 git diff --no-index non/git/b <(cat non/git/c) &&
	test_expect_code 0 git diff --no-index <(cat non/git/b) non/git/c &&
	test_expect_code 0 git diff --no-index <(cat non/git/b) <(cat non/git/c) &&
	test_expect_code 0 cat non/git/b | git diff --no-index - non/git/c &&
	test_expect_code 0 cat non/git/c | git diff --no-index non/git/b - &&
	test_expect_code 0 cat non/git/b | git diff --no-index - <(cat non/git/c) &&
	test_expect_code 0 cat non/git/c | git diff --no-index <(cat non/git/b) -
'

test_expect_success 'diff --no-index finds diff in piped subshells' '
	(
		set -- <(cat /dev/null) <(cat /dev/null)
		cat <<-EOF >expect
			diff --git a$1 b$2
			--- a$1
			+++ b$2
			@@ -1 +1 @@
			-1
			+2
		EOF
	) &&
	test_expect_code 1 \
		git diff --no-index <(cat non/git/b) <(sed s/1/2/ non/git/c) >actual &&
	test_cmp expect actual
'

test_expect_success 'diff --no-index with stat and numstat' '
	(
		set -- <(cat /dev/null) <(cat /dev/null)
		min=$((${#1} < ${#2} ? ${#1} : ${#2}))
		for ((i=0; i<min; i++)); do [ "${1:i:1}" = "${2:i:1}" ] || break; done
		base=${1:0:i-1}
		cat <<-EOF >expect1
			 $base{${1#$base} => ${2#$base}} | 2 +-
			 1 file changed, 1 insertion(+), 1 deletion(-)
		EOF
		cat <<-EOF >expect2
			1	1	$base{${1#$base} => ${2#$base}}
		EOF
	) &&
	test_expect_code 1 \
		git diff --no-index --stat <(cat non/git/a) <(sed s/1/2/ non/git/b) >actual &&
	test_cmp expect1 actual &&
	test_expect_code 1 \
		git diff --no-index --numstat <(cat non/git/a) <(sed s/1/2/ non/git/b) >actual &&
	test_cmp expect2 actual
'

test_expect_success PIPE 'diff --no-index on filesystem pipes' '
	(
		cd non/git &&
		mkdir f g &&
		mkfifo f/1 g/1 &&
		test_expect_code 128 git diff --no-index f g &&
		test_expect_code 128 git diff --no-index ../../a f &&
		test_expect_code 128 git diff --no-index g ../../a &&
		test_expect_code 128 git diff --no-index f/1 g/1 &&
		test_expect_code 128 git diff --no-index f/1 ../../a/1 &&
		test_expect_code 128 git diff --no-index ../../a/1 g/1
	)
'

test_expect_success PIPE 'diff --no-index reads symlinks to named pipes as symlinks' '
	(
		cd non/git &&
		mkdir h i &&
		ln -s ../f/1 h/1 &&
		ln -s ../g/1 i/1 &&
		test_expect_code 1 git diff --no-index h i >actual &&
		cat <<-EOF >expect &&
			diff --git a/h/1 b/i/1
			index d0b5850..d8b9c34 120000
			--- a/h/1
			+++ b/i/1
			@@ -1 +1 @@
			-../f/1
			\ No newline at end of file
			+../g/1
			\ No newline at end of file
		EOF
		test_cmp expect actual &&
		test_expect_code 1 git diff --no-index ../../a h >actual &&
		cat <<-EOF >expect &&
			diff --git a/../../a/1 b/../../a/1
			deleted file mode 100644
			index d00491f..0000000
			--- a/../../a/1
			+++ /dev/null
			@@ -1 +0,0 @@
			-1
			diff --git a/h/1 b/h/1
			new file mode 120000
			index 0000000..d0b5850
			--- /dev/null
			+++ b/h/1
			@@ -0,0 +1 @@
			+../f/1
			\ No newline at end of file
			diff --git a/../../a/2 b/../../a/2
			deleted file mode 100644
			index 0cfbf08..0000000
			--- a/../../a/2
			+++ /dev/null
			@@ -1 +0,0 @@
			-2
		EOF
		test_cmp expect actual &&
		test_expect_code 1 git diff --no-index i ../../a >actual &&
		cat <<-EOF >expect &&
			diff --git a/i/1 b/i/1
			deleted file mode 120000
			index d8b9c34..0000000
			--- a/i/1
			+++ /dev/null
			@@ -1 +0,0 @@
			-../g/1
			\ No newline at end of file
			diff --git a/../../a/1 b/../../a/1
			new file mode 100644
			index 0000000..d00491f
			--- /dev/null
			+++ b/../../a/1
			@@ -0,0 +1 @@
			+1
			diff --git a/../../a/2 b/../../a/2
			new file mode 100644
			index 0000000..0cfbf08
			--- /dev/null
			+++ b/../../a/2
			@@ -0,0 +1 @@
			+2
		EOF
		test_cmp expect actual &&
		test_expect_code 1 git diff --no-index h/1 i/1 >actual &&
		cat <<-EOF >expect &&
			diff --git a/h/1 b/i/1
			index d0b5850..d8b9c34 120000
			--- a/h/1
			+++ b/i/1
			@@ -1 +1 @@
			-../f/1
			\ No newline at end of file
			+../g/1
			\ No newline at end of file
		EOF
		test_cmp expect actual &&
		test_expect_code 1 git diff --no-index h/1 ../../a/1 >actual &&
		cat <<-EOF >expect &&
			diff --git a/h/1 b/h/1
			deleted file mode 120000
			index d0b5850..0000000
			--- a/h/1
			+++ /dev/null
			@@ -1 +0,0 @@
			-../f/1
			\ No newline at end of file
			diff --git a/../../a/1 b/../../a/1
			new file mode 100644
			index 0000000..d00491f
			--- /dev/null
			+++ b/../../a/1
			@@ -0,0 +1 @@
			+1
		EOF
		test_cmp expect actual &&
		test_expect_code 1 git diff --no-index ../../a/1 i/1 >actual &&
		cat <<-EOF >expect &&
			diff --git a/../../a/1 b/../../a/1
			deleted file mode 100644
			index d00491f..0000000
			--- a/../../a/1
			+++ /dev/null
			@@ -1 +0,0 @@
			-1
			diff --git a/i/1 b/i/1
			new file mode 120000
			index 0000000..d8b9c34
			--- /dev/null
			+++ b/i/1
			@@ -0,0 +1 @@
			+../g/1
			\ No newline at end of file
		EOF
		test_cmp expect actual
	)
'

test_done
debug log:

solving e49f773515 ...
found e49f773515 in https://public-inbox.org/git/20200918113256.8699-3-tguyot@gmail.com/
found 0168946b63 in git.git.git
preparing index
index prepared:
100755 0168946b6394092bbedc4da6d57ef9ba8e205927	t/t4053-diff-no-index.sh

applying [1/1] https://public-inbox.org/git/20200918113256.8699-3-tguyot@gmail.com/
diff --git a/t/t4053-diff-no-index.sh b/t/t4053-diff-no-index.sh
index 0168946b63..e49f773515 100755

Checking patch t/t4053-diff-no-index.sh...
Applied patch t/t4053-diff-no-index.sh cleanly.

index at:
100755 e49f773515455266822a7ff1bfbe24af79525663	t/t4053-diff-no-index.sh

Code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).