]> git.ipfire.org Git - thirdparty/git.git/blame - t/t2006-checkout-index-basic.sh
checkout: fix bug that makes checkout follow symlinks in leading path
[thirdparty/git.git] / t / t2006-checkout-index-basic.sh
CommitLineData
cf9d52e4
NTND
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 &&
9a001381 10 test_i18ngrep "[Uu]sage" err
cf9d52e4
NTND
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 ) &&
9a001381 21 test_i18ngrep "[Uu]sage" broken/usage
cf9d52e4
NTND
22'
23
684dd4c2
MT
24for mode in 'case' 'utf-8'
25do
26 case "$mode" in
27 case) dir='A' symlink='a' mode_prereq='CASE_INSENSITIVE_FS' ;;
28 utf-8)
29 dir=$(printf "\141\314\210") symlink=$(printf "\303\244")
30 mode_prereq='UTF8_NFD_TO_NFC' ;;
31 esac
32
33 test_expect_success SYMLINKS,$mode_prereq \
34 "checkout-index with $mode-collision don't write to the wrong place" '
35 git init $mode-collision &&
36 (
37 cd $mode-collision &&
38 mkdir target-dir &&
39
40 empty_obj_hex=$(git hash-object -w --stdin </dev/null) &&
41 symlink_hex=$(printf "%s" "$PWD/target-dir" | git hash-object -w --stdin) &&
42
43 cat >objs <<-EOF &&
44 100644 blob ${empty_obj_hex} ${dir}/x
45 100644 blob ${empty_obj_hex} ${dir}/y
46 100644 blob ${empty_obj_hex} ${dir}/z
47 120000 blob ${symlink_hex} ${symlink}
48 EOF
49
50 git update-index --index-info <objs &&
51
52 # Note: the order is important here to exercise the
53 # case where the file at ${dir} has its type changed by
54 # the time Git tries to check out ${dir}/z.
55 #
56 # Also, we use core.precomposeUnicode=false because we
57 # want Git to treat the UTF-8 paths transparently on
58 # Mac OS, matching what is in the index.
59 #
60 git -c core.precomposeUnicode=false checkout-index -f \
61 ${dir}/x ${dir}/y ${symlink} ${dir}/z &&
62
63 # Should not create ${dir}/z at ${symlink}/z
64 test_path_is_missing target-dir/z
65
66 )
67 '
68done
69
cf9d52e4 70test_done