1#!/bin/sh
2#
3# Copyright (c) 2006 Junio C Hamano
4#
5
6test_description='Try various core-level commands in subdirectory.
7'
8
9. ./test-lib.sh
10. "$TEST_DIRECTORY"/lib-read-tree.sh
11
12test_expect_success setup '
13 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" &&
14 for c in $long; do echo $c; done >one &&
15 mkdir dir &&
16 for c in x y z $long a b c; do echo $c; done >dir/two &&
17 cp one original.one &&
18 cp dir/two original.two
19'
20LF='
21'
22
23test_expect_success 'update-index and ls-files' '
24 git update-index --add one &&
25 case "`git ls-files`" in
26 one) echo pass one ;;
27 *) echo bad one; exit 1 ;;
28 esac &&
29 (
30 cd dir &&
31 git update-index --add two &&
32 case "`git ls-files`" in
33 two) echo pass two ;;
34 *) echo bad two; exit 1 ;;
35 esac
36 ) &&
37 case "`git ls-files`" in
38 dir/two"$LF"one) echo pass both ;;
39 *) echo bad; exit 1 ;;
40 esac
41'
42
43test_expect_success 'cat-file' '
44 two=`git ls-files -s dir/two` &&
45 two=`expr "$two" : "[0-7]* \\([0-9a-f]*\\)"` &&
46 echo "$two" &&
47 git cat-file -p "$two" >actual &&
48 cmp dir/two actual &&
49 (
50 cd dir &&
51 git cat-file -p "$two" >actual &&
52 cmp two actual
53 )
54'
55rm -f actual dir/actual
56
57test_expect_success 'diff-files' '
58 echo a >>one &&
59 echo d >>dir/two &&
60 case "`git diff-files --name-only`" in
61 dir/two"$LF"one) echo pass top ;;
62 *) echo bad top; exit 1 ;;
63 esac &&
64 # diff should not omit leading paths
65 (
66 cd dir &&
67 case "`git diff-files --name-only`" in
68 dir/two"$LF"one) echo pass subdir ;;
69 *) echo bad subdir; exit 1 ;;
70 esac &&
71 case "`git diff-files --name-only .`" in
72 dir/two) echo pass subdir limited ;;
73 *) echo bad subdir limited; exit 1 ;;
74 esac
75 )
76'
77
78test_expect_success 'write-tree' '
79 top=`git write-tree` &&
80 echo $top &&
81 (
82 cd dir &&
83 sub=`git write-tree` &&
84 echo $sub &&
85 test "z$top" = "z$sub"
86 )
87'
88
89test_expect_success 'checkout-index' '
90 git checkout-index -f -u one &&
91 cmp one original.one &&
92 (
93 cd dir &&
94 git checkout-index -f -u two &&
95 cmp two ../original.two
96 )
97'
98
99test_expect_success 'read-tree' '
100 rm -f one dir/two &&
101 tree=`git write-tree` &&
102 read_tree_u_must_succeed --reset -u "$tree" &&
103 cmp one original.one &&
104 cmp dir/two original.two &&
105 (
106 cd dir &&
107 rm -f two &&
108 read_tree_u_must_succeed --reset -u "$tree" &&
109 cmp two ../original.two &&
110 cmp ../one ../original.one
111 )
112'
113
114test_expect_success 'alias expansion' '
115 (
116 git config alias.ss status &&
117 cd dir &&
118 git status &&
119 git ss
120 )
121'
122
123test_expect_success '!alias expansion' '
124 pwd >expect &&
125 (
126 git config alias.test !pwd &&
127 cd dir &&
128 git test >../actual
129 ) &&
130 test_cmp expect actual
131'
132
133test_expect_success 'GIT_PREFIX for !alias' '
134 printf "dir/" >expect &&
135 (
136 git config alias.test "!sh -c \"printf \$GIT_PREFIX\"" &&
137 cd dir &&
138 git test >../actual
139 ) &&
140 test_cmp expect actual
141'
142
143test_expect_success 'no file/rev ambiguity check inside .git' '
144 git commit -a -m 1 &&
145 (
146 cd .git &&
147 git show -s HEAD
148 )
149'
150
151test_expect_success 'no file/rev ambiguity check inside a bare repo' '
152 git clone -s --bare .git foo.git &&
153 (
154 cd foo.git &&
155 GIT_DIR=. git show -s HEAD
156 )
157'
158
159# This still does not work as it should...
160: test_expect_success 'no file/rev ambiguity check inside a bare repo' '
161 git clone -s --bare .git foo.git &&
162 (
163 cd foo.git &&
164 git show -s HEAD
165 )
166'
167
168test_expect_success SYMLINKS 'detection should not be fooled by a symlink' '
169 rm -fr foo.git &&
170 git clone -s .git another &&
171 ln -s another yetanother &&
172 (
173 cd yetanother/.git &&
174 git show -s HEAD
175 )
176'
177
178test_done