3 # Copyright (c) 2006 Junio C Hamano
6 test_description
='Try various core-level commands in subdirectory.
9 TEST_PASSES_SANITIZE_LEAK
=true
11 .
"$TEST_DIRECTORY"/lib-read-tree.sh
13 test_expect_success setup
'
14 long="a b c d e f g h i j k l m n o p q r s t u v w x y z" &&
15 test_write_lines $long >one &&
17 test_write_lines x y z $long a b c >dir/two &&
18 cp one original.one &&
19 cp dir/two original.two
22 test_expect_success
'update-index and ls-files' '
23 git update-index --add one &&
24 case "$(git ls-files)" in
26 *) echo bad one; return 1 ;;
30 git update-index --add two &&
31 case "$(git ls-files)" in
33 *) echo bad two; exit 1 ;;
36 case "$(git ls-files)" in
37 dir/two"$LF"one) echo pass both ;;
38 *) echo bad; return 1 ;;
42 test_expect_success
'cat-file' '
43 two=$(git ls-files -s dir/two) &&
44 two=$(expr "$two" : "[0-7]* \\([0-9a-f]*\\)") &&
46 git cat-file -p "$two" >actual &&
50 git cat-file -p "$two" >actual &&
54 rm -f actual dir
/actual
56 test_expect_success
'diff-files' '
59 case "$(git diff-files --name-only)" in
60 dir/two"$LF"one) echo pass top ;;
61 *) echo bad top; return 1 ;;
63 # diff should not omit leading paths
66 case "$(git diff-files --name-only)" in
67 dir/two"$LF"one) echo pass subdir ;;
68 *) echo bad subdir; exit 1 ;;
70 case "$(git diff-files --name-only .)" in
71 dir/two) echo pass subdir limited ;;
72 *) echo bad subdir limited; exit 1 ;;
77 test_expect_success
'write-tree' '
78 top=$(git write-tree) &&
82 sub=$(git write-tree) &&
84 test "z$top" = "z$sub"
88 test_expect_success
'checkout-index' '
89 git checkout-index -f -u one &&
90 cmp one original.one &&
93 git checkout-index -f -u two &&
94 cmp two ../original.two
98 test_expect_success
'read-tree' '
100 tree=$(git write-tree) &&
101 read_tree_u_must_succeed --reset -u "$tree" &&
102 cmp one original.one &&
103 cmp dir/two original.two &&
107 read_tree_u_must_succeed --reset -u "$tree" &&
108 cmp two ../original.two &&
109 cmp ../one ../original.one
113 test_expect_success
'alias expansion' '
115 git config alias.test-status-alias status &&
118 git test-status-alias
122 test_expect_success
!MINGW
'!alias expansion' '
125 git config alias.test-alias-directory !pwd &&
127 git test-alias-directory >../actual
129 test_cmp expect actual
132 test_expect_success
'GIT_PREFIX for !alias' '
133 printf "dir/" >expect &&
135 git config alias.test-alias-directory "!sh -c \"printf \$GIT_PREFIX\"" &&
137 git test-alias-directory >../actual
139 test_cmp expect actual
142 test_expect_success
'GIT_PREFIX for built-ins' '
143 # Use GIT_EXTERNAL_DIFF to test that the "diff" built-in
144 # receives the GIT_PREFIX variable.
145 echo "dir/" >expect &&
146 write_script diff <<-\EOF &&
147 printf "%s\n" "$GIT_PREFIX"
151 echo "change" >two &&
152 GIT_EXTERNAL_DIFF=./diff git diff >../actual &&
155 test_cmp expect actual
158 test_expect_success
'no file/rev ambiguity check inside .git' '
159 git commit -a -m 1 &&
166 test_expect_success
'no file/rev ambiguity check inside a bare repo (explicit GIT_DIR)' '
167 test_when_finished "rm -fr foo.git" &&
168 git clone -s --bare .git foo.git &&
171 # older Git needed help by exporting GIT_DIR=.
172 # to realize that it is inside a bare repository.
173 # We keep this test around for regression testing.
174 GIT_DIR=. git show -s HEAD
178 test_expect_success
'no file/rev ambiguity check inside a bare repo' '
179 test_when_finished "rm -fr foo.git" &&
180 git clone -s --bare .git foo.git &&
187 test_expect_success SYMLINKS
'detection should not be fooled by a symlink' '
188 git clone -s .git another &&
189 ln -s another yetanother &&
191 cd yetanother/.git &&