]>
Commit | Line | Data |
---|---|---|
e1970ce4 JH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2005 Junio C Hamano | |
4 | # | |
5 | ||
6 | test_description='Test the very basics part #1. | |
7 | ||
8 | The rest of the test suite does not check the basic operation of git | |
9 | plumbing commands to work very carefully. Their job is to concentrate | |
10 | on tricky features that caused bugs in the past to detect regression. | |
11 | ||
12 | This test runs very basic features, like registering things in cache, | |
13 | writing tree, etc. | |
14 | ||
15 | Note that this test *deliberately* hard-codes many expected object | |
16 | IDs. When object ID computation changes, like in the previous case of | |
17 | swapping compression and hashing order, the person who is making the | |
18 | modification *should* take notice and update the test vectors here. | |
19 | ' | |
eea42069 JH |
20 | |
21 | ################################################################ | |
e2b70087 | 22 | # It appears that people try to run tests without building... |
eea42069 JH |
23 | |
24 | ../git >/dev/null | |
25 | if test $? != 1 | |
26 | then | |
27 | echo >&2 'You do not seem to have built git yet.' | |
28 | exit 1 | |
29 | fi | |
30 | ||
e1970ce4 JH |
31 | . ./test-lib.sh |
32 | ||
33 | ################################################################ | |
5be60078 | 34 | # git init has been done in an empty repository. |
e1970ce4 JH |
35 | # make sure it is empty. |
36 | ||
37 | find .git/objects -type f -print >should-be-empty | |
38 | test_expect_success \ | |
5be60078 | 39 | '.git/objects should be empty after git init in an empty repo.' \ |
a6080a0a | 40 | 'cmp -s /dev/null should-be-empty' |
e1970ce4 | 41 | |
9106c097 LT |
42 | # also it should have 2 subdirectories; no fan-out anymore, pack, and info. |
43 | # 3 is counting "objects" itself | |
e1970ce4 JH |
44 | find .git/objects -type d -print >full-of-directories |
45 | test_expect_success \ | |
9106c097 LT |
46 | '.git/objects should have 3 subdirectories.' \ |
47 | 'test $(wc -l < full-of-directories) = 3' | |
e1970ce4 | 48 | |
41ac414e JH |
49 | ################################################################ |
50 | # Test harness | |
51 | test_expect_success 'success is reported like this' ' | |
52 | : | |
53 | ' | |
54 | test_expect_failure 'pretend we have a known breakage' ' | |
55 | false | |
56 | ' | |
57 | test_expect_failure 'pretend we have fixed a known breakage' ' | |
58 | : | |
59 | ' | |
60 | ||
e1970ce4 JH |
61 | ################################################################ |
62 | # Basics of the basics | |
63 | ||
64 | # updating a new file without --add should fail. | |
41ac414e JH |
65 | test_expect_success 'git update-index without --add should fail adding.' ' |
66 | ! git update-index should-be-empty | |
67 | ' | |
e1970ce4 JH |
68 | |
69 | # and with --add it should succeed, even if it is empty (it used to fail). | |
70 | test_expect_success \ | |
5be60078 JH |
71 | 'git update-index with --add should succeed.' \ |
72 | 'git update-index --add should-be-empty' | |
e1970ce4 JH |
73 | |
74 | test_expect_success \ | |
5be60078 JH |
75 | 'writing tree out with git write-tree' \ |
76 | 'tree=$(git write-tree)' | |
e1970ce4 JH |
77 | |
78 | # we know the shape and contents of the tree and know the object ID for it. | |
79 | test_expect_success \ | |
80 | 'validate object ID of a known tree.' \ | |
81 | 'test "$tree" = 7bb943559a305bdd6bdee2cef6e5df2413c3d30a' | |
82 | ||
83 | # Removing paths. | |
84 | rm -f should-be-empty full-of-directories | |
41ac414e JH |
85 | test_expect_success 'git update-index without --remove should fail removing.' ' |
86 | ! git update-index should-be-empty | |
87 | ' | |
e1970ce4 JH |
88 | |
89 | test_expect_success \ | |
5be60078 JH |
90 | 'git update-index with --remove should be able to remove.' \ |
91 | 'git update-index --remove should-be-empty' | |
e1970ce4 JH |
92 | |
93 | # Empty tree can be written with recent write-tree. | |
94 | test_expect_success \ | |
5be60078 JH |
95 | 'git write-tree should be able to write an empty tree.' \ |
96 | 'tree=$(git write-tree)' | |
e1970ce4 JH |
97 | |
98 | test_expect_success \ | |
99 | 'validate object ID of a known tree.' \ | |
100 | 'test "$tree" = 4b825dc642cb6eb9a060e54bf8d69288fbee4904' | |
101 | ||
102 | # Various types of objects | |
103 | mkdir path2 path3 path3/subp3 | |
104 | for p in path0 path2/file2 path3/file3 path3/subp3/file3 | |
105 | do | |
106 | echo "hello $p" >$p | |
107 | ln -s "hello $p" ${p}sym | |
108 | done | |
109 | test_expect_success \ | |
5be60078 JH |
110 | 'adding various types of objects with git update-index --add.' \ |
111 | 'find path* ! -type d -print | xargs git update-index --add' | |
e1970ce4 JH |
112 | |
113 | # Show them and see that matches what we expect. | |
114 | test_expect_success \ | |
5be60078 JH |
115 | 'showing stage with git ls-files --stage' \ |
116 | 'git ls-files --stage >current' | |
e1970ce4 JH |
117 | |
118 | cat >expected <<\EOF | |
2eab945e JH |
119 | 100644 f87290f8eb2cbbea7857214459a0739927eab154 0 path0 |
120 | 120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0 path0sym | |
121 | 100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0 path2/file2 | |
122 | 120000 d8ce161addc5173867a3c3c730924388daedbc38 0 path2/file2sym | |
123 | 100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0 path3/file3 | |
124 | 120000 8599103969b43aff7e430efea79ca4636466794f 0 path3/file3sym | |
125 | 100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0 path3/subp3/file3 | |
126 | 120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0 path3/subp3/file3sym | |
e1970ce4 JH |
127 | EOF |
128 | test_expect_success \ | |
5be60078 | 129 | 'validate git ls-files output for a known tree.' \ |
e1970ce4 JH |
130 | 'diff current expected' |
131 | ||
132 | test_expect_success \ | |
5be60078 JH |
133 | 'writing tree out with git write-tree.' \ |
134 | 'tree=$(git write-tree)' | |
e1970ce4 JH |
135 | test_expect_success \ |
136 | 'validate object ID for a known tree.' \ | |
137 | 'test "$tree" = 087704a96baf1c2d1c869a8b084481e121c88b5b' | |
138 | ||
139 | test_expect_success \ | |
5be60078 JH |
140 | 'showing tree with git ls-tree' \ |
141 | 'git ls-tree $tree >current' | |
e1970ce4 | 142 | cat >expected <<\EOF |
2eab945e JH |
143 | 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0 |
144 | 120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym | |
145 | 040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe path2 | |
146 | 040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3 | |
e1970ce4 JH |
147 | EOF |
148 | test_expect_success \ | |
5be60078 | 149 | 'git ls-tree output for a known tree.' \ |
e1970ce4 JH |
150 | 'diff current expected' |
151 | ||
246cc52f JH |
152 | # This changed in ls-tree pathspec change -- recursive does |
153 | # not show tree nodes anymore. | |
e1970ce4 | 154 | test_expect_success \ |
5be60078 JH |
155 | 'showing tree with git ls-tree -r' \ |
156 | 'git ls-tree -r $tree >current' | |
e1970ce4 | 157 | cat >expected <<\EOF |
2eab945e JH |
158 | 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0 |
159 | 120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym | |
2eab945e JH |
160 | 100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path2/file2 |
161 | 120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path2/file2sym | |
2eab945e JH |
162 | 100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376 path3/file3 |
163 | 120000 blob 8599103969b43aff7e430efea79ca4636466794f path3/file3sym | |
2eab945e JH |
164 | 100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f path3/subp3/file3 |
165 | 120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path3/subp3/file3sym | |
e1970ce4 JH |
166 | EOF |
167 | test_expect_success \ | |
5be60078 | 168 | 'git ls-tree -r output for a known tree.' \ |
e1970ce4 JH |
169 | 'diff current expected' |
170 | ||
fdeb6bf5 JH |
171 | # But with -r -t we can have both. |
172 | test_expect_success \ | |
5be60078 JH |
173 | 'showing tree with git ls-tree -r -t' \ |
174 | 'git ls-tree -r -t $tree >current' | |
fdeb6bf5 JH |
175 | cat >expected <<\EOF |
176 | 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0 | |
177 | 120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym | |
178 | 040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe path2 | |
179 | 100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path2/file2 | |
180 | 120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path2/file2sym | |
181 | 040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3 | |
182 | 100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376 path3/file3 | |
183 | 120000 blob 8599103969b43aff7e430efea79ca4636466794f path3/file3sym | |
184 | 040000 tree 3c5e5399f3a333eddecce7a9b9465b63f65f51e2 path3/subp3 | |
185 | 100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f path3/subp3/file3 | |
186 | 120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path3/subp3/file3sym | |
187 | EOF | |
188 | test_expect_success \ | |
5be60078 | 189 | 'git ls-tree -r output for a known tree.' \ |
fdeb6bf5 JH |
190 | 'diff current expected' |
191 | ||
6bd20358 | 192 | test_expect_success \ |
5be60078 JH |
193 | 'writing partial tree out with git write-tree --prefix.' \ |
194 | 'ptree=$(git write-tree --prefix=path3)' | |
6bd20358 JH |
195 | test_expect_success \ |
196 | 'validate object ID for a known tree.' \ | |
197 | 'test "$ptree" = 21ae8269cacbe57ae09138dcc3a2887f904d02b3' | |
198 | ||
199 | test_expect_success \ | |
5be60078 JH |
200 | 'writing partial tree out with git write-tree --prefix.' \ |
201 | 'ptree=$(git write-tree --prefix=path3/subp3)' | |
6bd20358 JH |
202 | test_expect_success \ |
203 | 'validate object ID for a known tree.' \ | |
204 | 'test "$ptree" = 3c5e5399f3a333eddecce7a9b9465b63f65f51e2' | |
205 | ||
3d12d0cf JS |
206 | cat >badobjects <<EOF |
207 | 100644 blob 1000000000000000000000000000000000000000 dir/file1 | |
208 | 100644 blob 2000000000000000000000000000000000000000 dir/file2 | |
209 | 100644 blob 3000000000000000000000000000000000000000 dir/file3 | |
210 | 100644 blob 4000000000000000000000000000000000000000 dir/file4 | |
211 | 100644 blob 5000000000000000000000000000000000000000 dir/file5 | |
212 | EOF | |
213 | ||
214 | rm .git/index | |
215 | test_expect_success \ | |
216 | 'put invalid objects into the index.' \ | |
5be60078 | 217 | 'git update-index --index-info < badobjects' |
3d12d0cf | 218 | |
41ac414e JH |
219 | test_expect_success 'writing this tree without --missing-ok.' ' |
220 | ! git write-tree | |
221 | ' | |
3d12d0cf JS |
222 | |
223 | test_expect_success \ | |
224 | 'writing this tree with --missing-ok.' \ | |
5be60078 | 225 | 'git write-tree --missing-ok' |
3d12d0cf JS |
226 | |
227 | ||
e1970ce4 JH |
228 | ################################################################ |
229 | rm .git/index | |
230 | test_expect_success \ | |
5be60078 JH |
231 | 'git read-tree followed by write-tree should be idempotent.' \ |
232 | 'git read-tree $tree && | |
e1970ce4 | 233 | test -f .git/index && |
5be60078 | 234 | newtree=$(git write-tree) && |
e1970ce4 JH |
235 | test "$newtree" = "$tree"' |
236 | ||
237 | cat >expected <<\EOF | |
b6d8f309 JH |
238 | :100644 100644 f87290f8eb2cbbea7857214459a0739927eab154 0000000000000000000000000000000000000000 M path0 |
239 | :120000 120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0000000000000000000000000000000000000000 M path0sym | |
240 | :100644 100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0000000000000000000000000000000000000000 M path2/file2 | |
241 | :120000 120000 d8ce161addc5173867a3c3c730924388daedbc38 0000000000000000000000000000000000000000 M path2/file2sym | |
242 | :100644 100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0000000000000000000000000000000000000000 M path3/file3 | |
243 | :120000 120000 8599103969b43aff7e430efea79ca4636466794f 0000000000000000000000000000000000000000 M path3/file3sym | |
244 | :100644 100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0000000000000000000000000000000000000000 M path3/subp3/file3 | |
245 | :120000 120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0000000000000000000000000000000000000000 M path3/subp3/file3sym | |
e1970ce4 JH |
246 | EOF |
247 | test_expect_success \ | |
5be60078 JH |
248 | 'validate git diff-files output for a know cache/work tree state.' \ |
249 | 'git diff-files >current && diff >/dev/null -b current expected' | |
e1970ce4 JH |
250 | |
251 | test_expect_success \ | |
5be60078 JH |
252 | 'git update-index --refresh should succeed.' \ |
253 | 'git update-index --refresh' | |
e1970ce4 JH |
254 | |
255 | test_expect_success \ | |
5be60078 JH |
256 | 'no diff after checkout and git update-index --refresh.' \ |
257 | 'git diff-files >current && cmp -s current /dev/null' | |
e1970ce4 | 258 | |
9af0b8db JH |
259 | ################################################################ |
260 | P=087704a96baf1c2d1c869a8b084481e121c88b5b | |
261 | test_expect_success \ | |
5be60078 JH |
262 | 'git commit-tree records the correct tree in a commit.' \ |
263 | 'commit0=$(echo NO | git commit-tree $P) && | |
9af0b8db JH |
264 | tree=$(git show --pretty=raw $commit0 | |
265 | sed -n -e "s/^tree //p" -e "/^author /q") && | |
266 | test "z$tree" = "z$P"' | |
267 | ||
268 | test_expect_success \ | |
5be60078 JH |
269 | 'git commit-tree records the correct parent in a commit.' \ |
270 | 'commit1=$(echo NO | git commit-tree $P -p $commit0) && | |
9af0b8db JH |
271 | parent=$(git show --pretty=raw $commit1 | |
272 | sed -n -e "s/^parent //p" -e "/^author /q") && | |
273 | test "z$commit0" = "z$parent"' | |
274 | ||
275 | test_expect_success \ | |
5be60078 JH |
276 | 'git commit-tree omits duplicated parent in a commit.' \ |
277 | 'commit2=$(echo NO | git commit-tree $P -p $commit0 -p $commit0) && | |
9af0b8db JH |
278 | parent=$(git show --pretty=raw $commit2 | |
279 | sed -n -e "s/^parent //p" -e "/^author /q" | | |
280 | sort -u) && | |
281 | test "z$commit0" = "z$parent" && | |
282 | numparent=$(git show --pretty=raw $commit2 | | |
283 | sed -n -e "s/^parent //p" -e "/^author /q" | | |
284 | wc -l) && | |
285 | test $numparent = 1' | |
286 | ||
81a361be JH |
287 | test_expect_success 'update-index D/F conflict' ' |
288 | mv path0 tmp && | |
289 | mv path2 path0 && | |
290 | mv tmp path2 && | |
291 | git update-index --add --replace path2 path0/file2 && | |
292 | numpath0=$(git ls-files path0 | wc -l) && | |
293 | test $numpath0 = 1 | |
294 | ' | |
295 | ||
e5392c51 JS |
296 | test_expect_success 'absolute path works as expected' ' |
297 | mkdir first && | |
298 | ln -s ../.git first/.git && | |
299 | mkdir second && | |
300 | ln -s ../first second/other && | |
301 | mkdir third && | |
302 | dir="$(cd .git; pwd -P)" && | |
303 | dir2=third/../second/other/.git && | |
304 | test "$dir" = "$(test-absolute-path $dir2)" && | |
305 | file="$dir"/index && | |
306 | test "$file" = "$(test-absolute-path $dir2/index)" && | |
e371a4c6 | 307 | basename=blub && |
f69e836f | 308 | test "$dir/$basename" = "$(cd .git && test-absolute-path "$basename")" && |
e5392c51 JS |
309 | ln -s ../first/file .git/syml && |
310 | sym="$(cd first; pwd -P)"/file && | |
f69e836f | 311 | test "$sym" = "$(test-absolute-path "$dir2/syml")" |
e5392c51 JS |
312 | ' |
313 | ||
7fec10b7 JH |
314 | test_expect_success 'very long name in the index handled sanely' ' |
315 | ||
316 | a=a && # 1 | |
317 | a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 16 | |
318 | a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 256 | |
319 | a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 4096 | |
320 | a=${a}q && | |
321 | ||
322 | >path4 && | |
323 | git update-index --add path4 && | |
324 | ( | |
325 | git ls-files -s path4 | | |
326 | sed -e "s/ .*/ /" | | |
327 | tr -d "\012" | |
328 | echo "$a" | |
329 | ) | git update-index --index-info && | |
330 | len=$(git ls-files "a*" | wc -c) && | |
331 | test $len = 4098 | |
332 | ' | |
333 | ||
e1970ce4 | 334 | test_done |