1#!/bin/sh
2#
3# Copyright (c) 2006 Junio C Hamano
4#
56
test_description='Try various core-level commands in subdirectory.
7'
89
. ./test-lib.sh
10. "$TEST_DIRECTORY"/lib-read-tree.sh
1112
test_expect_success setup '
13long="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" &&
14for c in $long; do echo $c; done >one &&
15mkdir dir &&
16for c in x y z $long a b c; do echo $c; done >dir/two &&
17cp one original.one &&
18cp dir/two original.two
19'
2021
test_expect_success 'update-index and ls-files' '
22git update-index --add one &&
23case "`git ls-files`" in
24one) echo pass one ;;
25*) echo bad one; exit 1 ;;
26esac &&
27(
28cd dir &&
29git update-index --add two &&
30case "`git ls-files`" in
31two) echo pass two ;;
32*) echo bad two; exit 1 ;;
33esac
34) &&
35case "`git ls-files`" in
36dir/two"$LF"one) echo pass both ;;
37*) echo bad; exit 1 ;;
38esac
39'
4041
test_expect_success 'cat-file' '
42two=`git ls-files -s dir/two` &&
43two=`expr "$two" : "[0-7]* \\([0-9a-f]*\\)"` &&
44echo "$two" &&
45git cat-file -p "$two" >actual &&
46cmp dir/two actual &&
47(
48cd dir &&
49git cat-file -p "$two" >actual &&
50cmp two actual
51)
52'
53rm -f actual dir/actual
5455
test_expect_success 'diff-files' '
56echo a >>one &&
57echo d >>dir/two &&
58case "`git diff-files --name-only`" in
59dir/two"$LF"one) echo pass top ;;
60*) echo bad top; exit 1 ;;
61esac &&
62# diff should not omit leading paths
63(
64cd dir &&
65case "`git diff-files --name-only`" in
66dir/two"$LF"one) echo pass subdir ;;
67*) echo bad subdir; exit 1 ;;
68esac &&
69case "`git diff-files --name-only .`" in
70dir/two) echo pass subdir limited ;;
71*) echo bad subdir limited; exit 1 ;;
72esac
73)
74'
7576
test_expect_success 'write-tree' '
77top=`git write-tree` &&
78echo $top &&
79(
80cd dir &&
81sub=`git write-tree` &&
82echo $sub &&
83test "z$top" = "z$sub"
84)
85'
8687
test_expect_success 'checkout-index' '
88git checkout-index -f -u one &&
89cmp one original.one &&
90(
91cd dir &&
92git checkout-index -f -u two &&
93cmp two ../original.two
94)
95'
9697
test_expect_success 'read-tree' '
98rm -f one dir/two &&
99tree=`git write-tree` &&
100read_tree_u_must_succeed --reset -u "$tree" &&
101cmp one original.one &&
102cmp dir/two original.two &&
103(
104cd dir &&
105rm -f two &&
106read_tree_u_must_succeed --reset -u "$tree" &&
107cmp two ../original.two &&
108cmp ../one ../original.one
109)
110'
111112
test_expect_success 'alias expansion' '
113(
114git config alias.test-status-alias status &&
115cd dir &&
116git status &&
117git test-status-alias
118)
119'
120121
test_expect_success NOT_MINGW '!alias expansion' '
122pwd >expect &&
123(
124git config alias.test-alias-directory !pwd &&
125cd dir &&
126git test-alias-directory >../actual
127) &&
128test_cmp expect actual
129'
130131
test_expect_success 'GIT_PREFIX for !alias' '
132printf "dir/" >expect &&
133(
134git config alias.test-alias-directory "!sh -c \"printf \$GIT_PREFIX\"" &&
135cd dir &&
136git test-alias-directory >../actual
137) &&
138test_cmp expect actual
139'
140141
test_expect_success 'GIT_PREFIX for built-ins' '
142# Use GIT_EXTERNAL_DIFF to test that the "diff" built-in
143# receives the GIT_PREFIX variable.
144printf "dir/" >expect &&
145printf "#!/bin/sh\n" >diff &&
146printf "printf \"\$GIT_PREFIX\"" >>diff &&
147chmod +x diff &&
148(
149cd dir &&
150printf "change" >two &&
151env GIT_EXTERNAL_DIFF=./diff git diff >../actual
152git checkout -- two
153) &&
154test_cmp expect actual
155'
156157
test_expect_success 'no file/rev ambiguity check inside .git' '
158git commit -a -m 1 &&
159(
160cd .git &&
161git show -s HEAD
162)
163'
164165
test_expect_success 'no file/rev ambiguity check inside a bare repo' '
166git clone -s --bare .git foo.git &&
167(
168cd foo.git &&
169GIT_DIR=. git show -s HEAD
170)
171'
172173
# This still does not work as it should...
174: test_expect_success 'no file/rev ambiguity check inside a bare repo' '
175git clone -s --bare .git foo.git &&
176(
177cd foo.git &&
178git show -s HEAD
179)
180'
181182
test_expect_success SYMLINKS 'detection should not be fooled by a symlink' '
183rm -fr foo.git &&
184git clone -s .git another &&
185ln -s another yetanother &&
186(
187cd yetanother/.git &&
188git show -s HEAD
189)
190'
191192
test_done