Nguyễn Thái Ngọc Duy | cf9d52e | 2010-10-22 01:44:01 -0500 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='basic checkout-index tests |
| 4 | ' |
| 5 | |
Ævar Arnfjörð Bjarmason | 3e3b932 | 2022-07-28 01:13:41 +0200 | [diff] [blame] | 6 | TEST_PASSES_SANITIZE_LEAK=true |
Nguyễn Thái Ngọc Duy | cf9d52e | 2010-10-22 01:44:01 -0500 | [diff] [blame] | 7 | . ./test-lib.sh |
| 8 | |
| 9 | test_expect_success 'checkout-index --gobbledegook' ' |
| 10 | test_expect_code 129 git checkout-index --gobbledegook 2>err && |
Jiang Xin | 9a00138 | 2012-08-27 13:36:55 +0800 | [diff] [blame] | 11 | test_i18ngrep "[Uu]sage" err |
Nguyễn Thái Ngọc Duy | cf9d52e | 2010-10-22 01:44:01 -0500 | [diff] [blame] | 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 | ) && |
Jiang Xin | 9a00138 | 2012-08-27 13:36:55 +0800 | [diff] [blame] | 22 | test_i18ngrep "[Uu]sage" broken/usage |
Nguyễn Thái Ngọc Duy | cf9d52e | 2010-10-22 01:44:01 -0500 | [diff] [blame] | 23 | ' |
| 24 | |
Jeff King | 7e41061 | 2020-10-27 03:37:14 -0400 | [diff] [blame] | 25 | test_expect_success 'checkout-index reports errors (cmdline)' ' |
| 26 | test_must_fail git checkout-index -- does-not-exist 2>stderr && |
| 27 | test_i18ngrep not.in.the.cache stderr |
| 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 && |
| 33 | test_i18ngrep not.in.the.cache stderr |
| 34 | ' |
Matheus Tavares | 684dd4c | 2020-12-10 10:27:55 -0300 | [diff] [blame] | 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 |
Jeff King | 7e41061 | 2020-10-27 03:37:14 -0400 | [diff] [blame] | 80 | |
Matheus Tavares | 9334ea8 | 2021-02-16 11:06:51 -0300 | [diff] [blame] | 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 && |
| 91 | test_i18ngrep "unable to read sha1 file of file ($missing_blob)" stderr && |
| 92 | test_i18ngrep "unable to read sha1 file of symlink ($missing_blob)" stderr |
| 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 && |
| 101 | test_i18ngrep "cannot create temporary submodule sub" stderr |
| 102 | ' |
| 103 | |
Nguyễn Thái Ngọc Duy | cf9d52e | 2010-10-22 01:44:01 -0500 | [diff] [blame] | 104 | test_done |