]> git.ipfire.org Git - thirdparty/git.git/blame - t/t2006-checkout-index-basic.sh
leak tests: mark all trace2 tests as passing with SANITIZE=leak
[thirdparty/git.git] / t / t2006-checkout-index-basic.sh
CommitLineData
cf9d52e4
NTND
1#!/bin/sh
2
3test_description='basic checkout-index tests
4'
5
6. ./test-lib.sh
7
8test_expect_success 'checkout-index --gobbledegook' '
9 test_expect_code 129 git checkout-index --gobbledegook 2>err &&
9a001381 10 test_i18ngrep "[Uu]sage" err
cf9d52e4
NTND
11'
12
13test_expect_success 'checkout-index -h in broken repository' '
14 mkdir broken &&
15 (
16 cd broken &&
17 git init &&
18 >.git/index &&
19 test_expect_code 129 git checkout-index -h >usage 2>&1
20 ) &&
9a001381 21 test_i18ngrep "[Uu]sage" broken/usage
cf9d52e4
NTND
22'
23
7e410615
JK
24test_expect_success 'checkout-index reports errors (cmdline)' '
25 test_must_fail git checkout-index -- does-not-exist 2>stderr &&
26 test_i18ngrep not.in.the.cache stderr
27'
28
29test_expect_success 'checkout-index reports errors (stdin)' '
30 echo does-not-exist |
31 test_must_fail git checkout-index --stdin 2>stderr &&
32 test_i18ngrep not.in.the.cache stderr
33'
684dd4c2
MT
34for mode in 'case' 'utf-8'
35do
36 case "$mode" in
37 case) dir='A' symlink='a' mode_prereq='CASE_INSENSITIVE_FS' ;;
38 utf-8)
39 dir=$(printf "\141\314\210") symlink=$(printf "\303\244")
40 mode_prereq='UTF8_NFD_TO_NFC' ;;
41 esac
42
43 test_expect_success SYMLINKS,$mode_prereq \
44 "checkout-index with $mode-collision don't write to the wrong place" '
45 git init $mode-collision &&
46 (
47 cd $mode-collision &&
48 mkdir target-dir &&
49
50 empty_obj_hex=$(git hash-object -w --stdin </dev/null) &&
51 symlink_hex=$(printf "%s" "$PWD/target-dir" | git hash-object -w --stdin) &&
52
53 cat >objs <<-EOF &&
54 100644 blob ${empty_obj_hex} ${dir}/x
55 100644 blob ${empty_obj_hex} ${dir}/y
56 100644 blob ${empty_obj_hex} ${dir}/z
57 120000 blob ${symlink_hex} ${symlink}
58 EOF
59
60 git update-index --index-info <objs &&
61
62 # Note: the order is important here to exercise the
63 # case where the file at ${dir} has its type changed by
64 # the time Git tries to check out ${dir}/z.
65 #
66 # Also, we use core.precomposeUnicode=false because we
67 # want Git to treat the UTF-8 paths transparently on
68 # Mac OS, matching what is in the index.
69 #
70 git -c core.precomposeUnicode=false checkout-index -f \
71 ${dir}/x ${dir}/y ${symlink} ${dir}/z &&
72
73 # Should not create ${dir}/z at ${symlink}/z
74 test_path_is_missing target-dir/z
75
76 )
77 '
78done
7e410615 79
9334ea8e
MT
80test_expect_success 'checkout-index --temp correctly reports error on missing blobs' '
81 test_when_finished git reset --hard &&
82 missing_blob=$(echo "no such blob here" | git hash-object --stdin) &&
83 cat >objs <<-EOF &&
84 100644 $missing_blob file
85 120000 $missing_blob symlink
86 EOF
87 git update-index --index-info <objs &&
88
89 test_must_fail git checkout-index --temp symlink file 2>stderr &&
90 test_i18ngrep "unable to read sha1 file of file ($missing_blob)" stderr &&
91 test_i18ngrep "unable to read sha1 file of symlink ($missing_blob)" stderr
92'
93
94test_expect_success 'checkout-index --temp correctly reports error for submodules' '
95 git init sub &&
96 test_commit -C sub file &&
97 git submodule add ./sub &&
98 git commit -m sub &&
99 test_must_fail git checkout-index --temp sub 2>stderr &&
100 test_i18ngrep "cannot create temporary submodule sub" stderr
101'
102
cf9d52e4 103test_done