]>
Commit | Line | Data |
---|---|---|
cf9d52e4 NTND |
1 | #!/bin/sh |
2 | ||
3 | test_description='basic checkout-index tests | |
4 | ' | |
5 | ||
3e3b9321 | 6 | TEST_PASSES_SANITIZE_LEAK=true |
cf9d52e4 NTND |
7 | . ./test-lib.sh |
8 | ||
9 | test_expect_success 'checkout-index --gobbledegook' ' | |
10 | test_expect_code 129 git checkout-index --gobbledegook 2>err && | |
6789275d | 11 | test_grep "[Uu]sage" err |
cf9d52e4 NTND |
12 | ' |
13 | ||
14 | test_expect_success 'checkout-index -h in broken repository' ' | |
15 | mkdir broken && | |
16 | ( | |
17 | cd broken && | |
18 | git init && | |
19 | >.git/index && | |
20 | test_expect_code 129 git checkout-index -h >usage 2>&1 | |
21 | ) && | |
6789275d | 22 | test_grep "[Uu]sage" broken/usage |
cf9d52e4 NTND |
23 | ' |
24 | ||
7e410615 JK |
25 | test_expect_success 'checkout-index reports errors (cmdline)' ' |
26 | test_must_fail git checkout-index -- does-not-exist 2>stderr && | |
6789275d | 27 | test_grep not.in.the.cache stderr |
7e410615 JK |
28 | ' |
29 | ||
30 | test_expect_success 'checkout-index reports errors (stdin)' ' | |
31 | echo does-not-exist | | |
32 | test_must_fail git checkout-index --stdin 2>stderr && | |
6789275d | 33 | test_grep not.in.the.cache stderr |
7e410615 | 34 | ' |
684dd4c2 MT |
35 | for mode in 'case' 'utf-8' |
36 | do | |
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 | |
43 | ||
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 && | |
47 | ( | |
48 | cd $mode-collision && | |
49 | mkdir target-dir && | |
50 | ||
51 | empty_obj_hex=$(git hash-object -w --stdin </dev/null) && | |
52 | symlink_hex=$(printf "%s" "$PWD/target-dir" | git hash-object -w --stdin) && | |
53 | ||
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 | |
60 | ||
61 | git update-index --index-info <objs && | |
62 | ||
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. | |
66 | # | |
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. | |
70 | # | |
71 | git -c core.precomposeUnicode=false checkout-index -f \ | |
72 | ${dir}/x ${dir}/y ${symlink} ${dir}/z && | |
73 | ||
74 | # Should not create ${dir}/z at ${symlink}/z | |
75 | test_path_is_missing target-dir/z | |
76 | ||
77 | ) | |
78 | ' | |
79 | done | |
7e410615 | 80 | |
9334ea8e MT |
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 && | |
89 | ||
90 | test_must_fail git checkout-index --temp symlink file 2>stderr && | |
6789275d JH |
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 | |
9334ea8e MT |
93 | ' |
94 | ||
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 && | |
6789275d | 101 | test_grep "cannot create temporary submodule sub" stderr |
9334ea8e MT |
102 | ' |
103 | ||
cf9d52e4 | 104 | test_done |