rebase: use correct base for --keep-base when a branch is given
[alt-git.git] / t / t2006-checkout-index-basic.sh
blob7705e3a31708355c05271aa9d5eafa5af359043f
1 #!/bin/sh
3 test_description='basic checkout-index tests
6 . ./test-lib.sh
8 test_expect_success 'checkout-index --gobbledegook' '
9 test_expect_code 129 git checkout-index --gobbledegook 2>err &&
10 test_i18ngrep "[Uu]sage" err
13 test_expect_success 'checkout-index -h in broken repository' '
14 mkdir broken &&
16 cd broken &&
17 git init &&
18 >.git/index &&
19 test_expect_code 129 git checkout-index -h >usage 2>&1
20 ) &&
21 test_i18ngrep "[Uu]sage" broken/usage
24 test_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
29 test_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
34 for mode in 'case' 'utf-8'
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
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 &&
47 cd $mode-collision &&
48 mkdir target-dir &&
50 empty_obj_hex=$(git hash-object -w --stdin </dev/null) &&
51 symlink_hex=$(printf "%s" "$PWD/target-dir" | git hash-object -w --stdin) &&
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
60 git update-index --index-info <objs &&
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.
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.
70 git -c core.precomposeUnicode=false checkout-index -f \
71 ${dir}/x ${dir}/y ${symlink} ${dir}/z &&
73 # Should not create ${dir}/z at ${symlink}/z
74 test_path_is_missing target-dir/z
78 done
80 test_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 &&
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
94 test_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
103 test_done