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