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'
20LF='
21'
2223
test_expect_success 'update-index and ls-files' '
24git update-index --add one &&
25case "`git ls-files`" in
26one) echo pass one ;;
27*) echo bad one; exit 1 ;;
28esac &&
29(
30cd dir &&
31git update-index --add two &&
32case "`git ls-files`" in
33two) echo pass two ;;
34*) echo bad two; exit 1 ;;
35esac
36) &&
37case "`git ls-files`" in
38dir/two"$LF"one) echo pass both ;;
39*) echo bad; exit 1 ;;
40esac
41'
4243
test_expect_success 'cat-file' '
44two=`git ls-files -s dir/two` &&
45two=`expr "$two" : "[0-7]* \\([0-9a-f]*\\)"` &&
46echo "$two" &&
47git cat-file -p "$two" >actual &&
48cmp dir/two actual &&
49(
50cd dir &&
51git cat-file -p "$two" >actual &&
52cmp two actual
53)
54'
55rm -f actual dir/actual
5657
test_expect_success 'diff-files' '
58echo a >>one &&
59echo d >>dir/two &&
60case "`git diff-files --name-only`" in
61dir/two"$LF"one) echo pass top ;;
62*) echo bad top; exit 1 ;;
63esac &&
64# diff should not omit leading paths
65(
66cd dir &&
67case "`git diff-files --name-only`" in
68dir/two"$LF"one) echo pass subdir ;;
69*) echo bad subdir; exit 1 ;;
70esac &&
71case "`git diff-files --name-only .`" in
72dir/two) echo pass subdir limited ;;
73*) echo bad subdir limited; exit 1 ;;
74esac
75)
76'
7778
test_expect_success 'write-tree' '
79top=`git write-tree` &&
80echo $top &&
81(
82cd dir &&
83sub=`git write-tree` &&
84echo $sub &&
85test "z$top" = "z$sub"
86)
87'
8889
test_expect_success 'checkout-index' '
90git checkout-index -f -u one &&
91cmp one original.one &&
92(
93cd dir &&
94git checkout-index -f -u two &&
95cmp two ../original.two
96)
97'
9899
test_expect_success 'read-tree' '
100rm -f one dir/two &&
101tree=`git write-tree` &&
102read_tree_u_must_succeed --reset -u "$tree" &&
103cmp one original.one &&
104cmp dir/two original.two &&
105(
106cd dir &&
107rm -f two &&
108read_tree_u_must_succeed --reset -u "$tree" &&
109cmp two ../original.two &&
110cmp ../one ../original.one
111)
112'
113114
test_expect_success 'alias expansion' '
115(
116git config alias.ss status &&
117cd dir &&
118git status &&
119git ss
120)
121'
122123
test_expect_success '!alias expansion' '
124pwd >expect &&
125(
126git config alias.test !pwd &&
127cd dir &&
128git test >../actual
129) &&
130test_cmp expect actual
131'
132133
test_expect_success 'GIT_PREFIX for !alias' '
134printf "dir/" >expect &&
135(
136git config alias.test "!sh -c \"printf \$GIT_PREFIX\"" &&
137cd dir &&
138git test >../actual
139) &&
140test_cmp expect actual
141'
142143
test_expect_success 'no file/rev ambiguity check inside .git' '
144git commit -a -m 1 &&
145(
146cd .git &&
147git show -s HEAD
148)
149'
150151
test_expect_success 'no file/rev ambiguity check inside a bare repo' '
152git clone -s --bare .git foo.git &&
153(
154cd foo.git &&
155GIT_DIR=. git show -s HEAD
156)
157'
158159
# This still does not work as it should...
160: test_expect_success 'no file/rev ambiguity check inside a bare repo' '
161git clone -s --bare .git foo.git &&
162(
163cd foo.git &&
164git show -s HEAD
165)
166'
167168
test_expect_success SYMLINKS 'detection should not be fooled by a symlink' '
169rm -fr foo.git &&
170git clone -s .git another &&
171ln -s another yetanother &&
172(
173cd yetanother/.git &&
174git show -s HEAD
175)
176'
177178
test_done