]> git.ipfire.org Git - thirdparty/git.git/blame - t/t1020-subdirectory.sh
path.c: don't call the match function without value in trie_find()
[thirdparty/git.git] / t / t1020-subdirectory.sh
CommitLineData
c43ce6d6
JH
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
ea5070c9 10. "$TEST_DIRECTORY"/lib-read-tree.sh
c43ce6d6
JH
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'
c43ce6d6
JH
20
21test_expect_success 'update-index and ls-files' '
5be60078 22 git update-index --add one &&
c9e454cc 23 case "$(git ls-files)" in
335f8787 24 one) echo pass one ;;
c43ce6d6
JH
25 *) echo bad one; exit 1 ;;
26 esac &&
18a82692
JN
27 (
28 cd dir &&
29 git update-index --add two &&
c9e454cc 30 case "$(git ls-files)" in
18a82692
JN
31 two) echo pass two ;;
32 *) echo bad two; exit 1 ;;
33 esac
fd4ec4f2 34 ) &&
c9e454cc 35 case "$(git ls-files)" in
335f8787 36 dir/two"$LF"one) echo pass both ;;
c43ce6d6
JH
37 *) echo bad; exit 1 ;;
38 esac
39'
40
41test_expect_success 'cat-file' '
c9e454cc
EP
42 two=$(git ls-files -s dir/two) &&
43 two=$(expr "$two" : "[0-7]* \\([0-9a-f]*\\)") &&
c43ce6d6 44 echo "$two" &&
5be60078 45 git cat-file -p "$two" >actual &&
c43ce6d6 46 cmp dir/two actual &&
fd3c32c9
JL
47 (
48 cd dir &&
49 git cat-file -p "$two" >actual &&
50 cmp two actual
51 )
c43ce6d6
JH
52'
53rm -f actual dir/actual
54
55test_expect_success 'diff-files' '
c43ce6d6
JH
56 echo a >>one &&
57 echo d >>dir/two &&
c9e454cc 58 case "$(git diff-files --name-only)" in
335f8787 59 dir/two"$LF"one) echo pass top ;;
c43ce6d6
JH
60 *) echo bad top; exit 1 ;;
61 esac &&
62 # diff should not omit leading paths
fd3c32c9
JL
63 (
64 cd dir &&
c9e454cc 65 case "$(git diff-files --name-only)" in
fd3c32c9
JL
66 dir/two"$LF"one) echo pass subdir ;;
67 *) echo bad subdir; exit 1 ;;
68 esac &&
c9e454cc 69 case "$(git diff-files --name-only .)" in
fd3c32c9
JL
70 dir/two) echo pass subdir limited ;;
71 *) echo bad subdir limited; exit 1 ;;
72 esac
73 )
c43ce6d6
JH
74'
75
76test_expect_success 'write-tree' '
c9e454cc 77 top=$(git write-tree) &&
c43ce6d6 78 echo $top &&
fd3c32c9
JL
79 (
80 cd dir &&
c9e454cc 81 sub=$(git write-tree) &&
fd3c32c9
JL
82 echo $sub &&
83 test "z$top" = "z$sub"
84 )
c43ce6d6
JH
85'
86
87test_expect_success 'checkout-index' '
5be60078 88 git checkout-index -f -u one &&
c43ce6d6 89 cmp one original.one &&
fd3c32c9
JL
90 (
91 cd dir &&
92 git checkout-index -f -u two &&
93 cmp two ../original.two
94 )
c43ce6d6
JH
95'
96
97test_expect_success 'read-tree' '
c43ce6d6 98 rm -f one dir/two &&
c9e454cc 99 tree=$(git write-tree) &&
ea5070c9 100 read_tree_u_must_succeed --reset -u "$tree" &&
c43ce6d6
JH
101 cmp one original.one &&
102 cmp dir/two original.two &&
fd3c32c9
JL
103 (
104 cd dir &&
105 rm -f two &&
ea5070c9 106 read_tree_u_must_succeed --reset -u "$tree" &&
fd3c32c9
JL
107 cmp two ../original.two &&
108 cmp ../one ../original.one
109 )
c43ce6d6
JH
110'
111
101662c2
MG
112test_expect_success 'alias expansion' '
113 (
d16ece20 114 git config alias.test-status-alias status &&
101662c2
MG
115 cd dir &&
116 git status &&
d16ece20 117 git test-status-alias
101662c2
MG
118 )
119'
0daed417 120
f57a8715 121test_expect_success !MINGW '!alias expansion' '
0daed417
MG
122 pwd >expect &&
123 (
d16ece20 124 git config alias.test-alias-directory !pwd &&
0daed417 125 cd dir &&
d16ece20 126 git test-alias-directory >../actual
0daed417
MG
127 ) &&
128 test_cmp expect actual
129'
130
7cf16a14
MG
131test_expect_success 'GIT_PREFIX for !alias' '
132 printf "dir/" >expect &&
133 (
d16ece20 134 git config alias.test-alias-directory "!sh -c \"printf \$GIT_PREFIX\"" &&
7cf16a14 135 cd dir &&
d16ece20 136 git test-alias-directory >../actual
7cf16a14
MG
137 ) &&
138 test_cmp expect actual
139'
140
1f5d271f
DA
141test_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.
a3bb8ca7
JH
144 echo "dir/" >expect &&
145 write_script diff <<-\EOF &&
146 printf "%s\n" "$GIT_PREFIX"
147 EOF
1f5d271f
DA
148 (
149 cd dir &&
a3bb8ca7 150 echo "change" >two &&
f2deabfc 151 GIT_EXTERNAL_DIFF=./diff git diff >../actual &&
1f5d271f
DA
152 git checkout -- two
153 ) &&
154 test_cmp expect actual
155'
156
3dff5379 157test_expect_success 'no file/rev ambiguity check inside .git' '
68025633 158 git commit -a -m 1 &&
fd3c32c9
JL
159 (
160 cd .git &&
161 git show -s HEAD
162 )
68025633
JS
163'
164
66d2e04e
SB
165test_expect_success 'no file/rev ambiguity check inside a bare repo (explicit GIT_DIR)' '
166 test_when_finished "rm -fr foo.git" &&
68025633 167 git clone -s --bare .git foo.git &&
fd3c32c9
JL
168 (
169 cd foo.git &&
66d2e04e
SB
170 # older Git needed help by exporting GIT_DIR=.
171 # to realize that it is inside a bare repository.
172 # We keep this test around for regression testing.
fd3c32c9
JL
173 GIT_DIR=. git show -s HEAD
174 )
68025633
JS
175'
176
66d2e04e
SB
177test_expect_success 'no file/rev ambiguity check inside a bare repo' '
178 test_when_finished "rm -fr foo.git" &&
68025633 179 git clone -s --bare .git foo.git &&
fd3c32c9
JL
180 (
181 cd foo.git &&
182 git show -s HEAD
183 )
68025633
JS
184'
185
704a3143 186test_expect_success SYMLINKS 'detection should not be fooled by a symlink' '
68025633
JS
187 git clone -s .git another &&
188 ln -s another yetanother &&
fd3c32c9
JL
189 (
190 cd yetanother/.git &&
191 git show -s HEAD
192 )
68025633
JS
193'
194
c43ce6d6 195test_done