]> git.ipfire.org Git - thirdparty/git.git/blame - t/t0000-basic.sh
t0000: fix test if run with TEST_OUTPUT_DIRECTORY
[thirdparty/git.git] / t / t0000-basic.sh
CommitLineData
e1970ce4
JH
1#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
5
6test_description='Test the very basics part #1.
7
8The rest of the test suite does not check the basic operation of git
9plumbing commands to work very carefully. Their job is to concentrate
10on tricky features that caused bugs in the past to detect regression.
11
12This test runs very basic features, like registering things in cache,
13writing tree, etc.
14
15Note that this test *deliberately* hard-codes many expected object
16IDs. When object ID computation changes, like in the previous case of
17swapping compression and hashing order, the person who is making the
18modification *should* take notice and update the test vectors here.
19'
eea42069 20
e1970ce4
JH
21. ./test-lib.sh
22
8cb79803
DL
23try_local_xy () {
24 local x="local" y="alsolocal" &&
25 echo "$x $y"
01d3a526
MH
26}
27
7f0b5908 28# Check whether the shell supports the "local" keyword. "local" is not
01d3a526 29# POSIX-standard, but it is very widely supported by POSIX-compliant
7f0b5908 30# shells, and we rely on it within Git's test framework.
01d3a526 31#
7f0b5908
JK
32# If your shell fails this test, the results of other tests may be
33# unreliable. You may wish to report the problem to the Git mailing
34# list <git@vger.kernel.org>, as it could cause us to reconsider
35# relying on "local".
01d3a526
MH
36test_expect_success 'verify that the running shell supports "local"' '
37 x="notlocal" &&
8cb79803
DL
38 y="alsonotlocal" &&
39 echo "local alsolocal" >expected1 &&
40 try_local_xy >actual1 &&
01d3a526 41 test_cmp expected1 actual1 &&
8cb79803
DL
42 echo "notlocal alsonotlocal" >expected2 &&
43 echo "$x $y" >actual2 &&
01d3a526
MH
44 test_cmp expected2 actual2
45'
46
e1970ce4 47################################################################
5be60078 48# git init has been done in an empty repository.
e1970ce4
JH
49# make sure it is empty.
50
1b5b2b64
SL
51test_expect_success '.git/objects should be empty after git init in an empty repo' '
52 find .git/objects -type f -print >should-be-empty &&
53 test_line_count = 0 should-be-empty
54'
e1970ce4 55
9106c097
LT
56# also it should have 2 subdirectories; no fan-out anymore, pack, and info.
57# 3 is counting "objects" itself
1b5b2b64
SL
58test_expect_success '.git/objects should have 3 subdirectories' '
59 find .git/objects -type d -print >full-of-directories &&
60 test_line_count = 3 full-of-directories
61'
e1970ce4 62
41ac414e
JH
63################################################################
64# Test harness
65test_expect_success 'success is reported like this' '
1b5b2b64 66 :
41ac414e 67'
7b905119 68
0445e6f0
IB
69_run_sub_test_lib_test_common () {
70 neg="$1" name="$2" descr="$3" # stdin is the body of the test code
71 shift 3
ac223c40
JK
72
73 # intercept pseudo-options at the front of the argument list that we
74 # will not pass to child script
75 skip=
76 while test $# -gt 0
77 do
78 case "$1" in
79 --skip=*)
80 skip=${1#--*=}
81 shift
82 ;;
83 *)
84 break
85 ;;
86 esac
87 done
88
565b6fa8
AS
89 mkdir "$name" &&
90 (
a63c12c9
JK
91 # Pretend we're not running under a test harness, whether we
92 # are or not. The test-lib output depends on the setting of
93 # this variable, so we need a stable setting under which to run
94 # the sub-test.
95 sane_unset HARNESS_ACTIVE &&
565b6fa8 96 cd "$name" &&
0555e4af 97 write_script "$name.sh" "$TEST_SHELL_PATH" <<-EOF &&
565b6fa8
AS
98 test_description='$descr (run in sub test-lib)
99
100 This is run in a sub test-lib so that we do not get incorrect
101 passing metrics
102 '
103
104 # Point to the t/test-lib.sh, which isn't in ../ as usual
105 . "\$TEST_DIRECTORY"/test-lib.sh
106 EOF
107 cat >>"$name.sh" &&
565b6fa8 108 export TEST_DIRECTORY &&
ade15525
PS
109 # The child test re-sources GIT-BUILD-OPTIONS and may thus
110 # override the test output directory. We thus pass it as an
111 # explicit override to the child.
112 TEST_OUTPUT_DIRECTORY_OVERRIDE=$(pwd) &&
113 export TEST_OUTPUT_DIRECTORY_OVERRIDE &&
ac223c40
JK
114 GIT_SKIP_TESTS=$skip &&
115 export GIT_SKIP_TESTS &&
797e2cfd 116 sane_unset GIT_TEST_FAIL_PREREQS &&
0445e6f0
IB
117 if test -z "$neg"
118 then
119 ./"$name.sh" "$@" >out 2>err
120 else
0555e4af 121 ! ./"$name.sh" "$@" >out 2>err
0445e6f0 122 fi
565b6fa8
AS
123 )
124}
1b5b2b64 125
0445e6f0
IB
126run_sub_test_lib_test () {
127 _run_sub_test_lib_test_common '' "$@"
128}
129
130run_sub_test_lib_test_err () {
131 _run_sub_test_lib_test_common '!' "$@"
132}
133
565b6fa8
AS
134check_sub_test_lib_test () {
135 name="$1" # stdin is the expected output from the test
136 (
137 cd "$name" &&
ec10b018 138 test_must_be_empty err &&
565b6fa8
AS
139 sed -e 's/^> //' -e 's/Z$//' >expect &&
140 test_cmp expect out
141 )
142}
1b5b2b64 143
0445e6f0 144check_sub_test_lib_test_err () {
832c0e5e 145 name="$1" # stdin is the expected output from the test
7a40cf15 146 # expected error output is in descriptor 3
0445e6f0
IB
147 (
148 cd "$name" &&
149 sed -e 's/^> //' -e 's/Z$//' >expect.out &&
150 test_cmp expect.out out &&
151 sed -e 's/^> //' -e 's/Z$//' <&3 >expect.err &&
152 test_cmp expect.err err
153 )
154}
155
30291525
JK
156test_expect_success 'pretend we have a fully passing test suite' '
157 run_sub_test_lib_test full-pass "3 passing tests" <<-\EOF &&
5ebf89e8
AS
158 for i in 1 2 3
159 do
30291525 160 test_expect_success "passing test #$i" "true"
5ebf89e8
AS
161 done
162 test_done
163 EOF
30291525 164 check_sub_test_lib_test full-pass <<-\EOF
5ebf89e8
AS
165 > ok 1 - passing test #1
166 > ok 2 - passing test #2
167 > ok 3 - passing test #3
168 > # passed all 3 test(s)
169 > 1..3
170 EOF
30291525 171'
1b5b2b64 172
30291525 173test_expect_success 'pretend we have a partially passing test suite' '
77172420 174 run_sub_test_lib_test_err \
30291525
JK
175 partial-pass "2/3 tests passing" <<-\EOF &&
176 test_expect_success "passing test #1" "true"
177 test_expect_success "failing test #2" "false"
178 test_expect_success "passing test #3" "true"
5ebf89e8
AS
179 test_done
180 EOF
30291525 181 check_sub_test_lib_test partial-pass <<-\EOF
5ebf89e8
AS
182 > ok 1 - passing test #1
183 > not ok 2 - failing test #2
184 # false
185 > ok 3 - passing test #3
186 > # failed 1 among 3 test(s)
187 > 1..3
188 EOF
30291525 189'
1b5b2b64 190
30291525
JK
191test_expect_success 'pretend we have a known breakage' '
192 run_sub_test_lib_test failing-todo "A failing TODO test" <<-\EOF &&
193 test_expect_success "passing test" "true"
194 test_expect_failure "pretend we have a known breakage" "false"
5ebf89e8
AS
195 test_done
196 EOF
30291525 197 check_sub_test_lib_test failing-todo <<-\EOF
5ebf89e8
AS
198 > ok 1 - passing test
199 > not ok 2 - pretend we have a known breakage # TODO known breakage
200 > # still have 1 known breakage(s)
201 > # passed all remaining 1 test(s)
202 > 1..2
203 EOF
30291525 204'
1b5b2b64 205
30291525
JK
206test_expect_success 'pretend we have fixed a known breakage' '
207 run_sub_test_lib_test passing-todo "A passing TODO test" <<-\EOF &&
208 test_expect_failure "pretend we have fixed a known breakage" "true"
1b5b2b64
SL
209 test_done
210 EOF
30291525 211 check_sub_test_lib_test passing-todo <<-\EOF
b73d9a23
AS
212 > ok 1 - pretend we have fixed a known breakage # TODO known breakage vanished
213 > # 1 known breakage(s) vanished; please update test(s)
1b5b2b64
SL
214 > 1..1
215 EOF
30291525 216'
565b6fa8 217
30291525 218test_expect_success 'pretend we have fixed one of two known breakages (run in sub test-lib)' '
b73d9a23 219 run_sub_test_lib_test partially-passing-todos \
30291525
JK
220 "2 TODO tests, one passing" <<-\EOF &&
221 test_expect_failure "pretend we have a known breakage" "false"
222 test_expect_success "pretend we have a passing test" "true"
223 test_expect_failure "pretend we have fixed another known breakage" "true"
b73d9a23
AS
224 test_done
225 EOF
30291525 226 check_sub_test_lib_test partially-passing-todos <<-\EOF
b73d9a23
AS
227 > not ok 1 - pretend we have a known breakage # TODO known breakage
228 > ok 2 - pretend we have a passing test
229 > ok 3 - pretend we have fixed another known breakage # TODO known breakage vanished
230 > # 1 known breakage(s) vanished; please update test(s)
231 > # still have 1 known breakage(s)
232 > # passed all remaining 1 test(s)
233 > 1..3
234 EOF
30291525 235'
b73d9a23 236
30291525 237test_expect_success 'pretend we have a pass, fail, and known breakage' '
77172420 238 run_sub_test_lib_test_err \
30291525
JK
239 mixed-results1 "mixed results #1" <<-\EOF &&
240 test_expect_success "passing test" "true"
241 test_expect_success "failing test" "false"
242 test_expect_failure "pretend we have a known breakage" "false"
5ebf89e8
AS
243 test_done
244 EOF
30291525 245 check_sub_test_lib_test mixed-results1 <<-\EOF
5ebf89e8
AS
246 > ok 1 - passing test
247 > not ok 2 - failing test
248 > # false
249 > not ok 3 - pretend we have a known breakage # TODO known breakage
250 > # still have 1 known breakage(s)
251 > # failed 1 among remaining 2 test(s)
252 > 1..3
253 EOF
30291525 254'
5ebf89e8 255
30291525 256test_expect_success 'pretend we have a mix of all possible results' '
77172420 257 run_sub_test_lib_test_err \
30291525
JK
258 mixed-results2 "mixed results #2" <<-\EOF &&
259 test_expect_success "passing test" "true"
260 test_expect_success "passing test" "true"
261 test_expect_success "passing test" "true"
262 test_expect_success "passing test" "true"
263 test_expect_success "failing test" "false"
264 test_expect_success "failing test" "false"
265 test_expect_success "failing test" "false"
266 test_expect_failure "pretend we have a known breakage" "false"
267 test_expect_failure "pretend we have a known breakage" "false"
268 test_expect_failure "pretend we have fixed a known breakage" "true"
269 test_done
270 EOF
271 check_sub_test_lib_test mixed-results2 <<-\EOF
5ebf89e8
AS
272 > ok 1 - passing test
273 > ok 2 - passing test
274 > ok 3 - passing test
275 > ok 4 - passing test
276 > not ok 5 - failing test
277 > # false
278 > not ok 6 - failing test
279 > # false
280 > not ok 7 - failing test
281 > # false
282 > not ok 8 - pretend we have a known breakage # TODO known breakage
283 > not ok 9 - pretend we have a known breakage # TODO known breakage
b73d9a23
AS
284 > ok 10 - pretend we have fixed a known breakage # TODO known breakage vanished
285 > # 1 known breakage(s) vanished; please update test(s)
5ebf89e8 286 > # still have 2 known breakage(s)
b73d9a23 287 > # failed 3 among remaining 7 test(s)
5ebf89e8
AS
288 > 1..10
289 EOF
30291525 290'
5ebf89e8 291
a926c4b9 292test_expect_success 'test --verbose' '
77172420 293 run_sub_test_lib_test_err \
96f3ccc2 294 t1234-verbose "test verbose" --verbose <<-\EOF &&
517cd55f
TR
295 test_expect_success "passing test" true
296 test_expect_success "test with output" "echo foo"
297 test_expect_success "failing test" false
298 test_done
299 EOF
96f3ccc2
SG
300 mv t1234-verbose/out t1234-verbose/out+ &&
301 grep -v "^Initialized empty" t1234-verbose/out+ >t1234-verbose/out &&
302 check_sub_test_lib_test t1234-verbose <<-\EOF
ffe1afe6 303 > expecting success of 1234.1 '\''passing test'\'': true
517cd55f
TR
304 > ok 1 - passing test
305 > Z
ffe1afe6 306 > expecting success of 1234.2 '\''test with output'\'': echo foo
517cd55f 307 > foo
517cd55f
TR
308 > ok 2 - test with output
309 > Z
ffe1afe6 310 > expecting success of 1234.3 '\''failing test'\'': false
517cd55f
TR
311 > not ok 3 - failing test
312 > # false
313 > Z
314 > # failed 1 among 3 test(s)
315 > 1..3
316 EOF
317'
318
ff09af3f 319test_expect_success 'test --verbose-only' '
77172420 320 run_sub_test_lib_test_err \
96f3ccc2 321 t2345-verbose-only-2 "test verbose-only=2" \
ff09af3f
TR
322 --verbose-only=2 <<-\EOF &&
323 test_expect_success "passing test" true
324 test_expect_success "test with output" "echo foo"
325 test_expect_success "failing test" false
326 test_done
327 EOF
96f3ccc2 328 check_sub_test_lib_test t2345-verbose-only-2 <<-\EOF
ff09af3f
TR
329 > ok 1 - passing test
330 > Z
ffe1afe6 331 > expecting success of 2345.2 '\''test with output'\'': echo foo
ff09af3f 332 > foo
ff09af3f
TR
333 > ok 2 - test with output
334 > Z
335 > not ok 3 - failing test
336 > # false
337 > # failed 1 among 3 test(s)
338 > 1..3
339 EOF
340'
341
30291525 342test_expect_success 'GIT_SKIP_TESTS' '
7e28c16f 343 (
ef2ac68d 344 run_sub_test_lib_test git-skip-tests-basic \
ac223c40
JK
345 "GIT_SKIP_TESTS" \
346 --skip="git.2" <<-\EOF &&
7e28c16f
RJ
347 for i in 1 2 3
348 do
30291525 349 test_expect_success "passing test #$i" "true"
7e28c16f
RJ
350 done
351 test_done
352 EOF
30291525 353 check_sub_test_lib_test git-skip-tests-basic <<-\EOF
7e28c16f
RJ
354 > ok 1 - passing test #1
355 > ok 2 # skip passing test #2 (GIT_SKIP_TESTS)
356 > ok 3 - passing test #3
357 > # passed all 3 test(s)
358 > 1..3
359 EOF
360 )
30291525 361'
ef2ac68d 362
30291525 363test_expect_success 'GIT_SKIP_TESTS several tests' '
7e28c16f 364 (
ef2ac68d 365 run_sub_test_lib_test git-skip-tests-several \
ac223c40
JK
366 "GIT_SKIP_TESTS several tests" \
367 --skip="git.2 git.5" <<-\EOF &&
7e28c16f
RJ
368 for i in 1 2 3 4 5 6
369 do
30291525 370 test_expect_success "passing test #$i" "true"
7e28c16f
RJ
371 done
372 test_done
373 EOF
30291525 374 check_sub_test_lib_test git-skip-tests-several <<-\EOF
7e28c16f
RJ
375 > ok 1 - passing test #1
376 > ok 2 # skip passing test #2 (GIT_SKIP_TESTS)
377 > ok 3 - passing test #3
378 > ok 4 - passing test #4
379 > ok 5 # skip passing test #5 (GIT_SKIP_TESTS)
380 > ok 6 - passing test #6
381 > # passed all 6 test(s)
382 > 1..6
383 EOF
384 )
30291525 385'
ef2ac68d 386
30291525 387test_expect_success 'GIT_SKIP_TESTS sh pattern' '
7e28c16f 388 (
ef2ac68d 389 run_sub_test_lib_test git-skip-tests-sh-pattern \
ac223c40
JK
390 "GIT_SKIP_TESTS sh pattern" \
391 --skip="git.[2-5]" <<-\EOF &&
7e28c16f
RJ
392 for i in 1 2 3 4 5 6
393 do
30291525 394 test_expect_success "passing test #$i" "true"
7e28c16f
RJ
395 done
396 test_done
397 EOF
30291525 398 check_sub_test_lib_test git-skip-tests-sh-pattern <<-\EOF
7e28c16f
RJ
399 > ok 1 - passing test #1
400 > ok 2 # skip passing test #2 (GIT_SKIP_TESTS)
401 > ok 3 # skip passing test #3 (GIT_SKIP_TESTS)
402 > ok 4 # skip passing test #4 (GIT_SKIP_TESTS)
403 > ok 5 # skip passing test #5 (GIT_SKIP_TESTS)
404 > ok 6 - passing test #6
405 > # passed all 6 test(s)
406 > 1..6
407 EOF
408 )
30291525 409'
ef2ac68d 410
30291525 411test_expect_success 'GIT_SKIP_TESTS entire suite' '
b05b4093 412 (
b05b4093 413 run_sub_test_lib_test git-skip-tests-entire-suite \
ac223c40
JK
414 "GIT_SKIP_TESTS entire suite" \
415 --skip="git" <<-\EOF &&
b05b4093
DL
416 for i in 1 2 3
417 do
30291525 418 test_expect_success "passing test #$i" "true"
b05b4093
DL
419 done
420 test_done
421 EOF
30291525 422 check_sub_test_lib_test git-skip-tests-entire-suite <<-\EOF
b05b4093
DL
423 > 1..0 # SKIP skip all tests in git
424 EOF
425 )
30291525 426'
b05b4093 427
30291525 428test_expect_success 'GIT_SKIP_TESTS does not skip unmatched suite' '
b05b4093 429 (
b05b4093 430 run_sub_test_lib_test git-skip-tests-unmatched-suite \
ac223c40
JK
431 "GIT_SKIP_TESTS does not skip unmatched suite" \
432 --skip="notgit" <<-\EOF &&
b05b4093
DL
433 for i in 1 2 3
434 do
30291525 435 test_expect_success "passing test #$i" "true"
b05b4093
DL
436 done
437 test_done
438 EOF
30291525 439 check_sub_test_lib_test git-skip-tests-unmatched-suite <<-\EOF
b05b4093
DL
440 > ok 1 - passing test #1
441 > ok 2 - passing test #2
442 > ok 3 - passing test #3
443 > # passed all 3 test(s)
444 > 1..3
445 EOF
446 )
30291525 447'
b05b4093 448
30291525 449test_expect_success '--run basic' '
0445e6f0 450 run_sub_test_lib_test run-basic \
30291525 451 "--run basic" --run="1,3,5" <<-\EOF &&
0445e6f0
IB
452 for i in 1 2 3 4 5 6
453 do
30291525 454 test_expect_success "passing test #$i" "true"
0445e6f0
IB
455 done
456 test_done
457 EOF
30291525 458 check_sub_test_lib_test run-basic <<-\EOF
0445e6f0
IB
459 > ok 1 - passing test #1
460 > ok 2 # skip passing test #2 (--run)
461 > ok 3 - passing test #3
462 > ok 4 # skip passing test #4 (--run)
463 > ok 5 - passing test #5
464 > ok 6 # skip passing test #6 (--run)
465 > # passed all 6 test(s)
466 > 1..6
467 EOF
30291525 468'
0445e6f0 469
30291525 470test_expect_success '--run with a range' '
0445e6f0 471 run_sub_test_lib_test run-range \
30291525 472 "--run with a range" --run="1-3" <<-\EOF &&
0445e6f0
IB
473 for i in 1 2 3 4 5 6
474 do
30291525 475 test_expect_success "passing test #$i" "true"
0445e6f0
IB
476 done
477 test_done
478 EOF
30291525 479 check_sub_test_lib_test run-range <<-\EOF
0445e6f0
IB
480 > ok 1 - passing test #1
481 > ok 2 - passing test #2
482 > ok 3 - passing test #3
483 > ok 4 # skip passing test #4 (--run)
484 > ok 5 # skip passing test #5 (--run)
485 > ok 6 # skip passing test #6 (--run)
486 > # passed all 6 test(s)
487 > 1..6
488 EOF
30291525 489'
0445e6f0 490
30291525 491test_expect_success '--run with two ranges' '
0445e6f0 492 run_sub_test_lib_test run-two-ranges \
30291525 493 "--run with two ranges" --run="1-2,5-6" <<-\EOF &&
0445e6f0
IB
494 for i in 1 2 3 4 5 6
495 do
30291525 496 test_expect_success "passing test #$i" "true"
0445e6f0
IB
497 done
498 test_done
499 EOF
30291525 500 check_sub_test_lib_test run-two-ranges <<-\EOF
0445e6f0
IB
501 > ok 1 - passing test #1
502 > ok 2 - passing test #2
503 > ok 3 # skip passing test #3 (--run)
504 > ok 4 # skip passing test #4 (--run)
505 > ok 5 - passing test #5
506 > ok 6 - passing test #6
507 > # passed all 6 test(s)
508 > 1..6
509 EOF
30291525 510'
0445e6f0 511
30291525 512test_expect_success '--run with a left open range' '
0445e6f0 513 run_sub_test_lib_test run-left-open-range \
30291525 514 "--run with a left open range" --run="-3" <<-\EOF &&
0445e6f0
IB
515 for i in 1 2 3 4 5 6
516 do
30291525 517 test_expect_success "passing test #$i" "true"
0445e6f0
IB
518 done
519 test_done
520 EOF
30291525 521 check_sub_test_lib_test run-left-open-range <<-\EOF
0445e6f0
IB
522 > ok 1 - passing test #1
523 > ok 2 - passing test #2
524 > ok 3 - passing test #3
525 > ok 4 # skip passing test #4 (--run)
526 > ok 5 # skip passing test #5 (--run)
527 > ok 6 # skip passing test #6 (--run)
528 > # passed all 6 test(s)
529 > 1..6
530 EOF
30291525 531'
0445e6f0 532
30291525 533test_expect_success '--run with a right open range' '
0445e6f0 534 run_sub_test_lib_test run-right-open-range \
30291525 535 "--run with a right open range" --run="4-" <<-\EOF &&
0445e6f0
IB
536 for i in 1 2 3 4 5 6
537 do
30291525 538 test_expect_success "passing test #$i" "true"
0445e6f0
IB
539 done
540 test_done
541 EOF
30291525 542 check_sub_test_lib_test run-right-open-range <<-\EOF
0445e6f0
IB
543 > ok 1 # skip passing test #1 (--run)
544 > ok 2 # skip passing test #2 (--run)
545 > ok 3 # skip passing test #3 (--run)
546 > ok 4 - passing test #4
547 > ok 5 - passing test #5
548 > ok 6 - passing test #6
549 > # passed all 6 test(s)
550 > 1..6
551 EOF
30291525 552'
0445e6f0 553
30291525 554test_expect_success '--run with basic negation' '
0445e6f0 555 run_sub_test_lib_test run-basic-neg \
30291525 556 "--run with basic negation" --run="!3" <<-\EOF &&
0445e6f0
IB
557 for i in 1 2 3 4 5 6
558 do
30291525 559 test_expect_success "passing test #$i" "true"
0445e6f0
IB
560 done
561 test_done
562 EOF
30291525 563 check_sub_test_lib_test run-basic-neg <<-\EOF
0445e6f0
IB
564 > ok 1 - passing test #1
565 > ok 2 - passing test #2
566 > ok 3 # skip passing test #3 (--run)
567 > ok 4 - passing test #4
568 > ok 5 - passing test #5
569 > ok 6 - passing test #6
570 > # passed all 6 test(s)
571 > 1..6
572 EOF
30291525 573'
0445e6f0 574
30291525 575test_expect_success '--run with two negations' '
0445e6f0 576 run_sub_test_lib_test run-two-neg \
30291525 577 "--run with two negations" --run="!3,!6" <<-\EOF &&
0445e6f0
IB
578 for i in 1 2 3 4 5 6
579 do
30291525 580 test_expect_success "passing test #$i" "true"
0445e6f0
IB
581 done
582 test_done
583 EOF
30291525 584 check_sub_test_lib_test run-two-neg <<-\EOF
0445e6f0
IB
585 > ok 1 - passing test #1
586 > ok 2 - passing test #2
587 > ok 3 # skip passing test #3 (--run)
588 > ok 4 - passing test #4
589 > ok 5 - passing test #5
590 > ok 6 # skip passing test #6 (--run)
591 > # passed all 6 test(s)
592 > 1..6
593 EOF
30291525 594'
0445e6f0 595
30291525 596test_expect_success '--run a range and negation' '
0445e6f0 597 run_sub_test_lib_test run-range-and-neg \
30291525 598 "--run a range and negation" --run="-4,!2" <<-\EOF &&
0445e6f0
IB
599 for i in 1 2 3 4 5 6
600 do
30291525 601 test_expect_success "passing test #$i" "true"
0445e6f0
IB
602 done
603 test_done
604 EOF
30291525 605 check_sub_test_lib_test run-range-and-neg <<-\EOF
0445e6f0
IB
606 > ok 1 - passing test #1
607 > ok 2 # skip passing test #2 (--run)
608 > ok 3 - passing test #3
609 > ok 4 - passing test #4
610 > ok 5 # skip passing test #5 (--run)
611 > ok 6 # skip passing test #6 (--run)
612 > # passed all 6 test(s)
613 > 1..6
614 EOF
30291525 615'
0445e6f0 616
30291525 617test_expect_success '--run range negation' '
0445e6f0 618 run_sub_test_lib_test run-range-neg \
30291525 619 "--run range negation" --run="!1-3" <<-\EOF &&
0445e6f0
IB
620 for i in 1 2 3 4 5 6
621 do
30291525 622 test_expect_success "passing test #$i" "true"
0445e6f0
IB
623 done
624 test_done
625 EOF
30291525 626 check_sub_test_lib_test run-range-neg <<-\EOF
0445e6f0
IB
627 > ok 1 # skip passing test #1 (--run)
628 > ok 2 # skip passing test #2 (--run)
629 > ok 3 # skip passing test #3 (--run)
630 > ok 4 - passing test #4
631 > ok 5 - passing test #5
632 > ok 6 - passing test #6
633 > # passed all 6 test(s)
634 > 1..6
635 EOF
30291525 636'
0445e6f0 637
30291525 638test_expect_success '--run include, exclude and include' '
0445e6f0 639 run_sub_test_lib_test run-inc-neg-inc \
30291525
JK
640 "--run include, exclude and include" \
641 --run="1-5,!1-3,2" <<-\EOF &&
0445e6f0
IB
642 for i in 1 2 3 4 5 6
643 do
30291525 644 test_expect_success "passing test #$i" "true"
0445e6f0
IB
645 done
646 test_done
647 EOF
30291525 648 check_sub_test_lib_test run-inc-neg-inc <<-\EOF
0445e6f0
IB
649 > ok 1 # skip passing test #1 (--run)
650 > ok 2 - passing test #2
651 > ok 3 # skip passing test #3 (--run)
652 > ok 4 - passing test #4
653 > ok 5 - passing test #5
654 > ok 6 # skip passing test #6 (--run)
655 > # passed all 6 test(s)
656 > 1..6
657 EOF
30291525 658'
0445e6f0 659
30291525 660test_expect_success '--run include, exclude and include, comma separated' '
0445e6f0 661 run_sub_test_lib_test run-inc-neg-inc-comma \
30291525
JK
662 "--run include, exclude and include, comma separated" \
663 --run=1-5,!1-3,2 <<-\EOF &&
0445e6f0
IB
664 for i in 1 2 3 4 5 6
665 do
30291525 666 test_expect_success "passing test #$i" "true"
0445e6f0
IB
667 done
668 test_done
669 EOF
30291525 670 check_sub_test_lib_test run-inc-neg-inc-comma <<-\EOF
0445e6f0
IB
671 > ok 1 # skip passing test #1 (--run)
672 > ok 2 - passing test #2
673 > ok 3 # skip passing test #3 (--run)
674 > ok 4 - passing test #4
675 > ok 5 - passing test #5
676 > ok 6 # skip passing test #6 (--run)
677 > # passed all 6 test(s)
678 > 1..6
679 EOF
30291525 680'
0445e6f0 681
30291525 682test_expect_success '--run exclude and include' '
0445e6f0 683 run_sub_test_lib_test run-neg-inc \
30291525
JK
684 "--run exclude and include" \
685 --run="!3-,5" <<-\EOF &&
0445e6f0
IB
686 for i in 1 2 3 4 5 6
687 do
30291525 688 test_expect_success "passing test #$i" "true"
0445e6f0
IB
689 done
690 test_done
691 EOF
30291525 692 check_sub_test_lib_test run-neg-inc <<-\EOF
0445e6f0
IB
693 > ok 1 - passing test #1
694 > ok 2 - passing test #2
695 > ok 3 # skip passing test #3 (--run)
696 > ok 4 # skip passing test #4 (--run)
697 > ok 5 - passing test #5
698 > ok 6 # skip passing test #6 (--run)
699 > # passed all 6 test(s)
700 > 1..6
701 EOF
30291525 702'
0445e6f0 703
30291525 704test_expect_success '--run empty selectors' '
0445e6f0 705 run_sub_test_lib_test run-empty-sel \
30291525
JK
706 "--run empty selectors" \
707 --run="1,,3,,,5" <<-\EOF &&
0445e6f0
IB
708 for i in 1 2 3 4 5 6
709 do
30291525 710 test_expect_success "passing test #$i" "true"
0445e6f0
IB
711 done
712 test_done
713 EOF
30291525 714 check_sub_test_lib_test run-empty-sel <<-\EOF
0445e6f0
IB
715 > ok 1 - passing test #1
716 > ok 2 # skip passing test #2 (--run)
717 > ok 3 - passing test #3
718 > ok 4 # skip passing test #4 (--run)
719 > ok 5 - passing test #5
720 > ok 6 # skip passing test #6 (--run)
721 > # passed all 6 test(s)
722 > 1..6
723 EOF
30291525 724'
0445e6f0 725
30291525 726test_expect_success '--run substring selector' '
f21ac368 727 run_sub_test_lib_test run-substring-selector \
30291525
JK
728 "--run empty selectors" \
729 --run="relevant" <<-\EOF &&
730 test_expect_success "relevant test" "true"
f21ac368
EN
731 for i in 1 2 3 4 5 6
732 do
30291525 733 test_expect_success "other test #$i" "true"
f21ac368
EN
734 done
735 test_done
736 EOF
30291525 737 check_sub_test_lib_test run-substring-selector <<-\EOF
f21ac368
EN
738 > ok 1 - relevant test
739 > ok 2 # skip other test #1 (--run)
740 > ok 3 # skip other test #2 (--run)
741 > ok 4 # skip other test #3 (--run)
742 > ok 5 # skip other test #4 (--run)
743 > ok 6 # skip other test #5 (--run)
744 > ok 7 # skip other test #6 (--run)
745 > # passed all 7 test(s)
746 > 1..7
747 EOF
30291525 748'
f21ac368 749
30291525 750test_expect_success '--run keyword selection' '
0445e6f0 751 run_sub_test_lib_test_err run-inv-range-start \
30291525
JK
752 "--run invalid range start" \
753 --run="a-5" <<-\EOF &&
754 test_expect_success "passing test #1" "true"
0445e6f0
IB
755 test_done
756 EOF
757 check_sub_test_lib_test_err run-inv-range-start \
30291525 758 <<-\EOF_OUT 3<<-EOF_ERR
0445e6f0
IB
759 > FATAL: Unexpected exit with code 1
760 EOF_OUT
30291525 761 > error: --run: invalid non-numeric in range start: ${SQ}a-5${SQ}
0445e6f0 762 EOF_ERR
30291525 763'
0445e6f0 764
30291525 765test_expect_success '--run invalid range end' '
0445e6f0 766 run_sub_test_lib_test_err run-inv-range-end \
30291525
JK
767 "--run invalid range end" \
768 --run="1-z" <<-\EOF &&
769 test_expect_success "passing test #1" "true"
0445e6f0
IB
770 test_done
771 EOF
772 check_sub_test_lib_test_err run-inv-range-end \
30291525 773 <<-\EOF_OUT 3<<-EOF_ERR
0445e6f0
IB
774 > FATAL: Unexpected exit with code 1
775 EOF_OUT
30291525 776 > error: --run: invalid non-numeric in range end: ${SQ}1-z${SQ}
0445e6f0 777 EOF_ERR
30291525 778'
0445e6f0 779
efd2600e
JK
780test_expect_success 'tests respect prerequisites' '
781 run_sub_test_lib_test prereqs "tests respect prereqs" <<-\EOF &&
0445e6f0 782
efd2600e
JK
783 test_set_prereq HAVEIT
784 test_expect_success HAVEIT "prereq is satisfied" "true"
785 test_expect_success "have_prereq works" "
786 test_have_prereq HAVEIT
787 "
788 test_expect_success DONTHAVEIT "prereq not satisfied" "false"
bdccd3c1 789
efd2600e
JK
790 test_set_prereq HAVETHIS
791 test_expect_success HAVETHIS,HAVEIT "multiple prereqs" "true"
792 test_expect_success HAVEIT,DONTHAVEIT "mixed prereqs (yes,no)" "false"
793 test_expect_success DONTHAVEIT,HAVEIT "mixed prereqs (no,yes)" "false"
bdccd3c1 794
efd2600e
JK
795 test_done
796 EOF
797
798 check_sub_test_lib_test prereqs <<-\EOF
799 ok 1 - prereq is satisfied
800 ok 2 - have_prereq works
801 ok 3 # skip prereq not satisfied (missing DONTHAVEIT)
802 ok 4 - multiple prereqs
803 ok 5 # skip mixed prereqs (yes,no) (missing DONTHAVEIT of HAVEIT,DONTHAVEIT)
804 ok 6 # skip mixed prereqs (no,yes) (missing DONTHAVEIT of DONTHAVEIT,HAVEIT)
805 # passed all 6 test(s)
806 1..6
807 EOF
bdccd3c1
JK
808'
809
efd2600e
JK
810test_expect_success 'tests respect lazy prerequisites' '
811 run_sub_test_lib_test lazy-prereqs "respect lazy prereqs" <<-\EOF &&
bdccd3c1 812
efd2600e
JK
813 test_lazy_prereq LAZY_TRUE true
814 test_expect_success LAZY_TRUE "lazy prereq is satisifed" "true"
815 test_expect_success !LAZY_TRUE "negative lazy prereq" "false"
816
817 test_lazy_prereq LAZY_FALSE false
818 test_expect_success LAZY_FALSE "lazy prereq not satisfied" "false"
819 test_expect_success !LAZY_FALSE "negative false prereq" "true"
820
821 test_done
822 EOF
823
824 check_sub_test_lib_test lazy-prereqs <<-\EOF
825 ok 1 - lazy prereq is satisifed
826 ok 2 # skip negative lazy prereq (missing !LAZY_TRUE)
827 ok 3 # skip lazy prereq not satisfied (missing LAZY_FALSE)
828 ok 4 - negative false prereq
829 # passed all 4 test(s)
830 1..4
831 EOF
53ff3b96
SG
832'
833
efd2600e
JK
834test_expect_success 'nested lazy prerequisites' '
835 run_sub_test_lib_test nested-lazy "nested lazy prereqs" <<-\EOF &&
836
837 test_lazy_prereq NESTED_INNER "
838 >inner &&
839 rm -f outer
840 "
841 test_lazy_prereq NESTED_PREREQ "
842 >outer &&
843 test_have_prereq NESTED_INNER &&
844 echo can create new file in cwd >file &&
845 test_path_is_file outer &&
846 test_path_is_missing inner
847 "
848 test_expect_success NESTED_PREREQ "evaluate nested prereq" "true"
849
850 test_done
851 EOF
852
853 check_sub_test_lib_test nested-lazy <<-\EOF
854 ok 1 - evaluate nested prereq
855 # passed all 1 test(s)
856 1..1
857 EOF
858'
53ff3b96 859
30291525 860test_expect_success 'lazy prereqs do not turn off tracing' '
477dcadd 861 run_sub_test_lib_test lazy-prereq-and-tracing \
30291525 862 "lazy prereqs and -x" -v -x <<-\EOF &&
477dcadd
JS
863 test_lazy_prereq LAZY true
864
30291525 865 test_expect_success lazy "test_have_prereq LAZY && echo trace"
477dcadd
JS
866
867 test_done
868 EOF
869
30291525
JK
870 grep "echo trace" lazy-prereq-and-tracing/err
871'
477dcadd 872
03efadb7 873test_expect_success 'tests clean up after themselves' '
080e2952
JK
874 run_sub_test_lib_test cleanup "test with cleanup" <<-\EOF &&
875 clean=no
876 test_expect_success "do cleanup" "
877 test_when_finished clean=yes
878 "
879 test_expect_success "cleanup happened" "
880 test $clean = yes
881 "
882 test_done
883 EOF
03efadb7 884
080e2952
JK
885 check_sub_test_lib_test cleanup <<-\EOF
886 ok 1 - do cleanup
887 ok 2 - cleanup happened
888 # passed all 2 test(s)
889 1..2
890 EOF
891'
03efadb7 892
30291525 893test_expect_success 'tests clean up even on failures' '
77172420 894 run_sub_test_lib_test_err \
30291525
JK
895 failing-cleanup "Failing tests with cleanup commands" <<-\EOF &&
896 test_expect_success "tests clean up even after a failure" "
1b5b2b64
SL
897 touch clean-after-failure &&
898 test_when_finished rm clean-after-failure &&
899 (exit 1)
30291525
JK
900 "
901 test_expect_success "failure to clean up causes the test to fail" "
1b5b2b64 902 test_when_finished \"(exit 2)\"
30291525 903 "
1b5b2b64 904 test_done
1b5b2b64 905 EOF
30291525 906 check_sub_test_lib_test failing-cleanup <<-\EOF
5e5c006e 907 > not ok 1 - tests clean up even after a failure
1b5b2b64
SL
908 > # Z
909 > # touch clean-after-failure &&
910 > # test_when_finished rm clean-after-failure &&
911 > # (exit 1)
912 > # Z
5e5c006e 913 > not ok 2 - failure to clean up causes the test to fail
1b5b2b64 914 > # Z
30291525 915 > # test_when_finished "(exit 2)"
1b5b2b64
SL
916 > # Z
917 > # failed 2 among 2 test(s)
918 > 1..2
919 EOF
30291525 920'
892e6f7e 921
30291525 922test_expect_success 'test_atexit is run' '
77172420 923 run_sub_test_lib_test_err \
30291525
JK
924 atexit-cleanup "Run atexit commands" -i <<-\EOF &&
925 test_expect_success "tests clean up even after a failure" "
900721e1
JS
926 > ../../clean-atexit &&
927 test_atexit rm ../../clean-atexit &&
928 > ../../also-clean-atexit &&
929 test_atexit rm ../../also-clean-atexit &&
930 > ../../dont-clean-atexit &&
931 (exit 1)
30291525 932 "
900721e1
JS
933 test_done
934 EOF
935 test_path_is_file dont-clean-atexit &&
936 test_path_is_missing clean-atexit &&
937 test_path_is_missing also-clean-atexit
30291525 938'
900721e1 939
2c02b110 940test_expect_success 'test_oid provides sane info by default' '
941 test_oid zero >actual &&
942 grep "^00*\$" actual &&
943 rawsz="$(test_oid rawsz)" &&
944 hexsz="$(test_oid hexsz)" &&
945 test "$hexsz" -eq $(wc -c <actual) &&
946 test $(( $rawsz * 2)) -eq "$hexsz"
947'
948
949test_expect_success 'test_oid can look up data for SHA-1' '
950 test_when_finished "test_detect_hash" &&
951 test_set_hash sha1 &&
952 test_oid zero >actual &&
953 grep "^00*\$" actual &&
954 rawsz="$(test_oid rawsz)" &&
955 hexsz="$(test_oid hexsz)" &&
956 test $(wc -c <actual) -eq 40 &&
957 test "$rawsz" -eq 20 &&
958 test "$hexsz" -eq 40
959'
960
961test_expect_success 'test_oid can look up data for SHA-256' '
962 test_when_finished "test_detect_hash" &&
963 test_set_hash sha256 &&
964 test_oid zero >actual &&
965 grep "^00*\$" actual &&
966 rawsz="$(test_oid rawsz)" &&
967 hexsz="$(test_oid hexsz)" &&
968 test $(wc -c <actual) -eq 64 &&
969 test "$rawsz" -eq 32 &&
970 test "$hexsz" -eq 64
971'
972
ceaa4b3a 973test_expect_success 'test_oid can look up data for a specified algorithm' '
974 rawsz="$(test_oid --hash=sha1 rawsz)" &&
975 hexsz="$(test_oid --hash=sha1 hexsz)" &&
976 test "$rawsz" -eq 20 &&
977 test "$hexsz" -eq 40 &&
978 rawsz="$(test_oid --hash=sha256 rawsz)" &&
979 hexsz="$(test_oid --hash=sha256 hexsz)" &&
980 test "$rawsz" -eq 32 &&
981 test "$hexsz" -eq 64
982'
983
43a2afee
SG
984test_expect_success 'test_bool_env' '
985 (
986 sane_unset envvar &&
987
988 test_bool_env envvar true &&
989 ! test_bool_env envvar false &&
990
991 envvar= &&
992 export envvar &&
993 ! test_bool_env envvar true &&
994 ! test_bool_env envvar false &&
995
996 envvar=true &&
997 test_bool_env envvar true &&
998 test_bool_env envvar false &&
999
1000 envvar=false &&
1001 ! test_bool_env envvar true &&
1002 ! test_bool_env envvar false &&
1003
1004 envvar=invalid &&
1005 # When encountering an invalid bool value, test_bool_env
1006 # prints its error message to the original stderr of the
1007 # test script, hence the redirection of fd 7, and aborts
1008 # with "exit 1", hence the subshell.
1009 ! ( test_bool_env envvar true ) 7>err &&
1010 grep "error: test_bool_env requires bool values" err &&
1011
1012 envvar=true &&
1013 ! ( test_bool_env envvar invalid ) 7>err &&
1014 grep "error: test_bool_env requires bool values" err
1015 )
1016'
1017
e1970ce4
JH
1018################################################################
1019# Basics of the basics
1020
e483e144 1021test_oid_cache <<\EOF
1022path0f sha1:f87290f8eb2cbbea7857214459a0739927eab154
1023path0f sha256:638106af7c38be056f3212cbd7ac65bc1bac74f420ca5a436ff006a9d025d17d
1024
1025path0s sha1:15a98433ae33114b085f3eb3bb03b832b3180a01
1026path0s sha256:3a24cc53cf68edddac490bbf94a418a52932130541361f685df685e41dd6c363
1027
1028path2f sha1:3feff949ed00a62d9f7af97c15cd8a30595e7ac7
1029path2f sha256:2a7f36571c6fdbaf0e3f62751a0b25a3f4c54d2d1137b3f4af9cb794bb498e5f
1030
1031path2s sha1:d8ce161addc5173867a3c3c730924388daedbc38
1032path2s sha256:18fd611b787c2e938ddcc248fabe4d66a150f9364763e9ec133dd01d5bb7c65a
1033
1034path2d sha1:58a09c23e2ca152193f2786e06986b7b6712bdbe
1035path2d sha256:00e4b32b96e7e3d65d79112dcbea53238a22715f896933a62b811377e2650c17
1036
1037path3f sha1:0aa34cae68d0878578ad119c86ca2b5ed5b28376
1038path3f sha256:09f58616b951bd571b8cb9dc76d372fbb09ab99db2393f5ab3189d26c45099ad
1039
1040path3s sha1:8599103969b43aff7e430efea79ca4636466794f
1041path3s sha256:fce1aed087c053306f3f74c32c1a838c662bbc4551a7ac2420f5d6eb061374d0
1042
1043path3d sha1:21ae8269cacbe57ae09138dcc3a2887f904d02b3
1044path3d sha256:9b60497be959cb830bf3f0dc82bcc9ad9e925a24e480837ade46b2295e47efe1
1045
1046subp3f sha1:00fb5908cb97c2564a9783c0c64087333b3b464f
1047subp3f sha256:a1a9e16998c988453f18313d10375ee1d0ddefe757e710dcae0d66aa1e0c58b3
1048
1049subp3s sha1:6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c
1050subp3s sha256:81759d9f5e93c6546ecfcadb560c1ff057314b09f93fe8ec06e2d8610d34ef10
1051
1052subp3d sha1:3c5e5399f3a333eddecce7a9b9465b63f65f51e2
1053subp3d sha256:76b4ef482d4fa1c754390344cf3851c7f883b27cf9bc999c6547928c46aeafb7
1054
1055root sha1:087704a96baf1c2d1c869a8b084481e121c88b5b
1056root sha256:9481b52abab1b2ffeedbf9de63ce422b929f179c1b98ff7bee5f8f1bc0710751
1057
1058simpletree sha1:7bb943559a305bdd6bdee2cef6e5df2413c3d30a
1059simpletree sha256:1710c07a6c86f9a3c7376364df04c47ee39e5a5e221fcdd84b743bc9bb7e2bc5
1060EOF
1061
e1970ce4 1062# updating a new file without --add should fail.
1b5b2b64
SL
1063test_expect_success 'git update-index without --add should fail adding' '
1064 test_must_fail git update-index should-be-empty
41ac414e 1065'
e1970ce4
JH
1066
1067# and with --add it should succeed, even if it is empty (it used to fail).
1b5b2b64
SL
1068test_expect_success 'git update-index with --add should succeed' '
1069 git update-index --add should-be-empty
1070'
e1970ce4 1071
1b5b2b64
SL
1072test_expect_success 'writing tree out with git write-tree' '
1073 tree=$(git write-tree)
1074'
e1970ce4
JH
1075
1076# we know the shape and contents of the tree and know the object ID for it.
e483e144 1077test_expect_success 'validate object ID of a known tree' '
1078 test "$tree" = "$(test_oid simpletree)"
1b5b2b64 1079 '
e1970ce4
JH
1080
1081# Removing paths.
1b5b2b64
SL
1082test_expect_success 'git update-index without --remove should fail removing' '
1083 rm -f should-be-empty full-of-directories &&
1084 test_must_fail git update-index should-be-empty
41ac414e 1085'
e1970ce4 1086
1b5b2b64
SL
1087test_expect_success 'git update-index with --remove should be able to remove' '
1088 git update-index --remove should-be-empty
1089'
e1970ce4
JH
1090
1091# Empty tree can be written with recent write-tree.
1b5b2b64
SL
1092test_expect_success 'git write-tree should be able to write an empty tree' '
1093 tree=$(git write-tree)
1094'
e1970ce4 1095
1b5b2b64 1096test_expect_success 'validate object ID of a known tree' '
f9e7d9f8 1097 test "$tree" = $EMPTY_TREE
1b5b2b64 1098'
e1970ce4
JH
1099
1100# Various types of objects
1b5b2b64 1101
1b5b2b64
SL
1102test_expect_success 'adding various types of objects with git update-index --add' '
1103 mkdir path2 path3 path3/subp3 &&
1104 paths="path0 path2/file2 path3/file3 path3/subp3/file3" &&
1105 (
1106 for p in $paths
1107 do
1108 echo "hello $p" >$p || exit 1
c723a76d 1109 test_ln_s_add "hello $p" ${p}sym || exit 1
1b5b2b64
SL
1110 done
1111 ) &&
1112 find path* ! -type d -print | xargs git update-index --add
1113'
e1970ce4
JH
1114
1115# Show them and see that matches what we expect.
1b5b2b64
SL
1116test_expect_success 'showing stage with git ls-files --stage' '
1117 git ls-files --stage >current
1118'
1119
e483e144 1120test_expect_success 'validate git ls-files output for a known tree' '
1121 cat >expected <<-EOF &&
1122 100644 $(test_oid path0f) 0 path0
1123 120000 $(test_oid path0s) 0 path0sym
1124 100644 $(test_oid path2f) 0 path2/file2
1125 120000 $(test_oid path2s) 0 path2/file2sym
1126 100644 $(test_oid path3f) 0 path3/file3
1127 120000 $(test_oid path3s) 0 path3/file3sym
1128 100644 $(test_oid subp3f) 0 path3/subp3/file3
1129 120000 $(test_oid subp3s) 0 path3/subp3/file3sym
1b5b2b64
SL
1130 EOF
1131 test_cmp expected current
1132'
1133
1134test_expect_success 'writing tree out with git write-tree' '
1135 tree=$(git write-tree)
1136'
1137
e483e144 1138test_expect_success 'validate object ID for a known tree' '
1139 test "$tree" = "$(test_oid root)"
1b5b2b64
SL
1140'
1141
1142test_expect_success 'showing tree with git ls-tree' '
1143 git ls-tree $tree >current
1144'
1145
e483e144 1146test_expect_success 'git ls-tree output for a known tree' '
1147 cat >expected <<-EOF &&
1148 100644 blob $(test_oid path0f) path0
1149 120000 blob $(test_oid path0s) path0sym
1150 040000 tree $(test_oid path2d) path2
1151 040000 tree $(test_oid path3d) path3
1b5b2b64
SL
1152 EOF
1153 test_cmp expected current
1154'
e1970ce4 1155
246cc52f
JH
1156# This changed in ls-tree pathspec change -- recursive does
1157# not show tree nodes anymore.
1b5b2b64
SL
1158test_expect_success 'showing tree with git ls-tree -r' '
1159 git ls-tree -r $tree >current
1160'
1161
e483e144 1162test_expect_success 'git ls-tree -r output for a known tree' '
1163 cat >expected <<-EOF &&
1164 100644 blob $(test_oid path0f) path0
1165 120000 blob $(test_oid path0s) path0sym
1166 100644 blob $(test_oid path2f) path2/file2
1167 120000 blob $(test_oid path2s) path2/file2sym
1168 100644 blob $(test_oid path3f) path3/file3
1169 120000 blob $(test_oid path3s) path3/file3sym
1170 100644 blob $(test_oid subp3f) path3/subp3/file3
1171 120000 blob $(test_oid subp3s) path3/subp3/file3sym
1b5b2b64
SL
1172 EOF
1173 test_cmp expected current
1174'
e1970ce4 1175
fdeb6bf5 1176# But with -r -t we can have both.
1b5b2b64
SL
1177test_expect_success 'showing tree with git ls-tree -r -t' '
1178 git ls-tree -r -t $tree >current
1179'
3d12d0cf 1180
e483e144 1181test_expect_success 'git ls-tree -r output for a known tree' '
1182 cat >expected <<-EOF &&
1183 100644 blob $(test_oid path0f) path0
1184 120000 blob $(test_oid path0s) path0sym
1185 040000 tree $(test_oid path2d) path2
1186 100644 blob $(test_oid path2f) path2/file2
1187 120000 blob $(test_oid path2s) path2/file2sym
1188 040000 tree $(test_oid path3d) path3
1189 100644 blob $(test_oid path3f) path3/file3
1190 120000 blob $(test_oid path3s) path3/file3sym
1191 040000 tree $(test_oid subp3d) path3/subp3
1192 100644 blob $(test_oid subp3f) path3/subp3/file3
1193 120000 blob $(test_oid subp3s) path3/subp3/file3sym
1b5b2b64
SL
1194 EOF
1195 test_cmp expected current
1196'
3d12d0cf 1197
1b5b2b64
SL
1198test_expect_success 'writing partial tree out with git write-tree --prefix' '
1199 ptree=$(git write-tree --prefix=path3)
41ac414e 1200'
3d12d0cf 1201
e483e144 1202test_expect_success 'validate object ID for a known tree' '
1203 test "$ptree" = $(test_oid path3d)
1b5b2b64
SL
1204'
1205
1206test_expect_success 'writing partial tree out with git write-tree --prefix' '
1207 ptree=$(git write-tree --prefix=path3/subp3)
1208'
1209
e483e144 1210test_expect_success 'validate object ID for a known tree' '
1211 test "$ptree" = $(test_oid subp3d)
1b5b2b64
SL
1212'
1213
1214test_expect_success 'put invalid objects into the index' '
1215 rm -f .git/index &&
cdd1e17f 1216 suffix=$(echo $ZERO_OID | sed -e "s/^.//") &&
1217 cat >badobjects <<-EOF &&
1218 100644 blob $(test_oid 001) dir/file1
1219 100644 blob $(test_oid 002) dir/file2
1220 100644 blob $(test_oid 003) dir/file3
1221 100644 blob $(test_oid 004) dir/file4
1222 100644 blob $(test_oid 005) dir/file5
1b5b2b64
SL
1223 EOF
1224 git update-index --index-info <badobjects
1225'
1226
1227test_expect_success 'writing this tree without --missing-ok' '
1228 test_must_fail git write-tree
1229'
1230
1231test_expect_success 'writing this tree with --missing-ok' '
1232 git write-tree --missing-ok
1233'
3d12d0cf
JS
1234
1235
e1970ce4 1236################################################################
1b5b2b64 1237test_expect_success 'git read-tree followed by write-tree should be idempotent' '
99094a7a 1238 rm -f .git/index &&
1b5b2b64 1239 git read-tree $tree &&
ac9b5475 1240 test_path_is_file .git/index &&
1b5b2b64
SL
1241 newtree=$(git write-tree) &&
1242 test "$newtree" = "$tree"
1243'
1244
e483e144 1245test_expect_success 'validate git diff-files output for a know cache/work tree state' '
1246 cat >expected <<EOF &&
1247:100644 100644 $(test_oid path0f) $ZERO_OID M path0
1248:120000 120000 $(test_oid path0s) $ZERO_OID M path0sym
1249:100644 100644 $(test_oid path2f) $ZERO_OID M path2/file2
1250:120000 120000 $(test_oid path2s) $ZERO_OID M path2/file2sym
1251:100644 100644 $(test_oid path3f) $ZERO_OID M path3/file3
1252:120000 120000 $(test_oid path3s) $ZERO_OID M path3/file3sym
1253:100644 100644 $(test_oid subp3f) $ZERO_OID M path3/subp3/file3
1254:120000 120000 $(test_oid subp3s) $ZERO_OID M path3/subp3/file3sym
e1970ce4 1255EOF
1b5b2b64 1256 git diff-files >current &&
dcbaa0b3 1257 test_cmp expected current
1b5b2b64 1258'
e1970ce4 1259
1b5b2b64
SL
1260test_expect_success 'git update-index --refresh should succeed' '
1261 git update-index --refresh
1262'
e1970ce4 1263
1b5b2b64
SL
1264test_expect_success 'no diff after checkout and git update-index --refresh' '
1265 git diff-files >current &&
1266 cmp -s current /dev/null
1267'
e1970ce4 1268
9af0b8db 1269################################################################
e483e144 1270P=$(test_oid root)
1b5b2b64 1271
e483e144 1272test_expect_success 'git commit-tree records the correct tree in a commit' '
1b5b2b64
SL
1273 commit0=$(echo NO | git commit-tree $P) &&
1274 tree=$(git show --pretty=raw $commit0 |
1275 sed -n -e "s/^tree //p" -e "/^author /q") &&
1276 test "z$tree" = "z$P"
1277'
1278
e483e144 1279test_expect_success 'git commit-tree records the correct parent in a commit' '
1b5b2b64
SL
1280 commit1=$(echo NO | git commit-tree $P -p $commit0) &&
1281 parent=$(git show --pretty=raw $commit1 |
1282 sed -n -e "s/^parent //p" -e "/^author /q") &&
1283 test "z$commit0" = "z$parent"
1284'
1285
e483e144 1286test_expect_success 'git commit-tree omits duplicated parent in a commit' '
1b5b2b64
SL
1287 commit2=$(echo NO | git commit-tree $P -p $commit0 -p $commit0) &&
1288 parent=$(git show --pretty=raw $commit2 |
1289 sed -n -e "s/^parent //p" -e "/^author /q" |
1290 sort -u) &&
1291 test "z$commit0" = "z$parent" &&
1292 numparent=$(git show --pretty=raw $commit2 |
1293 sed -n -e "s/^parent //p" -e "/^author /q" |
1294 wc -l) &&
1295 test $numparent = 1
1296'
9af0b8db 1297
81a361be
JH
1298test_expect_success 'update-index D/F conflict' '
1299 mv path0 tmp &&
1300 mv path2 path0 &&
1301 mv tmp path2 &&
1302 git update-index --add --replace path2 path0/file2 &&
1303 numpath0=$(git ls-files path0 | wc -l) &&
1304 test $numpath0 = 1
1305'
1306
7fec10b7
JH
1307test_expect_success 'very long name in the index handled sanely' '
1308
1309 a=a && # 1
1310 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 16
1311 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 256
1312 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 4096
1313 a=${a}q &&
1314
1315 >path4 &&
1316 git update-index --add path4 &&
1317 (
1318 git ls-files -s path4 |
1319 sed -e "s/ .*/ /" |
75651fd7 1320 tr -d "\012" &&
7fec10b7
JH
1321 echo "$a"
1322 ) | git update-index --index-info &&
1323 len=$(git ls-files "a*" | wc -c) &&
1324 test $len = 4098
1325'
1326
6a67c759
DL
1327test_expect_success 'test_must_fail on a failing git command' '
1328 test_must_fail git notacommand
1329'
1330
1331test_expect_success 'test_must_fail on a failing git command with env' '
1332 test_must_fail env var1=a var2=b git notacommand
1333'
1334
1335test_expect_success 'test_must_fail rejects a non-git command' '
1336 ! test_must_fail grep ^$ notafile 2>err &&
1337 grep -F "test_must_fail: only '"'"'git'"'"' is allowed" err
1338'
1339
1340test_expect_success 'test_must_fail rejects a non-git command with env' '
1341 ! test_must_fail env var1=a var2=b grep ^$ notafile 2>err &&
1342 grep -F "test_must_fail: only '"'"'git'"'"' is allowed" err
1343'
1344
e1970ce4 1345test_done