setup: Provide GIT_PREFIX to built-ins
[git/raj.git] / t / t1020-subdirectory.sh
blob3c7448026d452a9b7d0de621d251f73d0379fe8f
1 #!/bin/sh
3 # Copyright (c) 2006 Junio C Hamano
6 test_description='Try various core-level commands in subdirectory.
9 . ./test-lib.sh
11 test_expect_success setup '
12 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" &&
13 for c in $long; do echo $c; done >one &&
14 mkdir dir &&
15 for c in x y z $long a b c; do echo $c; done >dir/two &&
16 cp one original.one &&
17 cp dir/two original.two
19 LF='
22 test_expect_success 'update-index and ls-files' '
23 git update-index --add one &&
24 case "`git ls-files`" in
25 one) echo pass one ;;
26 *) echo bad one; exit 1 ;;
27 esac &&
29 cd dir &&
30 git update-index --add two &&
31 case "`git ls-files`" in
32 two) echo pass two ;;
33 *) echo bad two; exit 1 ;;
34 esac
35 ) &&
36 case "`git ls-files`" in
37 dir/two"$LF"one) echo pass both ;;
38 *) echo bad; exit 1 ;;
39 esac
42 test_expect_success 'cat-file' '
43 two=`git ls-files -s dir/two` &&
44 two=`expr "$two" : "[0-7]* \\([0-9a-f]*\\)"` &&
45 echo "$two" &&
46 git cat-file -p "$two" >actual &&
47 cmp dir/two actual &&
49 cd dir &&
50 git cat-file -p "$two" >actual &&
51 cmp two actual
54 rm -f actual dir/actual
56 test_expect_success 'diff-files' '
57 echo a >>one &&
58 echo d >>dir/two &&
59 case "`git diff-files --name-only`" in
60 dir/two"$LF"one) echo pass top ;;
61 *) echo bad top; exit 1 ;;
62 esac &&
63 # diff should not omit leading paths
65 cd dir &&
66 case "`git diff-files --name-only`" in
67 dir/two"$LF"one) echo pass subdir ;;
68 *) echo bad subdir; exit 1 ;;
69 esac &&
70 case "`git diff-files --name-only .`" in
71 dir/two) echo pass subdir limited ;;
72 *) echo bad subdir limited; exit 1 ;;
73 esac
77 test_expect_success 'write-tree' '
78 top=`git write-tree` &&
79 echo $top &&
81 cd dir &&
82 sub=`git write-tree` &&
83 echo $sub &&
84 test "z$top" = "z$sub"
88 test_expect_success 'checkout-index' '
89 git checkout-index -f -u one &&
90 cmp one original.one &&
92 cd dir &&
93 git checkout-index -f -u two &&
94 cmp two ../original.two
98 test_expect_success 'read-tree' '
99 rm -f one dir/two &&
100 tree=`git write-tree` &&
101 git read-tree --reset -u "$tree" &&
102 cmp one original.one &&
103 cmp dir/two original.two &&
105 cd dir &&
106 rm -f two &&
107 git read-tree --reset -u "$tree" &&
108 cmp two ../original.two &&
109 cmp ../one ../original.one
113 test_expect_success 'alias expansion' '
115 git config alias.ss status &&
116 cd dir &&
117 git status &&
118 git ss
122 test_expect_success '!alias expansion' '
123 pwd >expect &&
125 git config alias.test !pwd &&
126 cd dir &&
127 git test >../actual
128 ) &&
129 test_cmp expect actual
132 test_expect_success 'GIT_PREFIX for !alias' '
133 printf "dir/" >expect &&
135 git config alias.test "!sh -c \"printf \$GIT_PREFIX\"" &&
136 cd dir &&
137 git test >../actual
138 ) &&
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 printf "dir/" >expect &&
146 printf "#!/bin/sh\n" >diff &&
147 printf "printf \"\$GIT_PREFIX\"" >>diff &&
148 chmod +x diff &&
150 cd dir &&
151 printf "change" >two &&
152 env GIT_EXTERNAL_DIFF=./diff git diff >../actual
153 git checkout -- two
154 ) &&
155 test_cmp expect actual
158 test_expect_success 'no file/rev ambiguity check inside .git' '
159 git commit -a -m 1 &&
161 cd .git &&
162 git show -s HEAD
166 test_expect_success 'no file/rev ambiguity check inside a bare repo' '
167 git clone -s --bare .git foo.git &&
169 cd foo.git &&
170 GIT_DIR=. git show -s HEAD
174 # This still does not work as it should...
175 : test_expect_success 'no file/rev ambiguity check inside a bare repo' '
176 git clone -s --bare .git foo.git &&
178 cd foo.git &&
179 git show -s HEAD
183 test_expect_success SYMLINKS 'detection should not be fooled by a symlink' '
184 rm -fr foo.git &&
185 git clone -s .git another &&
186 ln -s another yetanother &&
188 cd yetanother/.git &&
189 git show -s HEAD
193 test_done