Git fork
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 &&
10 test_grep "[Uu]sage" err
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 ) &&
21 test_grep "[Uu]sage" broken/usage
22'
23
24test_expect_success 'checkout-index does not crash with -h' '
25 test_expect_code 129 git checkout-index -h >usage &&
26 test_grep "[Uu]sage: git checkout-index " usage &&
27 test_expect_code 129 nongit git checkout-index -h >usage &&
28 test_grep "[Uu]sage: git checkout-index " usage
29'
30
31test_expect_success 'checkout-index reports errors (cmdline)' '
32 test_must_fail git checkout-index -- does-not-exist 2>stderr &&
33 test_grep not.in.the.cache stderr
34'
35
36test_expect_success 'checkout-index reports errors (stdin)' '
37 echo does-not-exist |
38 test_must_fail git checkout-index --stdin 2>stderr &&
39 test_grep not.in.the.cache stderr
40'
41for mode in 'case' 'utf-8'
42do
43 case "$mode" in
44 case) dir='A' symlink='a' mode_prereq='CASE_INSENSITIVE_FS' ;;
45 utf-8)
46 dir=$(printf "\141\314\210") symlink=$(printf "\303\244")
47 mode_prereq='UTF8_NFD_TO_NFC' ;;
48 esac
49
50 test_expect_success SYMLINKS,$mode_prereq \
51 "checkout-index with $mode-collision don't write to the wrong place" '
52 git init $mode-collision &&
53 (
54 cd $mode-collision &&
55 mkdir target-dir &&
56
57 empty_obj_hex=$(git hash-object -w --stdin </dev/null) &&
58 symlink_hex=$(printf "%s" "$PWD/target-dir" | git hash-object -w --stdin) &&
59
60 cat >objs <<-EOF &&
61 100644 blob ${empty_obj_hex} ${dir}/x
62 100644 blob ${empty_obj_hex} ${dir}/y
63 100644 blob ${empty_obj_hex} ${dir}/z
64 120000 blob ${symlink_hex} ${symlink}
65 EOF
66
67 git update-index --index-info <objs &&
68
69 # Note: the order is important here to exercise the
70 # case where the file at ${dir} has its type changed by
71 # the time Git tries to check out ${dir}/z.
72 #
73 # Also, we use core.precomposeUnicode=false because we
74 # want Git to treat the UTF-8 paths transparently on
75 # Mac OS, matching what is in the index.
76 #
77 git -c core.precomposeUnicode=false checkout-index -f \
78 ${dir}/x ${dir}/y ${symlink} ${dir}/z &&
79
80 # Should not create ${dir}/z at ${symlink}/z
81 test_path_is_missing target-dir/z
82
83 )
84 '
85done
86
87test_expect_success 'checkout-index --temp correctly reports error on missing blobs' '
88 test_when_finished git reset --hard &&
89 missing_blob=$(echo "no such blob here" | git hash-object --stdin) &&
90 cat >objs <<-EOF &&
91 100644 $missing_blob file
92 120000 $missing_blob symlink
93 EOF
94 git update-index --index-info <objs &&
95
96 test_must_fail git checkout-index --temp symlink file 2>stderr &&
97 test_grep "unable to read sha1 file of file ($missing_blob)" stderr &&
98 test_grep "unable to read sha1 file of symlink ($missing_blob)" stderr
99'
100
101test_expect_success 'checkout-index --temp correctly reports error for submodules' '
102 git init sub &&
103 test_commit -C sub file &&
104 git submodule add ./sub &&
105 git commit -m sub &&
106 test_must_fail git checkout-index --temp sub 2>stderr &&
107 test_grep "cannot create temporary submodule sub" stderr
108'
109
110test_done