]>
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 | ' | |
a7bb3940 JS |
60 | test_set_prereq HAVEIT |
61 | haveit=no | |
62 | test_expect_success HAVEIT 'test runs if prerequisite is satisfied' ' | |
63 | test_have_prereq HAVEIT && | |
64 | haveit=yes | |
65 | ' | |
66 | donthaveit=yes | |
67 | test_expect_success DONTHAVEIT 'unmet prerequisite causes test to be skipped' ' | |
68 | donthaveit=no | |
69 | ' | |
70 | if test $haveit$donthaveit != yesyes | |
71 | then | |
72 | say "bug in test framework: prerequisite tags do not work reliably" | |
73 | exit 1 | |
74 | fi | |
41ac414e | 75 | |
e1970ce4 JH |
76 | ################################################################ |
77 | # Basics of the basics | |
78 | ||
79 | # updating a new file without --add should fail. | |
41ac414e | 80 | test_expect_success 'git update-index without --add should fail adding.' ' |
d492b31c | 81 | test_must_fail git update-index should-be-empty |
41ac414e | 82 | ' |
e1970ce4 JH |
83 | |
84 | # and with --add it should succeed, even if it is empty (it used to fail). | |
85 | test_expect_success \ | |
5be60078 JH |
86 | 'git update-index with --add should succeed.' \ |
87 | 'git update-index --add should-be-empty' | |
e1970ce4 JH |
88 | |
89 | test_expect_success \ | |
5be60078 JH |
90 | 'writing tree out with git write-tree' \ |
91 | 'tree=$(git write-tree)' | |
e1970ce4 JH |
92 | |
93 | # we know the shape and contents of the tree and know the object ID for it. | |
94 | test_expect_success \ | |
95 | 'validate object ID of a known tree.' \ | |
96 | 'test "$tree" = 7bb943559a305bdd6bdee2cef6e5df2413c3d30a' | |
97 | ||
98 | # Removing paths. | |
99 | rm -f should-be-empty full-of-directories | |
41ac414e | 100 | test_expect_success 'git update-index without --remove should fail removing.' ' |
d492b31c | 101 | test_must_fail git update-index should-be-empty |
41ac414e | 102 | ' |
e1970ce4 JH |
103 | |
104 | test_expect_success \ | |
5be60078 JH |
105 | 'git update-index with --remove should be able to remove.' \ |
106 | 'git update-index --remove should-be-empty' | |
e1970ce4 JH |
107 | |
108 | # Empty tree can be written with recent write-tree. | |
109 | test_expect_success \ | |
5be60078 JH |
110 | 'git write-tree should be able to write an empty tree.' \ |
111 | 'tree=$(git write-tree)' | |
e1970ce4 JH |
112 | |
113 | test_expect_success \ | |
114 | 'validate object ID of a known tree.' \ | |
115 | 'test "$tree" = 4b825dc642cb6eb9a060e54bf8d69288fbee4904' | |
116 | ||
117 | # Various types of objects | |
704a3143 JS |
118 | # Some filesystems do not support symblic links; on such systems |
119 | # some expected values are different | |
e1970ce4 | 120 | mkdir path2 path3 path3/subp3 |
704a3143 JS |
121 | paths='path0 path2/file2 path3/file3 path3/subp3/file3' |
122 | for p in $paths | |
e1970ce4 JH |
123 | do |
124 | echo "hello $p" >$p | |
e1970ce4 | 125 | done |
704a3143 JS |
126 | if test_have_prereq SYMLINKS |
127 | then | |
128 | for p in $paths | |
129 | do | |
130 | ln -s "hello $p" ${p}sym | |
131 | done | |
132 | expectfilter=cat | |
133 | expectedtree=087704a96baf1c2d1c869a8b084481e121c88b5b | |
134 | expectedptree1=21ae8269cacbe57ae09138dcc3a2887f904d02b3 | |
135 | expectedptree2=3c5e5399f3a333eddecce7a9b9465b63f65f51e2 | |
136 | else | |
137 | expectfilter='grep -v sym' | |
138 | expectedtree=8e18edf7d7edcf4371a3ac6ae5f07c2641db7c46 | |
139 | expectedptree1=cfb8591b2f65de8b8cc1020cd7d9e67e7793b325 | |
140 | expectedptree2=ce580448f0148b985a513b693fdf7d802cacb44f | |
141 | fi | |
142 | ||
e1970ce4 | 143 | test_expect_success \ |
5be60078 JH |
144 | 'adding various types of objects with git update-index --add.' \ |
145 | 'find path* ! -type d -print | xargs git update-index --add' | |
e1970ce4 JH |
146 | |
147 | # Show them and see that matches what we expect. | |
148 | test_expect_success \ | |
5be60078 JH |
149 | 'showing stage with git ls-files --stage' \ |
150 | 'git ls-files --stage >current' | |
e1970ce4 | 151 | |
704a3143 | 152 | $expectfilter >expected <<\EOF |
2eab945e JH |
153 | 100644 f87290f8eb2cbbea7857214459a0739927eab154 0 path0 |
154 | 120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0 path0sym | |
155 | 100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0 path2/file2 | |
156 | 120000 d8ce161addc5173867a3c3c730924388daedbc38 0 path2/file2sym | |
157 | 100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0 path3/file3 | |
158 | 120000 8599103969b43aff7e430efea79ca4636466794f 0 path3/file3sym | |
159 | 100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0 path3/subp3/file3 | |
160 | 120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0 path3/subp3/file3sym | |
e1970ce4 JH |
161 | EOF |
162 | test_expect_success \ | |
5be60078 | 163 | 'validate git ls-files output for a known tree.' \ |
188c3827 | 164 | 'test_cmp expected current' |
e1970ce4 JH |
165 | |
166 | test_expect_success \ | |
5be60078 JH |
167 | 'writing tree out with git write-tree.' \ |
168 | 'tree=$(git write-tree)' | |
e1970ce4 JH |
169 | test_expect_success \ |
170 | 'validate object ID for a known tree.' \ | |
704a3143 | 171 | 'test "$tree" = "$expectedtree"' |
e1970ce4 JH |
172 | |
173 | test_expect_success \ | |
5be60078 JH |
174 | 'showing tree with git ls-tree' \ |
175 | 'git ls-tree $tree >current' | |
e1970ce4 | 176 | cat >expected <<\EOF |
2eab945e JH |
177 | 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0 |
178 | 120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym | |
179 | 040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe path2 | |
180 | 040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3 | |
e1970ce4 | 181 | EOF |
704a3143 | 182 | test_expect_success SYMLINKS \ |
5be60078 | 183 | 'git ls-tree output for a known tree.' \ |
188c3827 | 184 | 'test_cmp expected current' |
e1970ce4 | 185 | |
246cc52f JH |
186 | # This changed in ls-tree pathspec change -- recursive does |
187 | # not show tree nodes anymore. | |
e1970ce4 | 188 | test_expect_success \ |
5be60078 JH |
189 | 'showing tree with git ls-tree -r' \ |
190 | 'git ls-tree -r $tree >current' | |
704a3143 | 191 | $expectfilter >expected <<\EOF |
2eab945e JH |
192 | 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0 |
193 | 120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym | |
2eab945e JH |
194 | 100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path2/file2 |
195 | 120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path2/file2sym | |
2eab945e JH |
196 | 100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376 path3/file3 |
197 | 120000 blob 8599103969b43aff7e430efea79ca4636466794f path3/file3sym | |
2eab945e JH |
198 | 100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f path3/subp3/file3 |
199 | 120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path3/subp3/file3sym | |
e1970ce4 JH |
200 | EOF |
201 | test_expect_success \ | |
5be60078 | 202 | 'git ls-tree -r output for a known tree.' \ |
188c3827 | 203 | 'test_cmp expected current' |
e1970ce4 | 204 | |
fdeb6bf5 JH |
205 | # But with -r -t we can have both. |
206 | test_expect_success \ | |
5be60078 JH |
207 | 'showing tree with git ls-tree -r -t' \ |
208 | 'git ls-tree -r -t $tree >current' | |
fdeb6bf5 JH |
209 | cat >expected <<\EOF |
210 | 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0 | |
211 | 120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym | |
212 | 040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe path2 | |
213 | 100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path2/file2 | |
214 | 120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path2/file2sym | |
215 | 040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3 | |
216 | 100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376 path3/file3 | |
217 | 120000 blob 8599103969b43aff7e430efea79ca4636466794f path3/file3sym | |
218 | 040000 tree 3c5e5399f3a333eddecce7a9b9465b63f65f51e2 path3/subp3 | |
219 | 100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f path3/subp3/file3 | |
220 | 120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path3/subp3/file3sym | |
221 | EOF | |
704a3143 | 222 | test_expect_success SYMLINKS \ |
5be60078 | 223 | 'git ls-tree -r output for a known tree.' \ |
188c3827 | 224 | 'test_cmp expected current' |
fdeb6bf5 | 225 | |
6bd20358 | 226 | test_expect_success \ |
5be60078 JH |
227 | 'writing partial tree out with git write-tree --prefix.' \ |
228 | 'ptree=$(git write-tree --prefix=path3)' | |
6bd20358 JH |
229 | test_expect_success \ |
230 | 'validate object ID for a known tree.' \ | |
704a3143 | 231 | 'test "$ptree" = "$expectedptree1"' |
6bd20358 JH |
232 | |
233 | test_expect_success \ | |
5be60078 JH |
234 | 'writing partial tree out with git write-tree --prefix.' \ |
235 | 'ptree=$(git write-tree --prefix=path3/subp3)' | |
6bd20358 JH |
236 | test_expect_success \ |
237 | 'validate object ID for a known tree.' \ | |
704a3143 | 238 | 'test "$ptree" = "$expectedptree2"' |
6bd20358 | 239 | |
3d12d0cf JS |
240 | cat >badobjects <<EOF |
241 | 100644 blob 1000000000000000000000000000000000000000 dir/file1 | |
242 | 100644 blob 2000000000000000000000000000000000000000 dir/file2 | |
243 | 100644 blob 3000000000000000000000000000000000000000 dir/file3 | |
244 | 100644 blob 4000000000000000000000000000000000000000 dir/file4 | |
245 | 100644 blob 5000000000000000000000000000000000000000 dir/file5 | |
246 | EOF | |
247 | ||
248 | rm .git/index | |
249 | test_expect_success \ | |
250 | 'put invalid objects into the index.' \ | |
5be60078 | 251 | 'git update-index --index-info < badobjects' |
3d12d0cf | 252 | |
41ac414e | 253 | test_expect_success 'writing this tree without --missing-ok.' ' |
d492b31c | 254 | test_must_fail git write-tree |
41ac414e | 255 | ' |
3d12d0cf JS |
256 | |
257 | test_expect_success \ | |
258 | 'writing this tree with --missing-ok.' \ | |
5be60078 | 259 | 'git write-tree --missing-ok' |
3d12d0cf JS |
260 | |
261 | ||
e1970ce4 JH |
262 | ################################################################ |
263 | rm .git/index | |
264 | test_expect_success \ | |
5be60078 JH |
265 | 'git read-tree followed by write-tree should be idempotent.' \ |
266 | 'git read-tree $tree && | |
e1970ce4 | 267 | test -f .git/index && |
5be60078 | 268 | newtree=$(git write-tree) && |
e1970ce4 JH |
269 | test "$newtree" = "$tree"' |
270 | ||
704a3143 | 271 | $expectfilter >expected <<\EOF |
b6d8f309 JH |
272 | :100644 100644 f87290f8eb2cbbea7857214459a0739927eab154 0000000000000000000000000000000000000000 M path0 |
273 | :120000 120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0000000000000000000000000000000000000000 M path0sym | |
274 | :100644 100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0000000000000000000000000000000000000000 M path2/file2 | |
275 | :120000 120000 d8ce161addc5173867a3c3c730924388daedbc38 0000000000000000000000000000000000000000 M path2/file2sym | |
276 | :100644 100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0000000000000000000000000000000000000000 M path3/file3 | |
277 | :120000 120000 8599103969b43aff7e430efea79ca4636466794f 0000000000000000000000000000000000000000 M path3/file3sym | |
278 | :100644 100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0000000000000000000000000000000000000000 M path3/subp3/file3 | |
279 | :120000 120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0000000000000000000000000000000000000000 M path3/subp3/file3sym | |
e1970ce4 JH |
280 | EOF |
281 | test_expect_success \ | |
5be60078 JH |
282 | 'validate git diff-files output for a know cache/work tree state.' \ |
283 | 'git diff-files >current && diff >/dev/null -b current expected' | |
e1970ce4 JH |
284 | |
285 | test_expect_success \ | |
5be60078 JH |
286 | 'git update-index --refresh should succeed.' \ |
287 | 'git update-index --refresh' | |
e1970ce4 JH |
288 | |
289 | test_expect_success \ | |
5be60078 JH |
290 | 'no diff after checkout and git update-index --refresh.' \ |
291 | 'git diff-files >current && cmp -s current /dev/null' | |
e1970ce4 | 292 | |
9af0b8db | 293 | ################################################################ |
704a3143 | 294 | P=$expectedtree |
9af0b8db | 295 | test_expect_success \ |
5be60078 JH |
296 | 'git commit-tree records the correct tree in a commit.' \ |
297 | 'commit0=$(echo NO | git commit-tree $P) && | |
9af0b8db JH |
298 | tree=$(git show --pretty=raw $commit0 | |
299 | sed -n -e "s/^tree //p" -e "/^author /q") && | |
300 | test "z$tree" = "z$P"' | |
301 | ||
302 | test_expect_success \ | |
5be60078 JH |
303 | 'git commit-tree records the correct parent in a commit.' \ |
304 | 'commit1=$(echo NO | git commit-tree $P -p $commit0) && | |
9af0b8db JH |
305 | parent=$(git show --pretty=raw $commit1 | |
306 | sed -n -e "s/^parent //p" -e "/^author /q") && | |
307 | test "z$commit0" = "z$parent"' | |
308 | ||
309 | test_expect_success \ | |
5be60078 JH |
310 | 'git commit-tree omits duplicated parent in a commit.' \ |
311 | 'commit2=$(echo NO | git commit-tree $P -p $commit0 -p $commit0) && | |
9af0b8db JH |
312 | parent=$(git show --pretty=raw $commit2 | |
313 | sed -n -e "s/^parent //p" -e "/^author /q" | | |
314 | sort -u) && | |
315 | test "z$commit0" = "z$parent" && | |
316 | numparent=$(git show --pretty=raw $commit2 | | |
317 | sed -n -e "s/^parent //p" -e "/^author /q" | | |
318 | wc -l) && | |
319 | test $numparent = 1' | |
320 | ||
81a361be JH |
321 | test_expect_success 'update-index D/F conflict' ' |
322 | mv path0 tmp && | |
323 | mv path2 path0 && | |
324 | mv tmp path2 && | |
325 | git update-index --add --replace path2 path0/file2 && | |
326 | numpath0=$(git ls-files path0 | wc -l) && | |
327 | test $numpath0 = 1 | |
328 | ' | |
329 | ||
704a3143 | 330 | test_expect_success SYMLINKS 'absolute path works as expected' ' |
e5392c51 JS |
331 | mkdir first && |
332 | ln -s ../.git first/.git && | |
333 | mkdir second && | |
334 | ln -s ../first second/other && | |
335 | mkdir third && | |
336 | dir="$(cd .git; pwd -P)" && | |
337 | dir2=third/../second/other/.git && | |
d553e737 | 338 | test "$dir" = "$(test-path-utils make_absolute_path $dir2)" && |
e5392c51 | 339 | file="$dir"/index && |
d553e737 | 340 | test "$file" = "$(test-path-utils make_absolute_path $dir2/index)" && |
e371a4c6 | 341 | basename=blub && |
d553e737 | 342 | test "$dir/$basename" = "$(cd .git && test-path-utils make_absolute_path "$basename")" && |
e5392c51 JS |
343 | ln -s ../first/file .git/syml && |
344 | sym="$(cd first; pwd -P)"/file && | |
d553e737 | 345 | test "$sym" = "$(test-path-utils make_absolute_path "$dir2/syml")" |
e5392c51 JS |
346 | ' |
347 | ||
7fec10b7 JH |
348 | test_expect_success 'very long name in the index handled sanely' ' |
349 | ||
350 | a=a && # 1 | |
351 | a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 16 | |
352 | a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 256 | |
353 | a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 4096 | |
354 | a=${a}q && | |
355 | ||
356 | >path4 && | |
357 | git update-index --add path4 && | |
358 | ( | |
359 | git ls-files -s path4 | | |
360 | sed -e "s/ .*/ /" | | |
361 | tr -d "\012" | |
362 | echo "$a" | |
363 | ) | git update-index --index-info && | |
364 | len=$(git ls-files "a*" | wc -c) && | |
365 | test $len = 4098 | |
366 | ' | |
367 | ||
e1970ce4 | 368 | test_done |